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