StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTriggerData2018.cxx
1 /***************************************************************************
2  *
3  * $Id: StTriggerData2018.cxx,v 2.3 2018/06/06 18:03:59 ullrich Exp $
4  *
5  * Author: Akio Ogawa, October 13, 2017
6  ***************************************************************************
7  *
8  * Description: Concrete implementation of StTriggerData for 2018.
9  *
10  ***************************************************************************
11  *
12  * $Log: StTriggerData2018.cxx,v $
13  * Revision 2.3 2018/06/06 18:03:59 ullrich
14  * Added fcts: epdNHits, vpdADCSum, vpdMeanTimeDifference (Akio)
15  *
16  * Revision 2.2 2018/02/22 16:47:20 ullrich
17  * Changes for blind analysis and EPD
18  *
19  * Revision 2.1 2017/10/13 20:10:17 ullrich
20  * Initial Revision.
21  *
22  *
23  **************************************************************************/
24 #include <string.h>
25 #include <assert.h>
26 #include <iostream>
27 #include "StTriggerData2018.h"
28 
29 ClassImp(StTriggerData2018)
30 
32 {
33  mDebug = 0;
34  // printf("StTriggerData2018 Default Constructor\n");
35 }
36 
37 StTriggerData2018::StTriggerData2018(const TriggerDataBlk2018* data, int run):mData()
38 {
39  //printf("StTriggerData2018 Constructor with trigger data block\n");
40  mYear=2018; mRun = run; mDebug = 0;
41  mData = new TriggerDataBlk2018;
42  readData(data,1);
43 }
44 
45 StTriggerData2018::StTriggerData2018(const TriggerDataBlk2018* data, int run, int bs, int dbg):mData()
46 {
47  mYear=2018; mRun = run; mDebug = dbg;
48  if(mDebug==1) printf("StTriggerData2018 Constructor with trigger data block and byteswap option=%d\n",bs);
49  mData = new TriggerDataBlk2018;
50  readData(data,bs);
51 }
52 
53 void StTriggerData2018::blindRunInfo()
54 {
55  mRun=1000000*int(mRun/1000000);
56  mData->eventNumber = 0;
57  EvtDesc->bunchXing_hi = 0;
58  EvtDesc->bunchXing_lo = 0;
59  L1_DSM->BCdata[2] = 0;
60  L1_DSM->BCdata[3] = 0;
61  L1_DSM->BCdata[10] = 0;
62  L1_DSM->BCdata[11] = 0;
63 }
64 
65 void StTriggerData2018::readData(const TriggerDataBlk2018* data, int bs) {
66  int copyflag=1;
67  if (data==0) {copyflag=0;}
68  if(mDebug==1) printf("StTriggerData2018::readData copyflag=%d byteswap=%d data=%p mData=%p\n",copyflag,bs,data,mData);
69 
70  if (copyflag==1){
71  unsigned int ver = data->FormatVersion;
72  if (bs) swapI(&ver);
73 
74  if (ver == y18FORMAT_VERSION ) {
75  if (mDebug==1) printf("StTriggerData2018: version = 0x%x (0x%x or 0x08121140)\n",ver,y18FORMAT_VERSION);
76  }
77  else {
78  mErrorFlag = mErrorFlag | 0x1;
79  printf("StTriggerData2018: version = 0x%x != (0x%x)\n",ver,y18FORMAT_VERSION);
80  assert(0);
81  }
82 
83  unsigned int size = data->totalTriggerLength;
84  if (bs) swapI(&size);
85  if (size > y18MAX_TRG_BLK_SIZE) {
86  gMessMgr->Warning() << "StTriggerData2018: Data length = " << size
87  << " is bigger than max = " << y18MAX_TRG_BLK_SIZE
88  << endm;
89  assert(0);
90  }
91  if (mDebug==1) printf("StTriggerData2018: size = %d, maxsize = %d\n",size,y18MAX_TRG_BLK_SIZE);
92  memcpy(mData,data,size);
93  memset((char*)mData+size,0,sizeof(TriggerDataBlk2018)-size);
94  }
95 
96  if (bs) swapDataBlk(mData);
97  if (mDebug==1){
98  printf("StTriggerData2018: version = 0x%x (0x%x)\n",mData->FormatVersion,y18FORMAT_VERSION);
99  printf("StTriggerData2018: size = %d, maxsize = %d\n",mData->totalTriggerLength,y18MAX_TRG_BLK_SIZE);
100  printf("EventDesc length=%10d offset=%10d\n",mData->EventDesc_ofl.length,mData->EventDesc_ofl.offset);
101  printf("L1_DSM length=%10d offset=%10d\n",mData->L1_DSM_ofl.length,mData->L1_DSM_ofl.offset);
102  printf("Summary length=%10d offset=%10d\n",mData->Summary_ofl.length,mData->Summary_ofl.offset);
103  }
104 
105  EvtDesc=0; L1_DSM=0; TrgSum=0;
106  if (mData->EventDesc_ofl.length > 0) EvtDesc = (EvtDescData2018*)((char*)mData + mData->EventDesc_ofl.offset);
107  if (mData->L1_DSM_ofl.length > 0) L1_DSM = (L1_DSM_Data2018*)((char*)mData + mData->L1_DSM_ofl.offset);
108  if (mData->Summary_ofl.length > 0) TrgSum = (TrgSumData2018* )((char*)mData + mData->Summary_ofl.offset);
109  if (bs){
110  if (EvtDesc) swapEvtDesc(EvtDesc);
111  if (L1_DSM) swapL1_DSM(L1_DSM);
112  if (TrgSum) swapTrgSum(TrgSum);
113  }
114  if (EvtDesc==0 || L1_DSM==0 || TrgSum==0){
115  mErrorFlag = mErrorFlag | 0x1;
116  gMessMgr->Warning() << "StTriggerData2018: EvtDesc, L1_DSM or TrgSum is missing"
117  <<" mErrorFlag="<<mErrorFlag<<endm;
118  }
119 
120  int npre = numberOfPreXing();
121  int npost = numberOfPostXing();
122  if (npre<0 || npre>10 || npost<0 || npost>10){
123  mErrorFlag = mErrorFlag | 0x2;
124  gMessMgr->Warning() << "StTriggerData2018: Invalid npre/post = "<< npre << " / " << npost
125  <<" mErrorFlag="<<mErrorFlag<<endm;
126  }
127  if (mDebug==1) printf("StTriggerData2018: pre=%d post=%d\n",npre,npost);
128 
129  memset(mBC1,0,sizeof(mBC1));
130  memset(mMXQ,0,sizeof(mMXQ));
131  memset(mMIX,0,sizeof(mMIX));
132  memset(mBCW,0,sizeof(mBCW));
133  memset(mBCE,0,sizeof(mBCE));
134  memset(mEQ3,0,sizeof(mEQ3));
135  memset(mBBC,0,sizeof(mBBC));
136  memset(mBBQ,0,sizeof(mBBQ));
137  memset(mFMS,0,sizeof(mFMS));
138  memset(mQT1,0,sizeof(mQT1));
139  memset(mQT2,0,sizeof(mQT2));
140  memset(mQT3,0,sizeof(mQT3));
141  memset(mQT4,0,sizeof(mQT4));
142  memset(mEQ1,0,sizeof(mEQ1));
143  memset(mEQ2,0,sizeof(mEQ2));
144  memset(mxq,0,sizeof(mxq)); memset(tmxq,0,sizeof(tmxq));
145  memset(eq3,0,sizeof(eq3)); memset(teq3,0,sizeof(teq3));
146  memset(bbq,0,sizeof(bbq)); memset(tbbq,0,sizeof(tbbq));
147  memset(qt1,0,sizeof(qt1)); memset(tqt1,0,sizeof(tqt1));
148  memset(qt2,0,sizeof(qt2)); memset(tqt2,0,sizeof(tqt2));
149  memset(qt3,0,sizeof(qt3)); memset(tqt3,0,sizeof(tqt3));
150  memset(qt4,0,sizeof(qt4)); memset(tqt4,0,sizeof(tqt4));
151  memset(eq1,0,sizeof(eq1)); memset(teq1,0,sizeof(teq1));
152  memset(eq2,0,sizeof(eq2)); memset(teq2,0,sizeof(teq2));
154 
155  for (int i=0; i<1+npre+npost; i++) {
156  //printf("Doing prepost = %d\n",i);
157  if (i==0) {
158  offlen = mData->MainX;
159  }
160  else {
161  //printf("Prepost list offset = %d\n",mData->PrePostList[i-1]);
162  if (mData->PrePostList[i-1]==0) continue;
163  offlen = (TrgOfflen2018*) ((char*)mData + mData->PrePostList[i-1]);
164  }
165  if (bs) swapRawDetOfflen(offlen);
166  for(int k=0; k<y18MAX_OFFLEN; k++) {
167  if(static_cast<unsigned int>(offlen[k].length + offlen[k].offset) > static_cast<unsigned int>(mData->totalTriggerLength)) {
168  mErrorFlag = mErrorFlag | (1 << k);
169  gMessMgr->Warning() << "StTriggerData2018: offset ("<<offlen[k].offset<<") + length ("<<offlen[k].length
170  <<") exceeds total size("<<mData->totalTriggerLength<<") for data block id="<<k
171  <<" mErrorFlag="<<mErrorFlag<<endm;
172  }
173  }
174  int j;
175  j=offlen[y18BC1_CONF_NUM].length; if (j>0){mBC1[i] = (BELayerBlock2018*)((char*)mData + offlen[y18BC1_CONF_NUM].offset); swapRawDet((DataBlock2018*)mBC1[i],y18BC1_CONF_NUM,j,bs);}
176  j=offlen[y18MXQ_CONF_NUM].length; if (j>0){mMXQ[i] = (QTBlock2018* )((char*)mData + offlen[y18MXQ_CONF_NUM].offset); swapRawDet((DataBlock2018*)mMXQ[i],y18MXQ_CONF_NUM,j,bs);}
177  j=offlen[y18MIX_CONF_NUM].length; if (j>0){mMIX[i] = (MIXBlock2018* )((char*)mData + offlen[y18MIX_CONF_NUM].offset); swapRawDet((DataBlock2018*)mMIX[i],y18MIX_CONF_NUM,j,bs);}
178  j=offlen[y18BCW_CONF_NUM].length; if (j>0){mBCW[i] = (BWestBlock2018* )((char*)mData + offlen[y18BCW_CONF_NUM].offset); swapRawDet((DataBlock2018*)mBCW[i],y18BCW_CONF_NUM,j,bs);}
179  j=offlen[y18BCE_CONF_NUM].length; if (j>0){mBCE[i] = (BEastBlock2018* )((char*)mData + offlen[y18BCE_CONF_NUM].offset); swapRawDet((DataBlock2018*)mBCE[i],y18BCE_CONF_NUM,j,bs);}
180  j=offlen[y18EQ3_CONF_NUM].length; if (j>0){mEQ3[i] = (QTBlock2018* )((char*)mData + offlen[y18EQ3_CONF_NUM].offset); swapRawDet((DataBlock2018*)mEQ3[i],y18EQ3_CONF_NUM,j,bs);}
181  j=offlen[y18BBC_CONF_NUM].length; if (j>0){mBBC[i] = (BBCBlock2018* )((char*)mData + offlen[y18BBC_CONF_NUM].offset); swapRawDet((DataBlock2018*)mBBC[i],y18BBC_CONF_NUM,j,bs);}
182  j=offlen[y18BBQ_CONF_NUM].length; if (j>0){mBBQ[i] = (QTBlock2018* )((char*)mData + offlen[y18BBQ_CONF_NUM].offset); swapRawDet((DataBlock2018*)mBBQ[i],y18BBQ_CONF_NUM,j,bs);}
183  j=offlen[y18FMS_CONF_NUM].length; if (j>0){mFMS[i] = (FMSBlock2018* )((char*)mData + offlen[y18FMS_CONF_NUM].offset); swapRawDet((DataBlock2018*)mFMS[i],y18FMS_CONF_NUM,j,bs);}
184  j=offlen[y18QT1_CONF_NUM].length; if (j>0){mQT1[i] = (QTBlock2018* )((char*)mData + offlen[y18QT1_CONF_NUM].offset); swapRawDet((DataBlock2018*)mQT1[i],y18QT1_CONF_NUM,j,bs);}
185  j=offlen[y18QT2_CONF_NUM].length; if (j>0){mQT2[i] = (QTBlock2018* )((char*)mData + offlen[y18QT2_CONF_NUM].offset); swapRawDet((DataBlock2018*)mQT2[i],y18QT2_CONF_NUM,j,bs);}
186  j=offlen[y18QT3_CONF_NUM].length; if (j>0){mQT3[i] = (QTBlock2018* )((char*)mData + offlen[y18QT3_CONF_NUM].offset); swapRawDet((DataBlock2018*)mQT3[i],y18QT3_CONF_NUM,j,bs);}
187  j=offlen[y18QT4_CONF_NUM].length; if (j>0){mQT4[i] = (QTBlock2018* )((char*)mData + offlen[y18QT4_CONF_NUM].offset); swapRawDet((DataBlock2018*)mQT4[i],y18QT4_CONF_NUM,j,bs);}
188  j=offlen[y18EQ1_CONF_NUM].length; if (j>0){mEQ1[i] = (QTBlock2018* )((char*)mData + offlen[y18EQ1_CONF_NUM].offset); swapRawDet((DataBlock2018*)mEQ1[i],y18EQ1_CONF_NUM,j,bs);}
189  j=offlen[y18EQ2_CONF_NUM].length; if (j>0){mEQ2[i] = (QTBlock2018* )((char*)mData + offlen[y18EQ2_CONF_NUM].offset); swapRawDet((DataBlock2018*)mEQ2[i],y18EQ2_CONF_NUM,j,bs);}
190  if (mMXQ[i]) decodeQT(mMXQ[i]->length/4, mMXQ[i]->data, mxq[i], tmxq[i]);
191  if (mEQ3[i]) decodeQT(mEQ3[i]->length/4, mEQ3[i]->data, eq3[i], teq3[i]);
192  if (mBBQ[i]) decodeQT(mBBQ[i]->length/4, mBBQ[i]->data, bbq[i], tbbq[i]);
193  if (mQT1[i]) decodeQT(mQT1[i]->length/4, mQT1[i]->data, qt1[i], tqt1[i]);
194  if (mQT2[i]) decodeQT(mQT2[i]->length/4, mQT2[i]->data, qt2[i], tqt2[i]);
195  if (mQT3[i]) decodeQT(mQT3[i]->length/4, mQT3[i]->data, qt3[i], tqt3[i]);
196  if (mQT4[i]) decodeQT(mQT4[i]->length/4, mQT4[i]->data, qt4[i], tqt4[i]);
197  if (mEQ1[i]) decodeQT(mEQ1[i]->length/4, mEQ1[i]->data, eq1[i], teq1[i]);
198  if (mEQ2[i]) decodeQT(mEQ2[i]->length/4, mEQ2[i]->data, eq2[i], teq2[i]);
199  }
200  if (mDebug==1) dump();
201 }
202 
203 StTriggerData2018::~StTriggerData2018() {delete mData;}
204 
205 unsigned int StTriggerData2018::version() const
206 {
207  return EvtDesc->TrgDataFmtVer;
208 }
209 
210 unsigned int StTriggerData2018::eventNumber() const
211 {
212  return mData->eventNumber;
213 }
214 
215 unsigned int StTriggerData2018::token() const
216 {
217  return EvtDesc->TrgToken;
218 }
219 
220 unsigned int StTriggerData2018::triggerWord() const
221 {
222  return 0;
223 }
224 
225 unsigned int StTriggerData2018::actionWord() const
226 {
227  return
228  ( (unsigned short)(EvtDesc->actionWdTrgCommand) * 16 * 16 * 16 ) +
229  ( (unsigned short)(EvtDesc->actionWdDaqCommand) * 16 * 16 ) +
230  ( EvtDesc->actionWdDetectorBitMask & 0x00ff );
231 }
232 
233 unsigned int StTriggerData2018::numberOfPreXing() const
234 {
235  return EvtDesc->npre & 0xf;
236 }
237 
238 unsigned int StTriggerData2018::numberOfPostXing() const
239 {
240  return EvtDesc->npost & 0xf;
241 }
242 
243 unsigned short StTriggerData2018::busyStatus() const
244 {
245  return EvtDesc->internalBusy;
246 }
247 
248 unsigned short StTriggerData2018::dsmInput() const
249 {
250  return EvtDesc->DSMInput;
251 }
252 
253 unsigned short StTriggerData2018::trgToken() const
254 {
255  return EvtDesc->TrgToken;
256 }
257 
258 unsigned short StTriggerData2018::dsmAddress() const
259 {
260  return EvtDesc->DSMAddress;
261 }
262 
263 unsigned short StTriggerData2018::mAddBits() const
264 {
265  return EvtDesc->addBits;
266 }
267 
268 unsigned short StTriggerData2018::bcData(int channel) const
269 {
270  return L1_DSM->BCdata[channel];
271 }
272 
273 unsigned short StTriggerData2018::getTrgDetMask() const
274 {
275  return EvtDesc->trgDetMask;
276 }
277 
278 unsigned int StTriggerData2018::getTrgCrateMask() const
279 {
280  unsigned int p = EvtDesc->npost & 0xfff0;
281  unsigned int r = EvtDesc->res1 & 0x0ff0;
282  return
283  ( ((EvtDesc->npre & 0xfff0) >> 4)
284  + (p << 8)
285  + (r << 20) );
286 }
287 
288 unsigned short StTriggerData2018::lastDSM(int channel) const
289 {
290  return L1_DSM->lastDSM[channel];
291 }
292 
293 
294 unsigned short StTriggerData2018::vertexDSM(int channel) const
295 {
296  int dsmmap[8] = {3,2,1,0,7,6,5,4};
297  if(channel<0 || channel>7) return 0;
298  return L1_DSM->VTX[dsmmap[channel]];
299 }
300 
301 unsigned short StTriggerData2018::tcuBits() const
302 {
303  return EvtDesc->DSMInput;
304 }
305 
306 
307 unsigned int StTriggerData2018::tcuCounter() const
308 {
309  unsigned int hi = EvtDesc->tcuCtrBunch_hi;
310  return (hi << 16) + EvtDesc->DSMAddress;
311 }
312 
313 unsigned int StTriggerData2018::rccCounter(int crate) const
314 {
315  if(crate >= y18L1_CONF_NUM && crate <= y18EQ2_CONF_NUM){
316  return TrgSum->LocalClocks[crate];
317  }
318  return 0;
319 }
320 
321 unsigned long long StTriggerData2018::bunchCounter() const
322 {
323  unsigned long long bxinghi,bxing1,bxinglo, bx;
324  bxinghi = L1_DSM->BCdata[3];
325  bxing1 = L1_DSM->BCdata[10];
326  bxinglo = (bxing1 << 16) + L1_DSM->BCdata[11];
327  bx = (bxinghi << 32) + bxinglo;
328  return bx;
329 }
330 
331 unsigned int StTriggerData2018::bunchCounterHigh() const
332 {
333  return EvtDesc->bunchXing_hi;
334 }
335 
336 unsigned int StTriggerData2018::bunchCounterLow() const
337 {
338  return EvtDesc->bunchXing_lo;
339 }
340 
341 unsigned int StTriggerData2018::bunchId48Bit() const
342 {
343  return (int)(bunchCounter() % 120);
344 }
345 
346 unsigned int StTriggerData2018::bunchId7Bit() const
347 {
348  int b7=0, b7dat;
349  b7dat = L1_DSM->BCdata[2];
350  b7 = b7dat & 0x7f;
351  return b7;
352 }
353 
354 unsigned int StTriggerData2018::spinBit() const
355 {
356  if(mRun<12000000){
357  return (L1_DSM->lastDSM[7]/16)%256;
358  }else{
359  return (L1_DSM->lastDSM[4]/16)%256;
360  }
361 }
362 
363 unsigned int StTriggerData2018::spinBitYellowFilled() const
364 {
365  unsigned int sb = spinBit();
366  return sb%2;
367 }
368 
369 unsigned int StTriggerData2018::spinBitYellowUp() const
370 {
371  unsigned int sb = spinBit();
372  return (sb/2)%2;
373 }
374 
375 unsigned int StTriggerData2018::spinBitYellowDown() const
376 {
377  unsigned int sb = spinBit();
378  return (sb/4)%2;
379 }
380 
381 unsigned int StTriggerData2018::spinBitYellowUnpol() const
382 {
383  unsigned int sb = spinBit();
384  return (sb/8)%2;
385 }
386 
387 unsigned int StTriggerData2018::spinBitBlueFilled() const
388 {
389  unsigned int sb = spinBit();
390  return (sb/16)%2;
391 }
392 
393 unsigned int StTriggerData2018::spinBitBlueUp() const
394 {
395  unsigned int sb = spinBit();
396  return (sb/32)%2;
397 }
398 
399 unsigned int StTriggerData2018::spinBitBlueDown() const
400 {
401  unsigned int sb = spinBit();
402  return (sb/64)%2;
403 }
404 
405 unsigned int StTriggerData2018::spinBitBlueUnpol() const
406 {
407  unsigned int sb = spinBit();
408  return (sb/128)%2;
409 }
410 
411 unsigned short StTriggerData2018::bbcADC(StBeamDirection eastwest, int pmt, int prepost) const
412 {
413  const int addrmap[2][24] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
414  4, 4, 4, 4, 4, 4, 4, 4},
415  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
416  4, 4, 4, 4, 4, 4, 4, 4} };
417  const int chmap[2][24] = { { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
418  0, 1, 2, 3, 8, 9,10,11},
419  { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
420  16,17,18,19,24,25,26,27} };
421  int buffer = prepostAddress(prepost);
422  if (buffer >= 0 && pmt>=1 && pmt<=16) return bbq[buffer][addrmap[eastwest][pmt-1]][chmap[eastwest][pmt-1]];
423  return 0;
424 }
425 
426 unsigned short StTriggerData2018::bbcTDC(StBeamDirection eastwest, int pmt, int prepost) const
427 {
428  const int addrmap[2][24] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
429  4, 4, 4, 4, 4, 4, 4, 4},
430  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
431  4, 4, 4, 4, 4, 4, 4, 4} };
432  const int chmap[2][24] = { { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
433  0, 1, 2, 3, 8, 9,10,11},
434  { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
435  16,17,18,19,24,25,26,27} };
436  int buffer = prepostAddress(prepost);
437  if (buffer >= 0 && pmt>=1 && pmt<=16) return bbq[buffer][addrmap[eastwest][pmt-1]][chmap[eastwest][pmt-1]+4];
438  return 0;
439 }
440 
441 unsigned short StTriggerData2018::bbcTDC5bit(StBeamDirection eastwest, int pmt, int prepost) const
442 {
443  const int addrmap[2][24] = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
444  4, 4, 4, 4, 4, 4, 4, 4},
445  { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
446  4, 4, 4, 4, 4, 4, 4, 4} };
447  const int chmap[2][24] = { { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
448  0, 1, 2, 3, 8, 9,10,11},
449  { 0, 3, 8,16,19,24, 1, 2, 9,10,11,17,18,25,26,27,
450  16,17,18,19,24,25,26,27} };
451  int buffer = prepostAddress(prepost);
452  if (buffer >= 0 && pmt>=1 && pmt<=16) return tbbq[buffer][addrmap[eastwest][pmt-1]][chmap[eastwest][pmt-1]];
453  return 0;
454 }
455 
456 unsigned short StTriggerData2018::bbcADCSum(StBeamDirection eastwest, int prepost) const
457 {
458  unsigned short sum=0;
459  int buffer = prepostAddress(prepost);
460  //if (buffer >= 0) for(int i=1; i<=16; i++) {sum+=bbcADC(eastwest,i,prepost);}
461  if(buffer>=0){
462  if (mBBC[buffer]){
463  if(eastwest==east) { sum = mBBC[buffer]->BBClayer1[3]; }
464  else { sum = mBBC[buffer]->BBClayer1[1]; }
465  }
466  }
467  return sum;
468 }
469 
470 unsigned short StTriggerData2018::bbcADCSumLargeTile(StBeamDirection eastwest, int prepost) const
471 {
472  unsigned short sum=0;
473  //int buffer = prepostAddress(prepost);
474  //if (buffer >= 0) for(int i=17; i<=24; i++) {sum+=bbcADC(eastwest,i,prepost);}
475  return sum;
476 }
477 
478 unsigned short StTriggerData2018::bbcEarliestTDC(StBeamDirection eastwest, int prepost) const
479 {
480  int buffer = prepostAddress(prepost);
481  if (buffer >=0){
482  if (mBBC[buffer]){
483  if (eastwest==east) {return mBBC[buffer]->BBClayer1[2]%4096;}
484  else {return mBBC[buffer]->BBClayer1[0]%4096;}
485  }
486  }
487  return 0;
488 }
489 
490 unsigned short StTriggerData2018::bbcTimeDifference() const
491 {
492  return L1_DSM->VTX[3]%8192;
493 }
494 
495 unsigned short StTriggerData2018::bbcTacSum() const
496 {
497  return (((L1_DSM->VTX[3]) >> 13) & 0x1);
498 }
499 
500 unsigned short StTriggerData2018::bbcEarliestTDCLarge(StBeamDirection eastwest, int prepost) const
501 {
502  //int buffer = prepostAddress(prepost);
503  //if (buffer >=0){
504  // if (mBBC[buffer]){
505  // if (eastwest==east) {return mBBC[buffer]->BBClayer1[11] & 0x0fff;}
506  // else {return ((mBBC[buffer]->BBClayer1[11] & 0xf000) >> 12)
507  // +((mBBC[buffer]->BBClayer1[10] & 0x00ff) << 4 );}
508  // }
509  // }
510  return 0;
511 }
512 
513 unsigned short StTriggerData2018::bbcTimeDifferenceLarge() const
514 {
515  return L1_DSM->VTX[2]%8192;
516 }
517 
518 
519 unsigned short StTriggerData2018::bbcBB101(int ch, int prepost) const
520 {
521  int dsmmap[8] = {3,2,1,0,7,6,5,4};
522  int buffer = prepostAddress(prepost);
523  if (buffer>=0){
524  if (mBBC[buffer]){
525  if(ch>=0 && ch<=7) return mBBC[buffer]->BBClayer1[dsmmap[ch]];
526  }
527  }
528  return 0;
529 }
530 
531 unsigned short StTriggerData2018::bbcBB102(int ch, int prepost) const
532 {
533  int dsmmap[8] = {3,2,1,0,7,6,5,4};
534  int buffer = prepostAddress(prepost);
535  if (buffer>=0){
536  if (mBBC[buffer]){
537  if(ch>=0 && ch<=7) return mBBC[buffer]->BBClayer1[dsmmap[ch]+8];
538  }
539  }
540  return 0;
541 }
542 
543 unsigned short StTriggerData2018::epdTimeDifference() const
544 {
545  return L1_DSM->VTX[6]%8192;
546 }
547 
548 bool StTriggerData2018::epdHitLayer2(StBeamDirection eastwest) const
549 {
550  if(eastwest==east) return (L1_DSM->VTX[6] & 0x40) ? true : false;
551  return (L1_DSM->VTX[6] & 0x80) ? true : false;
552 }
553 
554 unsigned short StTriggerData2018::epdLayer0t(int ch, int prepost) const
555 {
556  int dsmmap[16] = {3,2,1,0,7,6,5,4, 11,10,9,8,15,14,13,12};
557  int buffer = prepostAddress(prepost);
558  if (buffer>=0){
559  if (mBBC[buffer]){
560  if(ch>=0 && ch<16) return mBBC[buffer]->EPDlayer0t[dsmmap[ch]];
561  }
562  }
563  return 0;
564 }
565 
566 unsigned short StTriggerData2018::epdLayer1(int ch, int prepost) const
567 {
568  int dsmmap[8] = {3,2,1,0,7,6,5,4};
569  int buffer = prepostAddress(prepost);
570  if (buffer>=0){
571  if (mBBC[buffer]){
572  if(ch>=0 && ch<8) return mBBC[buffer]->EPDlayer1[dsmmap[ch]];
573  }
574  }
575  return 0;
576 }
577 
578 unsigned short StTriggerData2018::epdNHits(StBeamDirection eastwest, int prepost) const
579 {
580  int buffer = prepostAddress(prepost);
581  if (buffer>=0){
582  if(eastwest==east){
583  unsigned short dsmEP001OutR = epdLayer1(0, 0);
584  unsigned short dsmEP001OutL = epdLayer1(1, 0);
585  unsigned int dsmEP001Out = (dsmEP001OutL<<16) + dsmEP001OutR;
586  return (dsmEP001Out >> 24) & 0xff;
587  }else{
588  unsigned short dsmEP002OutR = epdLayer1(2, 0);
589  unsigned short dsmEP002OutL = epdLayer1(3, 0);
590  unsigned int dsmEP002Out = (dsmEP002OutL<<16) + dsmEP002OutR;
591  return (dsmEP002Out >> 24) & 0xff;
592  }
593  }
594  return 0;
595 }
596 
597 
598 unsigned short StTriggerData2018::epdLayer0a(int ch, int prepost) const
599 {
600  int dsmmap[16] = {3,2,1,0,7,6,5,4};
601  int buffer = prepostAddress(prepost);
602  if (buffer>=0){
603  if (mBBC[buffer]){
604  if(ch>=0 && ch<8) return mBBC[buffer]->EPDlayer0a[dsmmap[ch]];
605  }
606  }
607  return 0;
608 }
609 
610 unsigned short StTriggerData2018::fpd(StBeamDirection eastwest, int module, int pmt, int prepost) const
611 {
612  return 0;
613 }
614 
615 unsigned short StTriggerData2018::fpdSum(StBeamDirection eastwest, int module) const
616 {
617  return 0;
618 }
619 
620 unsigned short StTriggerData2018::fpdLayer1DSMRaw(StBeamDirection eastwest, int channel, int prepost) const{
621  int buffer = prepostAddress(prepost);
622  if (buffer >= 0){
623  if (eastwest==east) { if (mMIX[buffer]) return mMIX[buffer]->FPDEastNSLayer1[channel]; }
624  else { if (mFMS[buffer]) return mFMS[buffer]->FMS[channel]; }
625  }
626  return 0;
627 }
628 
629 unsigned short StTriggerData2018::fpdLayer2DSMRaw(int channel) const{
630  if (channel<8) return L1_DSM->FPD[channel];
631  return 0;
632 }
633 
634 bool StTriggerData2018::zdcPresent(int prepost) const
635 {
636  int buffer = prepostAddress(prepost);
637  if (buffer >= 0) return mBBQ[buffer];
638  return false;
639 }
640 
641 unsigned short StTriggerData2018::zdcAtChannel(int channel, int prepost) const
642 {
643  int buffer = prepostAddress(prepost);
644  if (buffer >= 0 && channel>=0 && channel<32) return bbq[buffer][14][channel];
645  return 0;
646 }
647 
648 unsigned short StTriggerData2018::zdcAtAddress(int address, int prepost) const
649 {
650  return zdcAtChannel(address,prepost);
651 }
652 
653 unsigned short StTriggerData2018::zdcUnAttenuated(StBeamDirection eastwest, int prepost) const
654 {
655  int buffer = prepostAddress(prepost);
656  if (buffer >= 0) {
657  if (eastwest == east) return bbq[buffer][14][2];
658  else return bbq[buffer][14][18];
659  }
660  return 0;
661 }
662 
663 unsigned short StTriggerData2018::zdcAttenuated(StBeamDirection eastwest, int prepost) const
664 {
665  int buffer = prepostAddress(prepost);
666  if (buffer >= 0) {
667  if (eastwest == east) return bbq[buffer][14][3];
668  else return bbq[buffer][14][19];
669  }
670  return 0;
671 }
672 
673 unsigned short StTriggerData2018::zdcADC(StBeamDirection eastwest, int pmt, int prepost) const
674 {
675  int buffer = prepostAddress(prepost);
676  if (buffer >= 0 && pmt>=1 && pmt<=3) {
677  if (eastwest == east) {
678  if (pmt == 1) return bbq[buffer][14][0];
679  if (pmt == 2) return bbq[buffer][14][8];
680  if (pmt == 3) return bbq[buffer][14][9];
681  }
682  else {
683  if (pmt == 1) return bbq[buffer][14][16];
684  if (pmt == 2) return bbq[buffer][14][24];
685  if (pmt == 3) return bbq[buffer][14][25];
686  }
687  }
688  return 0;
689 }
690 
691 unsigned short StTriggerData2018::zdcTDC(StBeamDirection eastwest, int prepost) const
692 {
693  int buffer = prepostAddress(prepost);
694  if (buffer >= 0) {
695  if (eastwest == east) return bbq[buffer][14][6];
696  else return bbq[buffer][14][22];
697  }
698  return 0;
699 }
700 
701 unsigned short StTriggerData2018::zdcPmtTDC(StBeamDirection eastwest, int pmt, int prepost) const
702 {
703  int buffer = prepostAddress(prepost);
704  if (buffer >= 0 && pmt>=1 && pmt<=3) {
705  if (eastwest == east) {
706  if (pmt == 1) return bbq[buffer][14][4];
707  if (pmt == 2) return bbq[buffer][14][12];
708  if (pmt == 3) return bbq[buffer][14][13];
709  }
710  else {
711  if (pmt == 1) return bbq[buffer][14][20];
712  if (pmt == 2) return bbq[buffer][14][28];
713  if (pmt == 3) return bbq[buffer][14][29];
714  }
715  }
716  return 0;
717 }
718 
719 unsigned short StTriggerData2018::zdcHardwareSum(int prepost) const
720 {
721  int buffer = prepostAddress(prepost);
722  if (buffer >= 0) return bbq[buffer][14][11];
723  return 0;
724 }
725 
726 bool StTriggerData2018::zdcSMDPresent(int prepost) const
727 {
728  int buffer = prepostAddress(prepost);
729  if (buffer >= 0) return mMXQ[buffer];
730  return false;
731 }
732 
733 unsigned short StTriggerData2018::zdcSMD(StBeamDirection eastwest, int verthori, int strip, int prepost) const
734 {
735  static const int zdcsmd_map[2][2][8] ={
736  { { 31, 30, 29, 28, 27, 26, 25, 19} ,
737  { 24, 23, 22, 21, 20, 16, 18, 17} } ,
738  { { 15, 14, 13, 12, 11, 10, 9, 2} ,
739  { 8, 7, 6, 5, 4, 3, 0, 1} }
740  };
741  static const int zdcsmd_map2011[2][2][8] ={
742  { {24, 25, 26, 27, 28, 29, 30, 31} ,
743  {16, 17, 18, 19, 20, 21, 22, 23} } ,
744  { {8, 9, 10, 11, 12, 13, 14, 15} ,
745  {0, 1, 2, 3, 4, 5, 6, 7} }
746  };
747  if (verthori<0 || verthori>1) return 0;
748  if (strip<1 || strip>8) return 0;
749  int buffer = prepostAddress(prepost);
750  if (buffer >= 0) {
751  if(mRun<12034085){
752  return mxq[buffer][4][zdcsmd_map[eastwest][verthori][strip-1]];
753  }else{
754  return mxq[buffer][4][zdcsmd_map2011[eastwest][verthori][strip-1]];
755  }
756  }
757  return 0;
758 }
759 
760 unsigned short StTriggerData2018::zdcEarliestTDC(StBeamDirection eastwest, int prepost) const
761 {
762  int buffer = prepostAddress(prepost);
763  if (buffer >=0){
764  if (mBBC[buffer]){
765  if(mRun<12000000){
766  if (eastwest==east) {return ((mBBC[buffer]->ZDClayer1[3] >> 12) % 16) | ((mBBC[buffer]->ZDClayer1[2] % 256) << 4);}
767  else {return (mBBC[buffer]->ZDClayer1[3]) % 4096;}
768  }else{
769  if (eastwest==east) {return ((mBBC[buffer]->ZDClayer1[3] >> 10) % 64) | ((mBBC[buffer]->ZDClayer1[2] % 16) << 6);}
770  else {return (mBBC[buffer]->ZDClayer1[3]) % 1024;}
771  }
772  }
773  }
774  return 0;
775 }
776 
777 bool StTriggerData2018::zdcSumADCaboveThreshold(StBeamDirection eastwest, int prepost) const {
778  int buffer = prepostAddress(prepost);
779  if (buffer >=0){
780  if (mBBC[buffer]){
781  if(mRun<12000000){
782  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (27-16));}
783  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (24-16));}
784  }else{
785  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (25-16));}
786  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (22-16));}
787  }
788  }
789  }
790  return 0;
791 }
792 
793 bool StTriggerData2018::zdcFrontADCaboveThreshold(StBeamDirection eastwest, int prepost) const {
794  int buffer = prepostAddress(prepost);
795  if (buffer >=0){
796  if (mBBC[buffer]){
797  if(mRun<12000000){
798  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (29-16));}
799  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (26-16));}
800  }else{
801  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (23-16));}
802  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (20-16));}
803  }
804  }
805  }
806  return 0;
807 }
808 
809 bool StTriggerData2018::zdcBackADCaboveThreshold(StBeamDirection eastwest, int prepost) const {
810  int buffer = prepostAddress(prepost);
811  if (buffer >=0){
812  if (mBBC[buffer]){
813  if(mRun<12000000){
814  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (28-16));}
815  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (25-16));}
816  }else{
817  if (eastwest==east) {return mBBC[buffer]->ZDClayer1[2] & (1 << (24-16));}
818  else {return mBBC[buffer]->ZDClayer1[2] & (1 << (21-16));}
819  }
820  }
821  }
822  return 0;
823 }
824 
825 unsigned short StTriggerData2018::zdcTimeDifference() const
826 {
827  return L1_DSM->VTX[1]%256;
828 }
829 
830 bool StTriggerData2018::zdcSumADCaboveThresholdL2(StBeamDirection eastwest) const {
831  return L1_DSM->VTX[1] & (1 << ((eastwest==east) ? 10 : 11));
832 }
833 
834 bool StTriggerData2018::zdcFrontADCaboveThresholdL2(StBeamDirection eastwest) const {
835  return L1_DSM->VTX[1] & (1 << ((eastwest==east) ? 12 : 14));
836 }
837 
838 bool StTriggerData2018::zdcBackADCaboveThresholdL2(StBeamDirection eastwest) const {
839  return L1_DSM->VTX[1] & (1 << ((eastwest==east) ? 13 : 15));
840 }
841 
842 bool StTriggerData2018::zdcSumADCaboveThresholdL3(StBeamDirection eastwest) const {
843  if(mRun<12000000){ return lastDSM(2) & (1 << ((eastwest==east) ? 7 : 8)); }
844  else { return lastDSM(1) & (1 << ((eastwest==east) ? 7 : 8)); }
845 }
846 
847 bool StTriggerData2018::zdcFrontADCaboveThresholdL3(StBeamDirection eastwest) const {
848  if(mRun<12000000){ return lastDSM(2) & (1 << ((eastwest==east) ? 9 : 11)); }
849  else { return lastDSM(1) & (1 << ((eastwest==east) ? 9 : 11)); }
850 }
851 
852 bool StTriggerData2018::zdcBackADCaboveThresholdL3(StBeamDirection eastwest) const {
853  if(mRun<12000000){ return lastDSM(2) & (1 << ((eastwest==east) ? 10 : 12)); }
854  else { return lastDSM(1) & (1 << ((eastwest==east) ? 10 : 12)); }
855 }
856 
857 bool StTriggerData2018::zdcTimeDifferenceInWindow() const
858 {
859  if(mRun<12000000){ return lastDSM(2) & (1 << 6); }
860  else { return lastDSM(1) & (1 << 6); }
861 }
862 
863 unsigned short StTriggerData2018::zdcSMDHighestStrip(StBeamDirection eastwest, int verthori, int prepost) const
864 {
865  if(mRun<12000000) return 0;
866  // copy of the scaler output from ZDC SMD QT is sent to ZD101 J2
867  int buffer = prepostAddress(prepost);
868  if (buffer >=0){
869  if (mBBC[buffer]){
870  if (eastwest==east) {return (mBBC[buffer]->ZDClayer1[1] >> (verthori ? 6 : 9)) % 8;}
871  else {return (mBBC[buffer]->ZDClayer1[1] >> (verthori ? 0 : 3)) % 8;}
872  }
873  }
874  return 0;
875 }
876 
877 unsigned short StTriggerData2018::zdcTruncatedSum(StBeamDirection eastwest, int prepost) const
878 {
879  if(mRun<12000000) return 0;
880  int buffer = prepostAddress(prepost);
881  if (buffer >=0){
882  if (mBBC[buffer]){
883  if (eastwest==east) {return (mBBC[buffer]->ZDClayer1[2] >> (26-16)) % 8;}
884  else {return (mBBC[buffer]->ZDClayer1[2] >> (29-16)) % 8;}
885  }
886  }
887  return 0;
888 }
889 
890 unsigned short StTriggerData2018::pp2ppADC(StBeamDirection eastwest, int vh, int udio, int ch, int prepost) const
891 {
892  static const int map[2][2][2][2] ={ { { { 0, 1}, { 2, 3} } , { {16,17}, {18,19} } , } ,
893  { { { 8, 9}, {10,11} } , { {24,25}, {26,27} } , } };
894  if (vh<0 || vh>1) return 0;
895  if (udio<0 || udio>1) return 0;
896  if (ch<0 || ch>1) return 0;
897  int buffer = prepostAddress(prepost);
898  if (buffer >= 0) return mxq[buffer][2][map[eastwest][vh][udio][ch]];
899  return 0;
900 }
901 
902 unsigned short StTriggerData2018::pp2ppTAC(StBeamDirection eastwest, int vh, int udio, int ch, int prepost) const
903 {
904  static const int map[2][2][2][2] ={ { { { 0, 1}, { 2, 3} } , { {16,17}, {18,19} } , } ,
905  { { { 8, 9}, {10,11} } , { {24,25}, {26,27} } , } };
906  if (vh<0 || vh>1) return 0;
907  if (udio<0 || udio>1) return 0;
908  if (ch<0 || ch>1) return 0;
909  int buffer = prepostAddress(prepost);
910  if (buffer >= 0) return mxq[buffer][2][map[eastwest][vh][udio][ch]+4];
911  return 0;
912 }
913 
914 unsigned long StTriggerData2018::pp2ppDSM(int prepost) const {
915  if (prepost!=0) return 0;
916  return L1_DSM->TOF[7];
917 }
918 
919 unsigned short StTriggerData2018::bemcLayer1DSM(int channel, int prepost) const {
920  const int n_bemc_layer1=48;
921  if (channel<0 || channel >=n_bemc_layer1) {
922  gMessMgr->Warning() << "Barrel DSM layer 1 out of range (" << channel << ")" << endm;
923  return 0;
924  }
925  int buffer = prepostAddress(prepost);
926  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->BEMClayer1[channel];
927  return 0;
928 }
929 
930 unsigned short StTriggerData2018::eemcLayer1DSM(int channel, int prepost) const {
931  const int n_eemc_layer1=16;
932  if (channel<0 || channel >=n_eemc_layer1) {
933  gMessMgr->Warning() << "Endap DSM layer 1 out of range (" << channel << ")" << endm;
934  return 0;
935  }
936  int buffer = prepostAddress(prepost);
937  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->EEMClayer1[channel];
938  return 0;
939 }
940 
941 unsigned short StTriggerData2018::emcLayer2DSM(int channel) const {
942  const int n_emc_layer2=8;
943  if (channel<0 || channel >=n_emc_layer2) {
944  gMessMgr->Warning() << "EMC DSM layer 2 out of range (" << channel << ")" << endm;
945  return 0;
946  }
947  return L1_DSM->EMC[channel];
948 }
949 
950 unsigned short StTriggerData2018::tpcMaskDSM(int channel) const {
951  const int n_tpcMask=8;
952  if (channel<0 || channel >=n_tpcMask) {
953  gMessMgr->Warning() << "TPCMask DSM out of range (" << channel << ")" << endm;
954  return 0;
955  }
956  return L1_DSM->TPCMask[channel];
957 }
958 
959 unsigned char StTriggerData2018::bemcHighTower(int patch_id, int prepost) const {
960  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
961  const int m_max_patch=300; // Full barrel
962  if ( patch_id < 0 || patch_id >= m_max_patch) {
963  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
964  return 0;
965  }
966  int buffer = prepostAddress(prepost);
967  if (buffer >= 0) {
968  int dsm=patch_id/10;
969  int channel=patch_id%10;
970  unsigned short trg_word;
971  if (dsm>=15) {
972  if (mBCE[buffer])
973  trg_word=decodeEmc12bit(dsm-15,channel,mBCE[buffer]->BEMCEast);
974  else
975  return 0;
976  }
977  else {
978  if (mBCW[buffer])
979  trg_word=decodeEmc12bit(dsm,channel,mBCW[buffer]->BEMCWest);
980  else
981  return 0;
982  }
983  return trg_word & 0x3F;
984  }
985  return 0;
986 }
987 
988 unsigned char StTriggerData2018::bemcJetPatch (int patch_id, int prepost) const
989 {
990  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
991  const int m_max_patch=300; // Full barrel
992  if ( patch_id < 0 || patch_id >= m_max_patch) {
993  gMessMgr->Warning() << "Invalid Barrel patch id: " << patch_id << endm;
994  return 0;
995  }
996  int buffer = prepostAddress(prepost);
997  if (buffer >= 0) {
998  int dsm=patch_id/10;
999  int channel=patch_id%10;
1000  unsigned short trg_word;
1001  if (dsm>=15) {
1002  if (mBCE[buffer])
1003  trg_word=decodeEmc12bit(dsm-15,channel,mBCE[buffer]->BEMCEast);
1004  else
1005  return 0;
1006  }
1007  else {
1008  if (mBCW[buffer])
1009  trg_word=decodeEmc12bit(dsm,channel,mBCW[buffer]->BEMCWest);
1010  else
1011  return 0;
1012  }
1013  return trg_word >> 6;
1014  }
1015  return 0;
1016 }
1017 
1018 
1019 unsigned char StTriggerData2018::eemcHighTower(int patch_id, int prepost) const
1020 {
1021  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
1022  const int m_max_patch=90;
1023  if ( patch_id < 0 || patch_id >= m_max_patch) {
1024  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
1025  return 0;
1026  }
1027  int buffer = prepostAddress(prepost);
1028  if (buffer >= 0 && mBC1[buffer]) {
1029  int dsm=patch_id/10;
1030  int channel=patch_id%10;
1031  unsigned short trg_word = decodeEmc12bit(dsm,channel,mBC1[buffer]->EEMC);
1032  return trg_word & 0x3F;
1033  }
1034  return 0;
1035 }
1036 
1037 unsigned char StTriggerData2018::eemcJetPatch (int patch_id, int prepost) const
1038 {
1039  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
1040  const int m_max_patch=90;
1041  if ( patch_id < 0 || patch_id >= m_max_patch) {
1042  gMessMgr->Warning() << "Invalid Endcap patch id" << endm;
1043  return 0;
1044  }
1045  int buffer = prepostAddress(prepost);
1046  if (buffer >= 0 && mBC1[buffer]) {
1047  int dsm=patch_id/10;
1048  int channel=patch_id%10;
1049  unsigned short trg_word = decodeEmc12bit(dsm,channel,mBC1[buffer]->EEMC);
1050  return trg_word >> 6;
1051  }
1052  return 0;
1053 }
1054 
1055 unsigned char StTriggerData2018::bemcHighestTowerADC(int prepost) const {
1056  // Unpacking of Bemc trigger data (level 0 DSM input, trigger patches)
1057  const int m_max_patch=300; // Full barrel
1058  unsigned char h=0;
1059  for (int i=1; i<m_max_patch; i++){
1060  unsigned char hh=bemcHighTower(i,prepost);
1061  if (h>hh) h=hh;
1062  }
1063  return h;
1064 }
1065 
1066 unsigned char StTriggerData2018::eemcHighestTowerADC(int prepost) const {
1067  // Unpacking of Eemc trigger data (level 0 DSM input, trigger patches)
1068  const int m_max_patch=90;
1069  unsigned char h=0;
1070  for (int i=1; i<m_max_patch; i++){
1071  unsigned char hh=eemcHighTower(i,prepost);
1072  if (h>hh) h=hh;
1073  }
1074  return h;
1075 }
1076 
1077 char* StTriggerData2018::getTriggerStructure()
1078 {
1079  return (char*) mData;
1080 }
1081 
1082 TriggerDataBlk2018* StTriggerData2018::getTriggerStructure2018()
1083 {
1084  return mData;
1085 }
1086 
1087 int StTriggerData2018::getRawSize() const
1088 {
1089  return mData->totalTriggerLength;
1090 }
1091 
1092 unsigned char* StTriggerData2018::getDsm0_BEMCE(int prepost) const {
1093  int buffer = prepostAddress(prepost);
1094  if (buffer >= 0) if (mBCE[buffer]) return mBCE[buffer]->BEMCEast;
1095  return 0;
1096 }
1097 
1098 unsigned char* StTriggerData2018::getDsm0_BEMCW(int prepost) const {
1099  int buffer = prepostAddress(prepost);
1100  if (buffer >= 0) if (mBCW[buffer]) return mBCW[buffer]->BEMCWest;
1101  return 0;
1102 }
1103 
1104 unsigned short* StTriggerData2018::getDsm1_BEMC(int prepost) const {
1105  int buffer = prepostAddress(prepost);
1106  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->BEMClayer1;
1107  return 0;
1108 }
1109 
1110 unsigned char* StTriggerData2018::getDsm0_EEMC(int prepost) const {
1111  int buffer = prepostAddress(prepost);
1112  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->EEMC;
1113  return 0;
1114 }
1115 
1116 unsigned short* StTriggerData2018::getDsm1_EEMC(int prepost) const{
1117  int buffer = prepostAddress(prepost);
1118  if (buffer >= 0) if (mBC1[buffer]) return mBC1[buffer]->EEMClayer1;
1119  return 0;
1120 }
1121 
1122 unsigned short* StTriggerData2018::getDsm2_EMC() const{
1123  return L1_DSM->EMC;
1124 }
1125 
1126 unsigned short* StTriggerData2018::getDsm3() const{
1127  return L1_DSM->lastDSM;
1128 }
1129 
1130 int StTriggerData2018::L2ResultsOffset(StL2AlgorithmId id) const
1131 {
1132  switch(id) {
1133  default: return -999999999;
1134  }
1135 }
1136 
1137 bool StTriggerData2018::isL2Triggered(StL2TriggerResultType id) const
1138 {
1139  return false;
1140 }
1141 
1142 unsigned int StTriggerData2018::l2ResultLength() const
1143 {
1144  return sizeof(TrgSum->L2Result)/sizeof(unsigned int);
1145 }
1146 
1147 const unsigned int* StTriggerData2018::l2Result() const
1148 {
1149  return TrgSum->L2Result;
1150 }
1151 
1152 unsigned long long StTriggerData2018::l2sum() const
1153 {
1154  //printf("L2sum0=%08o\n",TrgSum->L2Sum[0]);
1155  //printf("L2sum1=%08o\n",TrgSum->L2Sum[1]);
1156  unsigned long long hi = TrgSum->L2Sum[1];
1157  unsigned long long lo = TrgSum->L2Sum[0];
1158  unsigned long long mask=(hi<<32) | lo;
1159  return mask;
1160 }
1161 
1162 unsigned short StTriggerData2018::vpdADC(StBeamDirection eastwest, int pmt, int prepost) const
1163 {
1164  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1165  if (pmt<1 || pmt>16) return 0;
1166  int buffer = prepostAddress(prepost);
1167  if (buffer >= 0) {
1168  if (mRun<=12003001) {return bbq[buffer][10+(int)eastwest*2][map[pmt-1]];}
1169  else {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]];}
1170  }
1171  return 0;
1172 }
1173 
1174 unsigned short StTriggerData2018::vpdTDC(StBeamDirection eastwest, int pmt, int prepost) const
1175 {
1176  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1177  if (pmt<1 || pmt>16) return 0;
1178  int buffer = prepostAddress(prepost);
1179  if (buffer >= 0) {
1180  if (mRun<=12003001) {return bbq[buffer][10+(int)eastwest*2][map[pmt-1]+4];}
1181  else {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]+4];}
1182  }
1183  return 0;
1184 }
1185 
1186 unsigned short StTriggerData2018::vpdADCHighThr(StBeamDirection eastwest, int pmt, int prepost) const
1187 {
1188  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1189  if (pmt<1 || pmt>16) return 0;
1190  int buffer = prepostAddress(prepost);
1191  if (buffer >= 0) {
1192  if (mRun<=12003001) {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]];}
1193  else {return mxq[buffer][6+(int)eastwest*2][map[pmt-1]];}
1194  }
1195  return 0;
1196 }
1197 
1198 unsigned short StTriggerData2018::vpdTDCHighThr(StBeamDirection eastwest, int pmt, int prepost) const
1199 {
1200  static const int map[16] = {0, 1, 2, 3, 8, 9,10,11,16,17,18,19,24,25,26,27};
1201  if (pmt<1 || pmt>16) return 0;
1202  int buffer = prepostAddress(prepost);
1203  if (buffer >= 0) {
1204  if (mRun<=12003001) {return bbq[buffer][6+(int)eastwest*2][map[pmt-1]+4];}
1205  else {return mxq[buffer][6+(int)eastwest*2][map[pmt-1]+4];};
1206  }
1207  return 0;
1208 }
1209 
1210 unsigned short StTriggerData2018::vpdEarliestTDC(StBeamDirection eastwest, int prepost) const
1211 {
1212  int buffer = prepostAddress(prepost);
1213  if (buffer >= 0){
1214  if (mBBC[buffer]){
1215  if (mRun<=10096084){
1216  if (eastwest==east) {return mBBC[buffer]->VPD[6]%4096;}
1217  else {return mBBC[buffer]->VPD[4]%4096;}
1218  }
1219  else if(mRun<=12003001) {
1220  if (eastwest==east) {return mBBC[buffer]->VPD[2]%4096;}
1221  else {return mBBC[buffer]->VPD[0]%4096;}
1222  }
1223  else {
1224  if (eastwest==east) {return mBBC[buffer]->VPD[6]%4096;}
1225  else {return mBBC[buffer]->VPD[4]%4096;}
1226  }
1227 
1228  }
1229  }
1230  return 0;
1231 }
1232 
1233 unsigned short StTriggerData2018::vpdEarliestTDCHighThr(StBeamDirection eastwest, int prepost) const
1234 {
1235  int buffer = prepostAddress(prepost);
1236  if (buffer >= 0){
1237  if (mRun<=10365999){
1238  return 0;
1239  }
1240  else if(mRun<=12003001) {
1241  if (mBBC[buffer]){
1242  if (eastwest==east) {return mBBC[buffer]->VPD[6]%4096;}
1243  else {return mBBC[buffer]->VPD[4]%4096;}
1244  }
1245  }else if(mRun<=14001001){
1246  if(mMIX[buffer]){
1247  if (eastwest==east) {return mMIX[buffer]->MTD_P2PLayer1[13] + ((mMIX[buffer]->MTD_P2PLayer1[12]&0x0f)<<8);}
1248  else {return mMIX[buffer]->MTD_P2PLayer1[9] + ((mMIX[buffer]->MTD_P2PLayer1[8]&0x0f)<<8);}
1249  }
1250  }else {
1251  if(mMIX[buffer]){
1252  if (eastwest==east) {return mMIX[buffer]->MTD_P2PLayer1[11] + ((mMIX[buffer]->MTD_P2PLayer1[10]&0xf)<<8);}
1253  else {return (mMIX[buffer]->MTD_P2PLayer1[10]>>4) + ((mMIX[buffer]->MTD_P2PLayer1[9]&0xff)<<4);}
1254  }
1255  }
1256  }
1257  return 0;
1258 }
1259 
1260 unsigned short StTriggerData2018::vpdADCSum(StBeamDirection eastwest, int prepost) const
1261 {
1262  if(eastwest==east){
1263  return (bbcVP101(4,prepost) & 0x7ff);
1264  }else{
1265  return (bbcVP101(6,prepost) & 0x7ff);
1266  }
1267 }
1268 
1269 float StTriggerData2018::vpdMeanTimeDifference(int prepost) const
1270 {
1271  // return L1_DSM->VTX[7]%8192;
1272  unsigned int ne=(bbcVP101(4,prepost) >> 11) & 0x1f;
1273  unsigned int nw=(bbcVP101(6,prepost) >> 11) & 0x1f;
1274  unsigned int se=bbcVP101(5,prepost);
1275  unsigned int sw=bbcVP101(7,prepost);
1276  int nwse=nw*se;
1277  int nesw=ne*sw;
1278  int nenw=ne*nw;
1279  if(nenw>0) return float(nwse-nesw)/float(nenw);
1280  return -2000.0;
1281 }
1282 
1283 unsigned short StTriggerData2018::bbcVP101(int ch, int prepost) const
1284 {
1285  int map[8]={3, 2, 1, 0, 7, 6, 5, 4};
1286  if(ch<0 || ch>7) return 0;
1287  int buffer = prepostAddress(prepost);
1288  if (buffer >= 0 && mBBC[buffer]){
1289  return mBBC[buffer]->VPD[map[ch]];
1290  }
1291  return 0;
1292 }
1293 
1294 
1295 unsigned short StTriggerData2018::dsmTF201Ch(int ch) const // read TF201 data
1296 {
1297  int map[8]={3, 2, 1, 0, 7, 6, 5, 4};
1298  return L1_DSM->TOF[map[ch]]; //ch4-7 currently unused
1299 }
1300 
1301 unsigned short StTriggerData2018::mtd4AtAddress(int address, int prepost) const // read QT4 data
1302 {
1303  if (mRun<=15001001) return 0; // Run-14 onwards...
1304  int buffer = prepostAddress(prepost);
1305  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][14][address];
1306  return 0;
1307 }
1308 
1309 unsigned short StTriggerData2018::nQTdata(int prepost) const
1310 {
1311  return 0;
1312 }
1313 
1314 unsigned int* StTriggerData2018::QTdata(int prepost) const
1315 {
1316  return 0;
1317 }
1318 
1319 unsigned short StTriggerData2018::fmsADC(int crt, int adr, int ch, int prepost) const
1320 {
1321  int buffer = prepostAddress(prepost);
1322  if (buffer >= 0 && crt>=1 && crt<=7 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1323  switch(crt){
1324  case 0: return bbq[buffer][adr][ch];
1325  case 1: return qt1[buffer][adr][ch];
1326  case 2: return qt2[buffer][adr][ch];
1327  case 3: return qt3[buffer][adr][ch];
1328  case 4: return qt4[buffer][adr][ch];
1329  case 5: return eq3[buffer][adr][ch];
1330  case 6: return eq1[buffer][adr][ch];
1331  case 7: return eq2[buffer][adr][ch];
1332  }
1333  }
1334  return 0;
1335 }
1336 
1337 unsigned short StTriggerData2018::fmsTDC(int crt, int adr, int ch, int prepost) const
1338 {
1339  int buffer = prepostAddress(prepost);
1340  if (buffer >= 0 && crt>=0 && crt<=7 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1341  switch(crt){
1342  case 0: return tbbq[buffer][adr][ch];
1343  case 1: return tqt1[buffer][adr][ch];
1344  case 2: return tqt2[buffer][adr][ch];
1345  case 3: return tqt3[buffer][adr][ch];
1346  case 4: return tqt4[buffer][adr][ch];
1347  case 5: return teq3[buffer][adr][ch];
1348  case 6: return teq1[buffer][adr][ch];
1349  case 7: return teq2[buffer][adr][ch];
1350  }
1351  }
1352  return 0;
1353 }
1354 
1355 unsigned short StTriggerData2018::epdADC(int crt, int adr, int ch, int prepost) const
1356 {
1357  int buffer = prepostAddress(prepost);
1358  if (buffer >= 0 && crt>=1 && crt<=3 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1359  switch(crt){
1360  case 1: return eq1[buffer][adr][ch];
1361  case 2: return eq2[buffer][adr][ch];
1362  case 3: return eq3[buffer][adr][ch];
1363  }
1364  }
1365  return 0;
1366 }
1367 
1368 unsigned short StTriggerData2018::epdTDC(int crt, int adr, int ch, int prepost) const
1369 {
1370  int buffer = prepostAddress(prepost);
1371  if (buffer >= 0 && crt>=1 && crt<=3 && adr>=0 && adr<16 && ch>=0 && ch<=31){
1372  switch(crt){
1373  case 1: return teq1[buffer][adr][ch];
1374  case 2: return teq2[buffer][adr][ch];
1375  case 3: return teq3[buffer][adr][ch];
1376  }
1377  }
1378  return 0;
1379 }
1380 
1381 unsigned char* StTriggerData2018::getDsm_FMS(int prepost) const
1382 {
1383  int buffer = prepostAddress(prepost);
1384  if (buffer >= 0) if (mFMS[buffer]) return mFMS[buffer]->FMS;
1385  return 0;
1386 }
1387 
1388 unsigned short* StTriggerData2018::getDsm1_FMS(int prepost) const
1389 {
1390  int buffer = prepostAddress(prepost);
1391  if (buffer >= 0) if (mMIX[buffer]) return mMIX[buffer]->FPDEastNSLayer1;
1392  return 0;
1393 }
1394 
1395 unsigned short* StTriggerData2018::getDsm2_FMS() const {return L1_DSM->FPD;}
1396 
1397 unsigned short StTriggerData2018::mxqAtSlotAddress(int address, int prepost, int slot) const
1398 {
1399  int buffer = prepostAddress(prepost);
1400  if (buffer >= 0 && address>=0 && address<32){
1401  if (slot >= 0 && slot<16){
1402  return mxq[buffer][slot][address];
1403  }
1404  }
1405  return 0;
1406 }
1407 
1408 unsigned short StTriggerData2018::mtdQtAtCh(int qtid, int address, int prepost) const
1409 { // read all the MTD QTs data, and the range of qtid is 1-8
1410  int map1[4] = {0, 10, 12, 14};
1411  int map2[8] = {0, 9, 10, 11, 12, 13, 14, 15};
1412  int map3[4] = {0, 9, 11, 13};
1413 
1414  int buffer = prepostAddress(prepost);
1415  if(buffer>=0 && qtid>0 && address>=0 && address<32){
1416  if(mRun<=12003001){
1417  if(qtid>1) return 0;
1418  else return mxq[buffer][map1[qtid-1]][address];
1419  }
1420  else if(mRun<=14001001){
1421  if(qtid>2) return 0;
1422  else return mxq[buffer][map1[qtid-1]][address];
1423  }
1424  else if(mRun<=15001001){
1425  if(qtid>3) return 0;
1426  else return mxq[buffer][map1[qtid-1]][address];
1427  }
1428  else if(mRun<=17001001){
1429  if(qtid>4) return 0;
1430  else return mxq[buffer][map1[qtid-1]][address];
1431  }
1432  else if(mRun<=18001001){
1433  if(qtid>8) return 0;
1434  else return mxq[buffer][map2[qtid-1]][address];
1435  }
1436  else{
1437  if(qtid>4) return 0;
1438  else return mxq[buffer][map3[qtid-1]][address];
1439  }
1440  }
1441 
1442  return 0;
1443 }
1444 
1445 unsigned short StTriggerData2018::mtdAtAddress(int address, int prepost) const
1446 {
1447  int buffer = prepostAddress(prepost);
1448  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][0][address];
1449  return 0;
1450 }
1451 
1452 unsigned short StTriggerData2018::mtdgemAtAddress(int address, int prepost) const
1453 {
1454  if (mRun<=12003001) return 0;
1455  int buffer = prepostAddress(prepost);
1456  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][10][address];
1457  return 0;
1458 }
1459 
1460 unsigned short StTriggerData2018::mtd3AtAddress(int address, int prepost) const
1461 {
1462  if (mRun<=14001001) return 0; // Run-13 onwards...
1463  int buffer = prepostAddress(prepost);
1464  if (buffer >= 0 && address>=0 && address<32) return mxq[buffer][12][address];
1465  return 0;
1466 }
1467 
1468 
1469 unsigned short StTriggerData2018::mtdAdc(StBeamDirection eastwest, int pmt, int prepost) const
1470 {
1471  //pmt in not used for 2018, it is place holder for next year
1472  int buffer = prepostAddress(prepost);
1473  if (buffer >= 0 && pmt==0){
1474  if (eastwest==east) {
1475  if (mRun<=10133008) return mxq[buffer][0][0];
1476  else return mxq[buffer][0][24];
1477  }
1478  if (eastwest==west) return mxq[buffer][0][8];
1479  }
1480  return 0;
1481 }
1482 
1483 unsigned short StTriggerData2018::mtdTdc(StBeamDirection eastwest, int pmt, int prepost) const
1484 {
1485  //pmt in not used for 2018, it is place holder for next year
1486  int buffer = prepostAddress(prepost);
1487  if (buffer >= 0 && pmt==0){
1488  if (eastwest==east) {
1489  if (mRun<=10133008) return mxq[buffer][0][4];
1490  else return mxq[buffer][0][28];
1491  }
1492  if (eastwest==west) return mxq[buffer][0][12];
1493  }
1494  return 0;
1495 }
1496 
1497 unsigned char StTriggerData2018::mtdDsmAtCh(int ch, int prepost) const
1498 {
1499  int map[16] = {7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8};
1500  //int map2[8] = {3, 2, 1, 0, 7, 6, 5, 4};
1501  int buffer = prepostAddress(prepost);
1502  if (buffer >= 0 && ch>=0){
1503  if(mMIX[buffer]){
1504  if(ch<16){
1505  return mMIX[buffer]->MTD_P2PLayer1[map[ch]];
1506  }else if(ch<32){
1507  //int add= 8 + map2[(ch-16)/2];
1508  unsigned char v=0;
1509  //if(ch%2==0){ v=(unsigned char)((mMIX[buffer]->TPCpreMask[add] & 0xff00)>>8);}
1510  //else { v=(unsigned char)((mMIX[buffer]->TPCpreMask[add] & 0x00ff) );}
1511  return v;
1512  }
1513  }
1514  }
1515  return 0;
1516 }
1517 
1518 bool StTriggerData2018::mtdDsmHit(int pmt, int prepost) const
1519 {
1520  //pmt in not used for 2018, it is place holder for next year
1521  int buffer = prepostAddress(prepost);
1522  if (buffer >= 0){
1523  if(mMIX[buffer]){
1524  if(mRun<10133008 && mRun<11000000){
1525  if( (mMIX[buffer]->MTD_P2PLayer1[5] & 0x1) && (mMIX[buffer]->MTD_P2PLayer1[5] & 0x10) ) return true;
1526  }
1527  else{
1528  if(prepost!=0) return false;
1529  return (L1_DSM->TOF[3] & 0x1);
1530  }
1531  }
1532  }
1533  return false;
1534 }
1535 
1536 unsigned short StTriggerData2018::mtdVpdTacDiff() const
1537 {
1538  return (L1_DSM->TOF[3] & 0x3fff);
1539 }
1540 
1541 unsigned short StTriggerData2018::tofAtAddress(int address, int prepost) const
1542 {
1543  int buffer = prepostAddress(prepost);
1544  if (buffer>=0 && address>=0 && address<48) {
1545  if (mMIX[buffer]) return mMIX[buffer]->TOF[address];
1546  }
1547  return 0;
1548 }
1549 
1550 unsigned short StTriggerData2018::tofTrayMultiplicity(int tray, int prepost) const
1551 {
1552  int dsmmap[8] = {3,2,1,0,7,6,5,4};
1553  int traydsm[120] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 5, 5, 5, 5, 5,
1554  5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3,
1555  3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
1556  1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
1557  3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
1558  5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
1559  int traych[120] = { 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3,
1560  2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3,
1561  2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3,
1562  18,19,10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,15,16,17,
1563  18,19,10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,15,16,17,
1564  18,19,10,11,12,13,14,15,16,17,18,19,10,11,12,13,14,15,16,17};
1565  int buffer = prepostAddress(prepost);
1566  if (buffer>=0 && tray>=1 && tray<=120) {
1567  if (mMIX[buffer]) {
1568  int address = traydsm[tray-1]*8 + dsmmap[traych[tray-1]/3];
1569  int ch = traych[tray-1]%3;
1570  return (mMIX[buffer]->TOF[address] >> (5*ch)) & 0x1f;
1571  }
1572  }
1573  return 0;
1574 }
1575 
1576 unsigned short StTriggerData2018::tofMultiplicity(int prepost) const
1577 {
1578  if (prepost==0) return L1_DSM->TOF[1]%8192;
1579  return 0;
1580 }
1581 
1582 void StTriggerData2018::dump() const
1583 {
1584  printf("***** StTriggerData Dump *****\n");
1585  printf(" mDebug=%d mData=%p\n",mDebug,mData);
1586  printf(" Year=%d EvtDesc version=%x header version%x\n",year(),version(),mData->FormatVersion);
1587  printf(" Run#=%d Event#=%d\n",mRun,eventNumber());
1588  printf(" %d pre and %d post crossing data available\n",numberOfPreXing(),numberOfPostXing());
1589  printf(" Token=%d TriggerWord=%x ActionWord=%x BusyStatus=%x\n",
1590  token(), triggerWord(), actionWord(), busyStatus());
1591  printf(" TUC Bits=%d : ",tcuBits());
1592  for (int i=0; i<16; i++) {printf(" %d",(tcuBits()>>(15-i))%2);}; printf("\n");
1593  printf(" BunchId 7bit=%d 48bit=%d\n",bunchId7Bit(), bunchId48Bit());
1594  printf(" Spin Bits=%d : ",spinBit());
1595  for (int i=0; i<8; i++) {printf(" %d",(spinBit()>>(7-i))%2);}; printf("\n");
1596  // printf(" CTB ADC : "); for (int i=0; i<240;i++){ printf("%d ",ctb(i,0)); }; printf("\n");
1597  printf(" BBC East ADC : "); for (int i=1; i<=24;i++){ printf("%d ",bbcADC(east,i,0)); }; printf("\n");
1598  printf(" BBC West ADC : "); for (int i=1; i<=24;i++){ printf("%d ",bbcADC(west,i,0)); }; printf("\n");
1599  printf(" BBC East TAC : "); for (int i=1; i<=16;i++){ printf("%d ",bbcTDC(east,i,0)); }; printf("\n");
1600  printf(" BBC West TAC : "); for (int i=1; i<=16;i++){ printf("%d ",bbcTDC(west,i,0)); }; printf("\n");
1601  for (int i=-numberOfPreXing(); i<=static_cast<int>(numberOfPostXing()); i++){
1602  printf(" BBC Sums %d xing : ",i);
1603  printf("East=%d West=%d Large tile East=%d West=%d\n",
1604  bbcADCSum(east,i),bbcADCSum(west,i),
1605  bbcADCSumLargeTile(east,i),bbcADCSumLargeTile(west,i));
1606  }
1607  printf(" BBC Earilest : "); printf("East=%d West=%d Difference+256=%d\n",
1608  bbcEarliestTDC(east,0),bbcEarliestTDC(west,0),bbcTimeDifference());
1609  printf(" ZDC Earilest : "); printf("East=%d West=%d Difference=%d\n",
1610  zdcEarliestTDC(east,0),zdcEarliestTDC(west,0),zdcTimeDifference());
1611  //printf(" FPD East North : ");for (int i=1; i<=49;i++){ printf("%d ",fpd(east,0,i,0)); }; printf("\n");
1612  //printf(" FPD East South : ");for (int i=1; i<=49;i++){ printf("%d ",fpd(east,1,i,0)); }; printf("\n");
1613  //printf(" FPD East Top : ");for (int i=1; i<=25;i++){ printf("%d ",fpd(east,2,i,0)); }; printf("\n");
1614  //printf(" FPD East Bottom : ");for (int i=1; i<=25;i++){ printf("%d ",fpd(east,3,i,0)); }; printf("\n");
1615  //printf(" FPD East North PS: ");for (int i=1; i<= 7;i++){ printf("%d ",fpd(east,4,i,0)); }; printf("\n");
1616  //printf(" FPD East South PS: ");for (int i=1; i<= 7;i++){ printf("%d ",fpd(east,5,i,0)); }; printf("\n");
1617  //printf(" FPD West South : ");for (int i=1; i<=49;i++){ printf("%d ",fpd(west,1,i,0)); }; printf("\n");
1618  //printf(" FPD West Bottom : ");for (int i=1; i<=25;i++){ printf("%d ",fpd(west,3,i,0)); }; printf("\n");
1619  //printf(" FPD West South PS: ");for (int i=1; i<= 7;i++){ printf("%d ",fpd(west,5,i,0)); }; printf("\n");
1620  //printf(" FPD Sums East : ");for (int j=0; j<4 ;j++) printf("%d ",fpdSum(east,j)); printf("\n");
1621  //printf(" FPD Sums West : ");for (int j=0; j<4 ;j++) printf("%d ",fpdSum(west,j)); printf("\n");
1622  printf(" ZDC Sum(A) East : ");printf("%d ",zdcAttenuated(east)); printf("\n");
1623  printf(" ZDC Sum(A) West : ");printf("%d ",zdcAttenuated(west)); printf("\n");
1624  printf(" ZDC Sum(UA) East : ");printf("%d ",zdcUnAttenuated(east)); printf("\n");
1625  printf(" ZDC Sum(UA) West : ");printf("%d ",zdcUnAttenuated(west)); printf("\n");
1626  printf(" VPD E Earliest TAC : %d\n", vpdEarliestTDC(east));
1627  printf(" VPD W Earliest TAC : %d\n", vpdEarliestTDC(west));
1628  printf(" VPD TimeDifference : %d\n", vpdTimeDifference());
1629  printf(" L2 result : \n");
1630  for (int j=0; j<4 ;j++) { for (int k=0; k<16; k++) {printf("%u ",*(l2Result()+j*16+k)); } printf("\n");}
1631  printf("BBClayer1:");
1632  int buffer = prepostAddress(0);
1633  if (buffer >=0){
1634  if (mBBC[buffer]){
1635  for (int i = 0;i < 16;i++) printf(" %1x %04X", i, mBBC[buffer]->BBClayer1[i]);
1636  }
1637  }
1638  printf("\n");
1639  printf("ZDClayer1:");
1640  if (buffer >=0){
1641  if (mBBC[buffer]){
1642  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, mBBC[buffer]->ZDClayer1[i]);
1643  }
1644  }
1645  printf("\n");
1646  printf("VPDlayer1:");
1647  if (buffer >=0){
1648  if (mBBC[buffer]){
1649  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, mBBC[buffer]->VPD[i]);
1650  }
1651  }
1652  printf("\n");
1653  printf("VTX:");
1654  if (L1_DSM){
1655  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, L1_DSM->VTX[i]);
1656  }
1657  printf("\n");
1658  printf("Last DSM:");
1659  if (L1_DSM){
1660  for (int i = 0;i < 8;i++) printf(" %1x %04X", i, L1_DSM->lastDSM[i]);
1661  }
1662  printf("\n");
1663  printf("***** End StTriggerData Dump *****\n");
1664 }
1665 
1666 void StTriggerData2018::killFMS(){
1667  TrgOfflen2018* offlen;
1668  int npre = numberOfPreXing();
1669  int npost = numberOfPostXing();
1670  for (int i=0; i<1+npre+npost; i++){
1671  if (i==0)
1672  {offlen = mData->MainX;}
1673  else {
1674  if (mData->PrePostList[i-1]==0) continue;
1675  offlen = (TrgOfflen2018*) ((char*)mData + mData->PrePostList[i-1]);
1676  }
1677  int j;
1678  j=offlen[y18QT1_CONF_NUM].length; if (j>0){memset((char*)mData + offlen[y18QT1_CONF_NUM].offset, 0, j); offlen[y18QT1_CONF_NUM].length=0;};
1679  j=offlen[y18QT2_CONF_NUM].length; if (j>0){memset((char*)mData + offlen[y18QT2_CONF_NUM].offset, 0, j); offlen[y18QT2_CONF_NUM].length=0;};
1680  j=offlen[y18QT3_CONF_NUM].length; if (j>0){memset((char*)mData + offlen[y18QT3_CONF_NUM].offset, 0, j); offlen[y18QT3_CONF_NUM].length=0;};
1681  j=offlen[y18QT4_CONF_NUM].length; if (j>0){memset((char*)mData + offlen[y18QT4_CONF_NUM].offset, 0, j); offlen[y18QT4_CONF_NUM].length=0;};
1682  }
1683 }
1684 
1685 void StTriggerData2018::swapRawDet(DataBlock2018* data, int name, int hlength,int bs)
1686 {
1687  BELayerBlock2018* bc1;
1688  MIXBlock2018* mix;
1689  BBCBlock2018 *bbc;
1690  QTBlock2018* qtdata;
1691  int header_length = 8;
1692  if(bs) swapI((unsigned int*)&data->length);
1693  switch(name){
1694  case y18MXQ_CONF_NUM : case y18EQ3_CONF_NUM : case y18BBQ_CONF_NUM :
1695  case y18QT1_CONF_NUM : case y18QT2_CONF_NUM : case y18QT3_CONF_NUM : case y18QT4_CONF_NUM :
1696  case y18EQ1_CONF_NUM : case y18EQ2_CONF_NUM :
1697  header_length = 12; break;
1698  }
1699  if (hlength != data->length + header_length){
1700  mErrorFlag = mErrorFlag | (1 << name);
1701  printf("StTriggerData2018: Error reading Block=%2d [%1c%1c%1c%1c] length %d != %d + %d\n",
1702  name,data->name[0],data->name[1],data->name[2],data->name[3],
1703  hlength,data->length,header_length);
1704  printf("StTriggerData2018: Droping the data block =%2d [%1c%1c%1c%1c] with ErrorFlag=0x%x\n",
1705  name,data->name[0],data->name[1],data->name[2],data->name[3],mErrorFlag);
1706  data=0;
1707  return;
1708  }
1709  if (bs){
1710  switch(name){
1711  case y18BC1_CONF_NUM :
1712  bc1 = (BELayerBlock2018*) data;
1713  swapSSn((unsigned int*)bc1->BEMClayer1,48);
1714  swapSSn((unsigned int*)bc1->EEMClayer1,16);
1715  break;
1716  case y18MIX_CONF_NUM :
1717  mix = (MIXBlock2018*) data;
1718  swapSSn((unsigned int*)mix->FPDEastNSLayer1,8);
1719  swapSSn((unsigned int*)mix->TOFLayer1,8+48);
1720  break;
1721  case y18BCW_CONF_NUM :
1722  //only char
1723  break;
1724  case y18BCE_CONF_NUM :
1725  //only char
1726  break;
1727  case y18BBC_CONF_NUM :
1728  bbc = (BBCBlock2018*) data;
1729  swapSSn((unsigned int*)bbc->BBClayer1,16+8+8+16+8+8);
1730  break;
1731  case y18FMS_CONF_NUM :
1732  //only char
1733  break;
1734  case y18MXQ_CONF_NUM :
1735  case y18EQ3_CONF_NUM :
1736  case y18BBQ_CONF_NUM :
1737  case y18QT1_CONF_NUM :
1738  case y18QT2_CONF_NUM :
1739  case y18QT3_CONF_NUM :
1740  case y18QT4_CONF_NUM :
1741  case y18EQ1_CONF_NUM :
1742  case y18EQ2_CONF_NUM :
1743  qtdata = (QTBlock2018*) data;
1744  swapI((unsigned int*)&qtdata->dataLoss);
1745  swapIn(qtdata->data, qtdata->length/4);
1746  break;
1747  }
1748  }
1749  if(mDebug>0)
1750  printf("Read id=%2d name=%1c%1c%1c%1c length=%d\n",
1751  name,data->name[0],data->name[1],data->name[2],data->name[3],data->length);
1752 }
1753 
1754 void StTriggerData2018::Streamer(TBuffer &R__b)
1755 {
1756  // Stream an object of class StTriggerData2018.
1757 
1758  if (R__b.IsReading()) {
1759  R__b.ReadClassBuffer(StTriggerData2018::Class(),this);
1760  // cout << "StTriggerData2018::Streamer read trigger data!!!"<<endl;
1761  if(mData) readData();
1762  }
1763  else {
1764  R__b.WriteClassBuffer(StTriggerData2018::Class(),this);
1765  }
1766 }