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