7 #ifndef TRG_UTIL_2009_HH
8 #define TRG_UTIL_2009_HH
18 #include "RTS/trg/include/trgDataDefs_46.h"
19 #include "RTS/trg/include/trgConfNum.h"
21 #include "trgDataDefs_46.h"
22 #include "trgConfNum.h"
25 inline unsigned short bswap16(
unsigned short x) {
return bswap_16(x); }
26 inline unsigned int bswap32(
unsigned int x) {
return bswap_32(x); }
28 inline void swapTrgOfflen(
TrgOfflen& trgOfflen)
30 trgOfflen.offset = bswap32(trgOfflen.offset);
31 trgOfflen.length = bswap32(trgOfflen.length);
36 evtDesc.length = bswap32(evtDesc.length);
37 evtDesc.bunchXing_hi = bswap32(evtDesc.bunchXing_hi);
38 evtDesc.bunchXing_lo = bswap32(evtDesc.bunchXing_lo);
39 evtDesc.actionWdDetectorBitMask = bswap16(evtDesc.actionWdDetectorBitMask);
40 evtDesc.TrgToken = bswap16(evtDesc.TrgToken);
41 evtDesc.addBits = bswap16(evtDesc.addBits);
42 evtDesc.DSMInput = bswap16(evtDesc.DSMInput);
43 evtDesc.externalBusy = bswap16(evtDesc.externalBusy);
44 evtDesc.internalBusy = bswap16(evtDesc.internalBusy);
45 evtDesc.physicsWord = bswap16(evtDesc.physicsWord);
46 evtDesc.TriggerWord = bswap16(evtDesc.TriggerWord);
47 evtDesc.DSMAddress = bswap16(evtDesc.DSMAddress);
48 evtDesc.TCU_Mark = bswap16(evtDesc.TCU_Mark);
49 evtDesc.npre = bswap16(evtDesc.npre);
50 evtDesc.npost = bswap16(evtDesc.npost);
55 L1data.length = bswap32(L1data.length);
56 transform(L1data.TOF,L1data.TOF+8,L1data.TOF,bswap16);
57 transform(L1data.VTX,L1data.VTX+8,L1data.VTX,bswap16);
58 transform(L1data.EMC,L1data.EMC+8,L1data.EMC,bswap16);
59 transform(L1data.BCdata,L1data.BCdata+16,L1data.BCdata,bswap16);
60 transform(L1data.specialTriggers,L1data.specialTriggers+8,L1data.specialTriggers,bswap16);
61 transform(L1data.FPD,L1data.FPD+8,L1data.FPD,bswap16);
62 transform(L1data.lastDSM,L1data.lastDSM+8,L1data.lastDSM,bswap16);
67 trgSum.length = bswap32(trgSum.length);
68 transform(trgSum.L1Sum,trgSum.L1Sum+2,trgSum.L1Sum,bswap32);
69 transform(trgSum.L2Sum,trgSum.L2Sum+2,trgSum.L2Sum,bswap32);
70 transform(trgSum.L1Result,trgSum.L1Result+32,trgSum.L1Result,bswap32);
71 transform(trgSum.L2Result,trgSum.L2Result+64,trgSum.L2Result,bswap32);
72 transform(trgSum.C2Result,trgSum.C2Result+64,trgSum.C2Result,bswap32);
77 data.length = bswap32(data.length);
82 bc1.length = bswap32(bc1.length);
83 transform(bc1.BEMClayer1,bc1.BEMClayer1+48,bc1.BEMClayer1,bswap16);
84 transform(bc1.EEMClayer1,bc1.EEMClayer1+16,bc1.EEMClayer1,bswap16);
87 inline void swapMIXBlock(
MIXBlock& mix)
89 mix.length = bswap32(mix.length);
90 transform(mix.FPDEastNSLayer1,mix.FPDEastNSLayer1+8,mix.FPDEastNSLayer1,bswap16);
91 transform(mix.TOFLayer1,mix.TOFLayer1+8,mix.TOFLayer1,bswap16);
92 transform(mix.TOF,mix.TOF+48,mix.TOF,bswap16);
97 bcw.length = bswap32(bcw.length);
102 bce.length = bswap32(bce.length);
105 inline void swapBBCBlock(
BBCBlock& bbc)
107 bbc.length = bswap32(bbc.length);
108 transform(bbc.BBClayer1,bbc.BBClayer1+16,bbc.BBClayer1,bswap16);
109 transform(bbc.ZDClayer1,bbc.ZDClayer1+8,bbc.ZDClayer1,bswap16);
110 transform(bbc.VPD,bbc.VPD+8,bbc.VPD,bswap16);
113 inline void swapFMSBlock(
FMSBlock& fms)
115 fms.length = bswap32(fms.length);
118 inline void swapQTBlock(
QTBlock& qt)
120 qt.length = bswap32(qt.length);
121 qt.dataLoss = bswap32(qt.dataLoss);
130 assert(strncmp(bc1->name,
"BC1", 3) == 0);
131 swapBELayerBlock(*bc1);
137 assert(strncmp(mix->name,
"MIX", 3) == 0);
144 assert(strncmp(bcw->name,
"BCW", 3) == 0);
145 swapBWestBlock(*bcw);
151 assert(strncmp(bce->name,
"BCE", 3) == 0);
152 swapBEastBlock(*bce);
158 assert(strncmp(bbc->name,
"BBC", 3) == 0);
165 assert(strncmp(fms->name,
"FMS", 3) == 0);
175 assert(strncmp(qt->name,
"QT1", 3) == 0 ||
176 strncmp(qt->name,
"QT2", 3) == 0 ||
177 strncmp(qt->name,
"QT3", 3) == 0 ||
178 strncmp(qt->name,
"QT4", 3) == 0);
194 trgData.FormatVersion = bswap32(trgData.FormatVersion);
196 trgData.totalTriggerLength = bswap32(trgData.totalTriggerLength);
197 trgData.eventNumber = bswap32(trgData.eventNumber);
201 swapTrgOfflen(trgData.EventDesc_ofl);
203 assert(strncmp(evtDesc->name,
"EVD", 3) == 0 || strncmp(evtDesc->name,
"EVT", 3) == 0);
204 swapEvtDescData(*evtDesc);
208 swapTrgOfflen(trgData.L1_DSM_ofl);
210 assert(strncmp(L1data->name,
"L1DS", 4) == 0);
211 swapL1_DSM_Data(*L1data);
215 swapTrgOfflen(trgData.Summary_ofl);
217 assert(strncmp(trgSum->name,
"TSUM", 4) == 0);
218 swapTrgSumData(*trgSum);
222 for (
int crate = 0; crate < MAX_OFFLEN; ++crate) {
223 swapTrgOfflen(trgData.MainX[crate]);
224 if (trgData.MainX[crate].offset && trgData.MainX[crate].length) {
226 swapDataBlockAtCrate(*data, crate);
232 const int nentries = evtDesc->npre + evtDesc->npost;
234 for (
int i = 0; i < nentries; ++i) {
235 trgData.PrePostList[i] = bswap32(trgData.PrePostList[i]);
237 for (
int crate = 0; crate < MAX_OFFLEN; ++crate) {
238 swapTrgOfflen(PrePostX[crate]);
239 if (PrePostX[crate].offset && PrePostX[crate].length) {
241 swapDataBlockAtCrate(*data, crate);
247 inline void printName(
const char* name)
250 for (
int i = 0; i < 4; ++i) putchar(name[i]);
254 inline void printEvtDescData(
const EvtDescData& evtDesc)
256 printName(evtDesc.name);
257 printf(
"TrgDataFmtVer: 0x%x\n", evtDesc.TrgDataFmtVer);
258 printf(
"length: %d\n", evtDesc.length);
259 printf(
"bunchXing_hi: %d\n", evtDesc.bunchXing_hi);
260 printf(
"bunchXing_lo: %d\n", evtDesc.bunchXing_lo);
261 printf(
"actionWdDetectorBitMask: %d\n", evtDesc.actionWdDetectorBitMask);
262 printf(
"actionWdTrgCommand: %d\n", evtDesc.actionWdTrgCommand);
263 printf(
"actionWdDaqCommand: %d\n", evtDesc.actionWdDaqCommand);
264 printf(
"TrgToken: %d\n", evtDesc.TrgToken);
265 printf(
"addBits: %d\n", evtDesc.addBits);
266 printf(
"DSMInput: %d\n", evtDesc.DSMInput);
267 printf(
"externalBusy: %d\n", evtDesc.externalBusy);
268 printf(
"internalBusy: %d\n", evtDesc.internalBusy);
269 printf(
"physicsWord: %d\n", evtDesc.physicsWord);
270 printf(
"TriggerWord: %d\n", evtDesc.TriggerWord);
271 printf(
"DSMAddress: %d\n", evtDesc.DSMAddress);
272 printf(
"TCU_Mark: %d\n", evtDesc.TCU_Mark);
273 printf(
"npre: %d\n", evtDesc.npre);
274 printf(
"npost: %d\n", evtDesc.npost);
277 inline void printL1_DSM_Data(
const L1_DSM_Data& L1data)
279 printName(L1data.name);
280 printf(
"length: %d\n", L1data.length);
282 for (
int i = 0; i < 8; ++i) printf(
"%04x ", L1data.TOF[i]);
285 for (
int i = 0; i < 8; ++i) printf(
"%04x ", L1data.VTX[i]);
288 for (
int i = 0; i < 8; ++i) printf(
"%04x ", L1data.EMC[i]);
291 for (
int i = 0; i < 16; ++i) {
292 printf(
"%04x ", L1data.BCdata[i]);
293 if (i % 8 == 7) printf(
"\n");
295 printf(
"specialTriggers: ");
296 for (
int i = 0; i < 8; ++i) printf(
"%04x ", L1data.specialTriggers[i]);
299 for (
int i = 0; i < 8; ++i) printf(
"%04x ", L1data.FPD[i]);
302 for (
int i = 0; i < 8; ++i) printf(
"%04x ", L1data.lastDSM[i]);
306 inline void printTrgSumData(
const TrgSumData& trgSum)
308 printName(trgSum.name);
309 printf(
"length: %d\n", trgSum.length);
311 for (
int i = 0; i < 2; ++i) printf(
"%08x ", trgSum.L1Sum[i]);
314 for (
int i = 0; i < 2; ++i) printf(
"%08x ", trgSum.L2Sum[i]);
316 printf(
"L1Result:\n");
317 for (
int i = 0; i < 32; ++i) {
318 printf(
"%08x ", trgSum.L1Result[i]);
319 if (i % 8 == 7) printf(
"\n");
321 printf(
"L2Result:\n");
322 for (
int i = 0; i < 64; ++i) {
323 printf(
"%08x ", trgSum.L2Result[i]);
324 if (i %8 == 7) printf(
"\n");
326 printf(
"C2Result:\n");
327 for (
int i = 0; i < 64; ++i) {
328 printf(
"%08x ", trgSum.C2Result[i]);
329 if (i % 8 == 7) printf(
"\n");
333 inline void printMIXBlock(
const MIXBlock& mix)
336 printf(
"length: %d\n", mix.length);
337 printf(
"FPDEastNSLayer1: ");
338 for (
int i = 0; i < 8; ++i) printf(
"%04x ", mix.FPDEastNSLayer1[i]);
340 printf(
"MTD_P2PLayer1:\n");
341 for (
int i = 0; i < 16; ++i) {
342 printf(
"%x ", mix.MTD_P2PLayer1[i]);
343 if (i % 8 == 7) printf(
"\n");
345 printf(
"TOFLayer1: ");
346 for (
int i = 0; i < 8; ++i) printf(
"%04x ", mix.TOFLayer1[i]);
349 for (
int i = 0; i < 48; ++i) {
350 printf(
"%04x ", mix.TOF[i]);
351 if (i % 8 == 7) printf(
"\n");
355 inline void printBBCBlock(
const BBCBlock& bbc)
358 printf(
"length: %d\n", bbc.length);
359 printf(
"BBClayer1:\n");
360 for (
int i = 0; i < 16; ++i) {
361 printf(
"%04x ", bbc.BBClayer1[i]);
362 if (i % 8 == 7) printf(
"\n");
364 printf(
"ZDClayer1:\n");
365 for (
int i = 0; i < 8; ++i) printf(
"%04x ", bbc.ZDClayer1[i]);
368 for (
int i = 0; i < 8; ++i) printf(
"%04x ", bbc.VPD[i]);
372 inline void printFMSBlock(
const FMSBlock& fms)
375 printf(
"length: %d\n", fms.length);
376 for (
int i = 0; i < 256; ++i) {
377 printf(
"%02x ", fms.FMS[i]);
378 if (i % 16 == 15) printf(
"\n");
382 inline void printQTBlock(
const QTBlock& qt)
385 printf(
"length: %d\n", qt.length);
386 printf(
"dataLoss: %d\n", qt.dataLoss);
387 int len = qt.length-4;
388 unsigned char* data = (
unsigned char*)&qt.data;
389 for (
int i = 0; i < len; ++i) {
390 printf(
"%02x ", data[i]);
391 if (i % 16 == 15) printf(
"\n");
398 printf(
"length: %d\n", bc1.length);
399 printf(
"BEMClayer1:\n");
400 for (
int i = 0; i < 48; ++i) {
401 printf(
"%04x ", bc1.BEMClayer1[i]);
402 if (i % 8 == 7) printf(
"\n");
404 printf(
"EEMClayer1:\n");
405 for (
int i = 0; i < 16; ++i) {
406 printf(
"%04x ", bc1.EEMClayer1[i]);
407 if (i % 8 == 7) printf(
"\n");
410 for (
int i = 0; i < 144; ++i) {
411 printf(
"%02x ", bc1.EEMC[i]);
412 if (i % 16 == 15) printf(
"\n");
416 inline void printBWestBlock(
const BWestBlock& bcw)
419 printf(
"length: %d\n", bcw.length);
420 printf(
"BEMCWest:\n");
421 for (
int i = 0; i < 240; ++i) {
422 printf(
"%02x ", bcw.BEMCWest[i]);
423 if (i % 16 == 15) printf(
"\n");
427 inline void printBEastBlock(
const BEastBlock& bce)
430 printf(
"length: %d\n", bce.length);
431 printf(
"BEMCEast:\n");
432 for (
int i = 0; i < 240; ++i) {
433 printf(
"%02x ", bce.BEMCEast[i]);
434 if (i % 16 == 15) printf(
"\n");
438 inline void printDataBlock(
const DataBlock& dataBlock)
440 printName(dataBlock.name);
441 printf(
"length: %d\n", dataBlock.length);
444 #endif // TRG_UTIL_2009_HH