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