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