7 #include <rtsSystems.h>
13 #define TRG_VERSION 0x21
14 #include <daqFormats.h>
23 static unsigned char ctbMap[240] = {
24 7, 6, 5, 4, 3, 23, 22, 21, 20, 19,
25 2, 1, 0, 15, 14, 18, 17, 16, 31, 30,
26 13, 12, 11, 10, 9, 29, 28, 27, 26, 25,
27 39, 38, 37, 36, 35, 55, 54, 53, 52, 51,
28 34, 33, 32, 47, 46, 50, 49, 48, 63, 62,
29 45, 44, 43, 42, 41, 61, 60, 59, 58, 57,
30 71, 70, 69, 68, 67, 87, 86, 85, 84, 83,
31 66, 65, 64, 79, 78, 82, 81, 80, 95, 94,
32 77, 76, 75, 74, 73, 93, 92, 91, 90, 89,
33 103, 102, 101, 100, 99, 119, 118, 117, 116, 115,
34 98, 97, 96, 111, 110, 114, 113, 112, 127, 126,
35 109, 108, 107, 106, 105, 125, 124, 123, 122, 121,
36 135, 134, 133, 132, 131, 151, 150, 149, 148, 147,
37 130, 129, 128, 143, 142, 146, 145, 144, 159, 158,
38 141, 140, 139, 138, 137, 157, 156, 155, 154, 153,
39 167, 166, 165, 164, 163, 183, 182, 181, 180, 179,
40 162, 161, 160, 175, 174, 178, 177, 176, 191, 190,
41 173, 172, 171, 170, 169, 189, 188, 187, 186, 185,
42 199, 198, 197, 196, 195, 215, 214, 213, 212, 211,
43 194, 193, 192, 207, 206, 210, 209, 208, 223, 222,
44 205, 204, 203, 202, 201, 221, 220, 219, 218, 217,
45 231, 230, 229, 228, 227, 247, 246, 245, 244, 243,
46 226, 225, 224, 239, 238, 242, 241, 240, 255, 254,
47 237, 236, 235, 234, 233, 253, 252, 251, 250, 249,
51 static unsigned char mwcMap[96] = {
52 71, 70, 69, 68, 67, 66, 65, 64, 79, 78, 77, 76,
53 95, 94, 93, 92, 87, 86, 85, 84, 83, 82, 81, 80,
54 99, 98, 97, 96, 111, 110, 109, 108, 103, 102, 101, 100,
55 119, 118, 117, 116, 115, 114, 113, 112, 127, 126, 125, 124,
56 7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12,
57 31, 30, 29, 28, 23, 22, 21, 20, 19, 18, 17, 16,
58 35, 34, 33, 32, 47, 46, 45, 44, 39, 38, 37, 36,
59 55, 54, 53, 52, 51, 50, 49, 48, 63, 62, 61, 60,
66 int trgReader21(
char *arg,
struct trg_t *trg)
69 int sdes, ssum, sraw ;
73 struct TRGD *trgd = (
struct TRGD *)arg ;
76 if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swap=1;
78 len = swap ? swap32(trgd->bh.length)*4 : trgd->bh.length*4;
80 sdes =
sizeof(trgd->bh) +
sizeof(trgd->desc) ;
81 ssum = sdes +
sizeof(trgd->sum) ;
82 sraw = ssum +
sizeof(trgd->raw[0]) ;
85 LOG(NOTE,
"No TRG Summaries, or Raw...",0,0,0,0,0) ;
89 LOG(NOTE,
"TRG: Summaries ONLY!",0,0,0,0,0) ;
93 LOG(DBG,
"len %d, desc len %d, sum len %d, raw trg 0 len %d, all raw len %d",
94 len,
sizeof(trgd->desc),
sizeof(trgd->sum),
sizeof(trgd->raw[0]),
sizeof(trgd->raw)) ;
96 LOG(DBG,
"evt desc bytes %d, sum bytes %d, raw bytes %d",trgd->desc.TCUdataBytes,
97 trgd->sum.TrgSumBytes,trgd->raw[0].RawDetBytes,0,0) ;
100 trg->npre = swap ? swap16(trgd->desc.npre) : trgd->desc.npre ;
101 trg->npost = swap ? swap16(trgd->desc.npost) : trgd->desc.npost ;
103 trg->xing_lo = swap ? swap32(trgd->desc.bunchXing_lo) : trgd->desc.bunchXing_lo ;
104 trg->xing_hi = swap ? swap32(trgd->desc.bunchXing_hi) : trgd->desc.bunchXing_hi ;
106 trg->phys_word = swap ? swap16(trgd->desc.physicsWord) : trgd->desc.physicsWord ;
107 trg->trg_word = swap ? swap16(trgd->desc.TriggerWord) : trgd->desc.TriggerWord ;
109 trg->trgd = (
void *) trgd ;
114 int trg_length = len -
sizeof(
struct bankHeader) ;
115 int exp_length =
sizeof(
EvtDescData) +
sizeof(trgd->sum) +
sizeof(trgd->raw[0]) +
116 sizeof(trgd->raw[0])*trg->npre +
sizeof(trgd->raw[0])*trg->npost ;
118 if(trg_length != exp_length) {
119 LOG(NOTE,
"Trigger data: is %d, expect %d bytes, trg->npre %d, trg->npost %d",
120 trg_length, exp_length,trg->npre,trg->npost,0) ;
123 LOG(DBG,
"Trigger data: is %d, expect %d bytes, trg->npre %d, trg->npost %d",
124 trg_length, exp_length,trg->npre,trg->npost,0) ;
128 trg->tcubits = swap ? swap16(trgd->desc.DSMInput) : trgd->desc.DSMInput;
129 trg->detlive = swap ? swap16(trgd->desc.externalBusy) : trgd->desc.externalBusy ;
132 LOG(DBG,
"TrgDataFmtVer 0x%X, 0x%04X %c %c", trgd->desc.TrgDataFmtVer,
133 trgd->sum.TrgSumHeader,
134 trgd->raw[0].CTBdataHeader[0],
135 trgd->raw[0].CTBdataHeader[1],0) ;
137 LOG(DBG,
"TrgSumBytes %d, 0x%04X %c %c %c", trgd->sum.TrgSumBytes,
138 trgd->sum.L0SumHeader,
139 trgd->raw[0].RawDetHeader[0],
140 trgd->raw[0].RawDetHeader[1],0) ;
147 trg->trg_sum = (
void *) &trg_sum ;
148 memset(&trg_sum,0,
sizeof(trg_sum)) ;
151 trg_sum.L1Sum[i] = swap ? swap32(trgd->sum.L1Sum[i]) : trgd->sum.L1Sum[i] ;
152 trg_sum.L2Sum[i] = swap ? swap32(trgd->sum.L2Sum[i]) : trgd->sum.L2Sum[i] ;
157 #define REAL_BAD_HACK(x) trg_sum.DSMdata.x = (swap ? swap16(trgd->sum.DSMdata.x) : trgd->sum.DSMdata.x)
160 REAL_BAD_HACK(CPA[i]) ;
163 REAL_BAD_HACK(BCdata[i]) ;
167 REAL_BAD_HACK(quadDSM[i]) ;
168 REAL_BAD_HACK(lastDSM[i]) ;
169 REAL_BAD_HACK(VTX[i]) ;
170 REAL_BAD_HACK(EMC[i]) ;
171 REAL_BAD_HACK(specialTriggers[i]) ;
172 REAL_BAD_HACK(FPD[i]) ;
182 trg->CTB[i] = trgd->raw[0].CTB[ctbMap[i]] ;
186 trg->MWC[i] = trgd->raw[0].MWC[mwcMap[i]] ;
191 trg->BEMC[0][i] = trgd->raw[0].BEMCEast[i] ;
195 trg->BEMC[1][i] = trgd->raw[0].BEMCWest[i] ;
199 trg->BEMC_l1[i] = swap ? swap16(trgd->raw[0].BEMClayer1[i]) : trgd->raw[0].BEMClayer1[i] ;
205 trg->EEMC[i] = trgd->raw[0].EEMC[i] ;
208 trg->EEMC_l1[i] = swap ? swap16(trgd->raw[0].EEMClayer1[i]) : trgd->raw[0].EEMClayer1[i];
216 trg->FPD[0][0][i] = trgd->raw[0].FPDEastNSLayer0[i] ;
219 trg->FPD_l1[0][0][i] = swap ? swap16(trgd->raw[0].FPDEastNSLayer1[i]) : trgd->raw[0].FPDEastNSLayer1[i] ;
223 trg->FPD[0][1][i] = trgd->raw[0].FPDEastTBLayer0[i] ;
226 trg->FPD_l1[0][1][i] = swap ? swap16(trgd->raw[0].FPDEastTBLayer1[i]) : trgd->raw[0].FPDEastTBLayer1[i] ;
230 trg->FPD[1][0][i] = trgd->raw[0].FPDWestNSLayer0[i] ;
233 trg->FPD_l1[1][0][i] = swap ? swap16(trgd->raw[0].FPDWestNSLayer1[i]) : trgd->raw[0].FPDWestNSLayer1[i];
237 trg->FPD[1][1][i] = trgd->raw[0].FPDWestTBLayer0[i] ;
240 trg->FPD_l1[1][1][i] = swap ? swap16(trgd->raw[0].FPDWestTBLayer1[i]) : trgd->raw[0].FPDWestTBLayer1[i];
246 for(i=0;i<(int)
sizeof(trgd->raw[0].BBC)/(int)
sizeof(trgd->raw[0].BBC[0]);i++) {
247 trg->BBC[i] = trgd->raw[0].BBC[i] ;
251 trg->BBC_l1[i] = swap ? swap16(trgd->raw[0].BBClayer1[i]) : trgd->raw[0].BBClayer1[i] ;
255 trg->ZDC[i] = trgd->raw[0].ZDC[i] ;
258 trg->ZDC_l1[i] = swap ? swap16(trgd->raw[0].ZDClayer1[i]) : trgd->raw[0].ZDClayer1[i];
262 trg->ZDCSMD[i] = trgd->raw[0].ZDCSMD[i] ;