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