/*:>-------------------------------------------------------------------- **: FILE: mMvdDCM.c **: HISTORY: **: 00jan93-v000a-hpl- Created by stic Version **: Id: idl.y,v 1.2 1998/02/03 22:21:05 dave Exp **:<------------------------------------------------------------------*/ #include "mMvdDCM.h" #include "pio.h" void MvdMess_(char *name_of_function, short ierror, short level, char *message, ...); #define NO_ERROR 0 /* used for mesage output with no error */ #define ERROR1 1 #define LOUD 2 /* messages which are usually output */ #define QUIET 1 /* used for messages which are output at default setting */ #define SILENT 0 /* for messages which are usually not output */ /* The following bit definitions are based on a document by J. Nagle */ /* and C.Y. Chi: */ /* http://www.nevis.columbia.edu/~nagle/PHENIX/mvd_format_pub.htm */ /* The data values are all stored in the lower 16 bits of each 32 bit */ /* word. The upper 16 bits are used as various flags to indicate what */ /* the actual contents of the word is -- which is mainly relevant when*/ /* zero suppression is used. These are set up as bit patterns to be */ /* "or'ed" with the data to construct the output data value. */ /* NoDataBit has the highest bit (bit 31) set -- this bit is set */ /* for "non-data" words and not for "data" words. The variables with */ /* Num in their names are used to set some sequence number in bits */ /* 28-30 for those words (user, parity, last word) which use them. */ /* The variables starting with "Flag" are various flags which use */ /* bits 16-27 to indicate the type of word being stored. */ #define NODATABIT 1 /* these use bits 28-30 as sequence numbers: */ #define PARITYNUM 1 #define LASTNUM 2 /* misc flags in bits 16-27: */ #define FLAGFLGS 0xF #define FLAGHEADER 0x6 #define FLAGUSER 0xE #define FLAGTRAILER 0xF /* bit 31 | bits 30-28 | bits 27-16 */ #define FLGS_MASK (NODATABIT<<31) | (FLAGFLGS<<16) #define MODULE_MASK (NODATABIT<<31) | (FLAGHEADER<<16) #define EVENT_MASK (NODATABIT<<31) | (FLAGHEADER<<16) #define BCOUNTER_MASK (NODATABIT<<31) | (FLAGHEADER<<16) #define DET_MASK (NODATABIT<<31) | (FLAGHEADER<<16) #define AMUCELLS_MASK 0 #define ADC_MASK(NADC) ((NADC+1)<<16) #define USER_MASK(NUSER) (NODATABIT<<31) | ((NUSER+1)<<28) | (FLAGUSER<<16) #define PARITY_MASK (NODATABIT<<31) | (PARITYNUM<<28) | (FLAGTRAILER<16) #define LASTWORD_MASK (NODATABIT<<31) | (LASTNUM<<28) | (FLAGTRAILER<16) #define MVDID 2 /* MVD subsystem ID = 2 */ long mMvdDCM_( TABLE_HEAD_ST *FEM_h, DMVDFEM_ST *FEM , TABLE_HEAD_ST *DCM_h, DMVDDCM_ST *DCM ) { /*:>-------------------------------------------------------------------- **: ROUTINE: mMvdDCM_ **: DESCRIPTION: Given the table containing DCM/IM output packets (FEM), **: Fill the table (DCM) containing the DCM outout. **: This is for the MVD subsystem. **: **: AUTHOR: J.P. Sullivan 10-Jul-98 **: ARGUMENTS: **: IN: **: FEM - output from DCM/IM's -- which is a **: rearranged output from the MCM's. **: FEM_h - header Structure for FEM **: INOUT: **: OUT: **: DCM - output from DCM's **: DCM_h - header Structure for DCM **: RETURNS: STAF Condition Value **: History: **: J.P.Sullivan rewrote 24-Jul-98 **:>------------------------------------------------------------------*/ unsigned long nadc; /* loop index for adc numbers */ unsigned long nuser; /* loop index for user words */ int i; /* loop index */ /**********************************************************************/ MvdMess_("mMvdDCM",NO_ERROR,LOUD, "\nmMvdDCM{" ); /**********************************************************************/ DCM_h->nok=0; /* reset number of output packets */ /* I am not sure if I understand the detailed definition of some */ /* of these quantities. Here, I have just copied the corresponding */ /* data values from the input FEM table. Maybe things like the */ /* event number will be something different in the real world. */ for ( i=0 ; inok ; i++ ) { /* set the data values, which go in the lower 16 bits, and then apply */ /* the bit masks which define the upper bits */ DCM[DCM_h->nok].nWord = 272; DCM[DCM_h->nok].scheme = IDMVD_DCM0; DCM[DCM_h->nok].packetID = 2001 + DCM_h->nok; DCM[DCM_h->nok].Flgs = (unsigned long)FEM[i].Flag | FLGS_MASK; DCM[DCM_h->nok].module = (unsigned long)FEM[i].adr | MODULE_MASK; DCM[DCM_h->nok].event = (unsigned long)FEM[i].Ecounter | EVENT_MASK; DCM[DCM_h->nok].Bcounter = (unsigned long)FEM[i].Bcounter | BCOUNTER_MASK; DCM[DCM_h->nok].det = MVDID | DET_MASK; DCM[DCM_h->nok].amucells = (unsigned long)FEM[i].amucells | AMUCELLS_MASK; for ( nadc=0; nadc<256; nadc++) DCM[DCM_h->nok].adc[nadc] = (unsigned long)FEM[i].adc[nadc] | ADC_MASK(nadc); for ( nuser=0; nuser<8; nuser++ ) DCM[DCM_h->nok].user[nuser] = (unsigned long)FEM[i].user[nuser] | USER_MASK(nuser); DCM[DCM_h->nok].parity = (unsigned long)FEM[i].parity | PARITY_MASK; DCM[DCM_h->nok].LastWord = 0 | LASTWORD_MASK; DCM_h->nok++; } MvdMess_("mMvdDCM",NO_ERROR,LOUD,"}"); return STAFCV_OK; }