/*:>-------------------------------------------------------------------- **: FILE: mMvdUnpack.c **: HISTORY: **: 00jan93-v000a-hpl- Created by stic Version **: Id: idl.y,v 1.2 1998/02/03 22:21:05 dave Exp **:<------------------------------------------------------------------*/ #include "mMvdUnpack.h" void MvdMess_(char *name_of_function, short ierror, short level, char *message, ...); /* the following definitions are used in the MvdMess calls: */ #define NO_ERROR 0 /* used for mesage output with no error */ #define ERROR1 1 /* illegal strip address */ #define ERROR2 2 /* illegal pad address */ #define ERROR3 3 /* illegal mcm number */ #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 */ #define MAXADC 256 /* number of ADCs per MCM */ #define MAXPANEL 12 /* number of panels per row in the barrel */ #define MAXROW 6 /* number of rows per shell in the barrel */ #define MAXSHELL 2 /* number of shells in the barrel */ #define MAXWEDGE 12 /* number of wedges in each endcap (pads) */ #define MAXEND 2 /* number of endcaps */ #define MAXROWPAD 21 /* max number of "rows" in each wedge */ #define MAXCOLUMN 12 /* max number of columns per wedge */ #define PADADCOFFSET 2 /* first pad detector channel is connected*/ /* to 3rd MCM input in pad detectors */ #define MAX_MCM_BARREL 144 /* number of MCM's addresses in barrel,*/ /* which is not the number of MCM's in */ /* the barrel -- addresses are assigned*/ /* even for locations in the "hole" in */ /* the outer layer */ long mMvdUnpack_( TABLE_HEAD_ST *DCM_h, DMVDDCM_ST *DCM , TABLE_HEAD_ST *bRaw_h, DMVBRAW_ST *bRaw , TABLE_HEAD_ST *cRaw_h, DMVCRAW_ST *cRaw ) { /*:>-------------------------------------------------------------------- **: ROUTINE: mMvdUnpack_ **: DESCRIPTION: Take staf "DCM Output" tables and fill the **: raw data tables for the MVD barrel and pads. **: AUTHOR: J.P.Sullivan 10-Jul-98 **: ARGUMENTS: **: IN: **: DCM - DCM output **: DCM_h - header Structure for DCM **: INOUT: **: OUT: **: bRaw - raw data table for barrel **: bRaw_h - header Structure for bRaw **: cRaw - raw data table for pads **: cRaw_h - header Structure for cRaw **: RETURNS: STAF Condition Value **:>------------------------------------------------------------------*/ int i; /* loop counter */ int nadc; /* loop counter */ short nplex; /* 0 or 1 -- for 1st and second MCM's which are */ /* input to each DCM */ short ndcm; /* DCM number */ short nmcm; /* MCM number */ short L_case; /* to switch on whether a table entry is for pads*/ /* or strips */ short itemp; /* duumy variable used in unpacking hit address */ short end; /* 0 or 1 -- which end of the MVD pads */ short wedge; /* 0 - 11 -- 12 wedges in each pad endcap */ short column; /* 0 - 11 -- 12 columns (phi segments) per wedge */ unsigned long low16=0xFFFF; /* low 16 bits set */ unsigned long low10=0x3FF; /* low 10 bits set, to mask ADC values*/ int low2=3; /* low 2 bits set */ unsigned long adr;/* DCM address (contains nplex bit) */ short adc; /* adc value */ short shell; /* 0 - 1 inner or outer shell in MVD barrel */ short row; /* this is actually used twice, once for the pads*/ /* where is runs 0-20 for the 21 radial segments */ /* in each wedge and one for the barrel, where it*/ /* runs 0-5 for the 6 phi segments. */ short panel; /* 0-11 for the 12 panels in each barrel row */ /**********************************************************************/ MvdMess_("mMvdUnpack",NO_ERROR,LOUD, "\nmMvdUnpack{" ); bRaw_h->nok=0; /* reset N events in barrel raw data table */ cRaw_h->nok=0; /* reset N events in pad raw data table */ /**********************************************************************/ for ( i=0 ; inok ; i++ ) { /* The first section inside this loop figures out whether this */ /* MCM comes from one of the pad detectors or strip detectors */ adr = DCM[i].module & low16; /* low 16 bits=module address */ nplex = (short)(adr & low2); /* multiplex bit */ ndcm = (short)(adr/4); /* DCM number */ nmcm = ndcm*2 + nplex; /* MCM number (2 MCMs per DCM)*/ L_case= 0; /* flag for strips=1/pads=2 */ if ( nmcm=0 ) { /* This should be a barrel MCM */ /* nmcm= panel + row*MAXPANEL + shell*(MAXROW*MAXPANEL); */ shell = nmcm/(MAXROW*MAXPANEL); itemp = nmcm - shell*(MAXROW*MAXPANEL); row = itemp/MAXPANEL; panel = itemp - row*MAXPANEL; if ( panel=0 && row=0 && shell=0 ) L_case = 1; else MvdMess_("mMvdUnpack",ERROR1,LOUD, "\tillegal strip MCM address nmcm=%d panel=%d row=%d shell=%d", nmcm, panel, row, shell); } else if ( nmcm < MAX_MCM_BARREL+MAXWEDGE*MAXEND && nmcm>=0 ) { /* This should be an pad MCM */ /* nmcm= wedge + end*MAXWEDGE + MAX_MCM_BARREL; */ itemp = nmcm - MAX_MCM_BARREL; end = itemp/MAXWEDGE; wedge = itemp - end*MAXWEDGE; if ( wedge=0 && end=0 ) L_case = 2; /* flag to mark this as a pad detector MCM */ else MvdMess_("mMvdUnpack",ERROR2,LOUD, "\tillegal pad MCM address nmcm=%d wedge=%d end=%d", nmcm, wedge, end); } else { MvdMess_("mMvdUnpack",ERROR3,LOUD, "\tillegal mcm number(all hex)=%x DCM[i].module=%x adr=%x nplex=%x ndcm=%x", nmcm,DCM[i].module,adr,nplex,ndcm); } /* now the code has decided whether this MCM is for pads or strips */ /* and has also decoded the address of the MCM, start filling in */ /* ADC values in the raw data array */ switch(L_case) { case 1: for ( nadc=0; nadc0 ) { bRaw[bRaw_h->nok].shell = shell; bRaw[bRaw_h->nok].row = row; bRaw[bRaw_h->nok].cell = panel; bRaw[bRaw_h->nok].strip = nadc; bRaw[bRaw_h->nok].adc = adc; bRaw_h->nok++; MvdMess_("mMvdUnpack",NO_ERROR,SILENT, "\tstrips:panel=%d row=%d shell=%d bRaw_h->nok=%d nmcm=%d ndcm=%d nplex=%d", panel, row, shell, bRaw_h->nok, nmcm, ndcm, nplex); } } break; case 2: /* the first 2 and last 2 ADC channels are not connected to anything */ for ( nadc=PADADCOFFSET; nadc0 ) { /* for the pads, the ADC number gives the row and column: */ /* nadc = row + column*MAXROWPAD + PADADCOFFSET; */ itemp = nadc - PADADCOFFSET; /* 2 pad offset for unused */ /* MCM channels at edges */ column = itemp/MAXROWPAD; row = itemp - column*MAXROWPAD; cRaw[cRaw_h->nok].end = end; cRaw[cRaw_h->nok].wedge = wedge; cRaw[cRaw_h->nok].row = row; cRaw[cRaw_h->nok].column= column; cRaw[cRaw_h->nok].adc = adc; cRaw_h->nok++; MvdMess_("mMvdUnpack",NO_ERROR,SILENT, "\tpads: wedge=%d end=%d cRaw_h->nok=%d nmcm=%d ndcm=%d nplex=%d row=%d column=%d", wedge, end, cRaw_h->nok, nmcm, ndcm, nplex, row, column); } } break; default: MvdMess_("mMvdUnpack",NO_ERROR,SILENT, "\terror unpacking MCM address nmcm=%d",nmcm); break; } } MvdMess_("mMvdUnpack",NO_ERROR,LOUD,"}"); return STAFCV_OK; }