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