8 #include <rtsSystems.h>
13 #define TRG_VERSION 0x30
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,
55 int trgReader30(
char *arg,
struct trg_t *trg)
58 int sdes, ssum, sraw ;
62 struct TRGD *trgd = (
struct TRGD *)arg ;
65 if(trgd->bh.byte_order != DAQ_RAW_FORMAT_ORDER) swap=1;
67 len = swap ? swap32(trgd->bh.length)*4 : trgd->bh.length*4;
69 sdes =
sizeof(trgd->bh) +
sizeof(trgd->desc) ;
70 ssum = sdes +
sizeof(trgd->sum) ;
73 LOG(NOTE,
"No TRG Summaries, or Raw...",0,0,0,0,0) ;
77 int rdb = swap ? swap16(trgd->raw[0].RawDetBytes) : trgd->raw[0].RawDetBytes;
81 int minsize =
sizeof(trgd->bh) +
sizeof(trgd->desc) +
sizeof(trgd->sum) + 1772;
85 LOG(NOTE,
"Trigger bank size smaller than minimum %d vs %d", sraw, minsize);
90 LOG(NOTE,
"Trigger Bank too small %d vs %d",len,sraw);
94 LOG(DBG,
"len %d, desc len %d, sum len %d, raw trg 0 len %d, all raw len %d",
95 len,
sizeof(trgd->desc),
sizeof(trgd->sum),
sizeof(trgd->raw[0]),
sizeof(trgd->raw)) ;
97 LOG(DBG,
"evt desc bytes %d, sum bytes %d, raw bytes %d",trgd->desc.TCUdataBytes,
98 trgd->sum.TrgSumBytes,trgd->raw[0].RawDetBytes,0,0) ;
101 trg->npre = swap ? swap16(trgd->desc.npre) : trgd->desc.npre ;
102 trg->npost = swap ? swap16(trgd->desc.npost) : trgd->desc.npost ;
104 trg->xing_lo = swap ? swap32(trgd->desc.bunchXing_lo) : trgd->desc.bunchXing_lo ;
105 trg->xing_hi = swap ? swap32(trgd->desc.bunchXing_hi) : trgd->desc.bunchXing_hi ;
107 trg->phys_word = swap ? swap16(trgd->desc.physicsWord) : trgd->desc.physicsWord ;
108 trg->trg_word = swap ? swap16(trgd->desc.TriggerWord) : trgd->desc.TriggerWord ;
110 trg->trgd = (
void *) trgd ;
115 unsigned int trg_length = len -
sizeof(
struct bankHeader) ;
131 LOG(ERR,
"Trigger data is too large: %d bytes more than max of %d",trg_length,
sizeof(
TrgDataType));
134 if(trg_length <
sizeof(
EvtDescData) +
sizeof(trgd->sum)) {
135 LOG(ERR,
"Trigger data is too small: %d bytes less than min of %d",trg_length,(
sizeof(
EvtDescData) +
sizeof(trgd->sum)));
139 trg->tcubits = swap ? swap16(trgd->desc.DSMInput) : trgd->desc.DSMInput;
140 trg->detlive = swap ? swap16(trgd->desc.externalBusy) : trgd->desc.externalBusy ;
143 LOG(DBG,
"TrgDataFmtVer 0x%X, 0x%04X %c %c", trgd->desc.TrgDataFmtVer,
144 trgd->sum.TrgSumHeader,
145 trgd->raw[0].CTBdataHeader[0],
146 trgd->raw[0].CTBdataHeader[1],0) ;
148 LOG(DBG,
"TrgSumBytes %d, 0x%04X %c %c %c", trgd->sum.TrgSumBytes,
149 trgd->sum.L0SumHeader,
150 trgd->raw[0].RawDetHeader[0],
151 trgd->raw[0].RawDetHeader[1],0) ;
158 trg->trg_sum = (
void *) &trg_sum ;
159 memset(&trg_sum,0,
sizeof(trg_sum)) ;
162 trg_sum.L1Sum[i] = swap ? swap32(trgd->sum.L1Sum[i]) : trgd->sum.L1Sum[i] ;
163 trg_sum.L2Sum[i] = swap ? swap32(trgd->sum.L2Sum[i]) : trgd->sum.L2Sum[i] ;
168 #define REAL_BAD_HACK(x) trg_sum.DSMdata.x = (swap ? swap16(trgd->sum.DSMdata.x) : trgd->sum.DSMdata.x)
170 for(i=0;i<8;i++) REAL_BAD_HACK(MTD[i]);
171 for(i=0;i<8;i++) REAL_BAD_HACK(VPD[i]);
172 for(i=0;i<16;i++) REAL_BAD_HACK(CPA[i]);
173 for(i=0;i<8;i++) REAL_BAD_HACK(CTB[i]);
174 for(i=0;i<8;i++) REAL_BAD_HACK(lastDSM[i]);
175 for(i=0;i<8;i++) REAL_BAD_HACK(VTX[i]);
176 for(i=0;i<8;i++) REAL_BAD_HACK(EMC[i]);
177 for(i=0;i<16;i++) REAL_BAD_HACK(BCdata[i]);
178 for(i=0;i<8;i++) REAL_BAD_HACK(specialTriggers[i]);
179 for(i=0;i<8;i++) REAL_BAD_HACK(FPD[i]);
186 trg->CTB[i] = trgd->raw[0].CTB[ctbMap[i]] ;
193 memset(trg->MWC, 0,
sizeof(trg->MWC));
195 for(i=0;i<32;i++) trg->MTD[i] = trgd->raw[0].MTD[i];
196 for(i=0;i<64;i++) trg->VPD[i] = trgd->raw[0].VPD[i];
197 for(i=0;i<16;i++) trg->TOF[i] = trgd->raw[0].TOF[i];
201 trg->BEMC[0][i] = trgd->raw[0].BEMCEast[i] ;
205 trg->BEMC[1][i] = trgd->raw[0].BEMCWest[i] ;
209 trg->BEMC_l1[i] = swap ? swap16(trgd->raw[0].BEMClayer1[i]) : trgd->raw[0].BEMClayer1[i] ;
215 trg->EEMC[i] = trgd->raw[0].EEMC[i] ;
218 trg->EEMC_l1[i] = swap ? swap16(trgd->raw[0].EEMClayer1[i]) : trgd->raw[0].EEMClayer1[i];
226 trg->FPD[0][0][i] = trgd->raw[0].FPDEastNSLayer0[i] ;
229 trg->FPD_l1[0][0][i] = swap ? swap16(trgd->raw[0].FPDEastNSLayer1[i]) : trgd->raw[0].FPDEastNSLayer1[i] ;
234 trg->FPD[0][1][i] = trgd->raw[0].FPDEastTBLayer0[i] ;
257 for(i=0;i<256;i++) trg->FPDW[i] = trgd->raw[0].FPDW[i];
261 for(i=0;i<(
int)
sizeof(trgd->raw[0].BBC)/(
int)
sizeof(trgd->raw[0].BBC[0]);i++) {
262 trg->BBC[i] = trgd->raw[0].BBC[i] ;
266 trg->BBC_l1[i] = swap ? swap16(trgd->raw[0].BBClayer1[i]) : trgd->raw[0].BBClayer1[i] ;
270 trg->ZDC[i] = trgd->raw[0].ZDC[i] ;
273 trg->ZDC_l1[i] = swap ? swap16(trgd->raw[0].ZDClayer1[i]) : trgd->raw[0].ZDClayer1[i];
277 trg->ZDCSMD[i] = trgd->raw[0].ZDCSMD[i] ;