StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
year2003.cxx
1 #include "St_trg_Maker.h"
2 #include "StDaqLib/TRG/trgStructures2003.h"
3 #include "St_DataSetIter.h"
4 #include "StDAQMaker/StDAQReader.h"
5 #include "StDAQMaker/StTRGReader.h"
6 #include "tables/St_dst_L0_Trigger_Table.h"
7 #include "tables/St_dst_L1_Trigger_Table.h"
8 #include "tables/St_dst_L2_Trigger_Table.h"
9 #include "tables/St_dst_TrgDet_Table.h"
10 #include "tables/St_ctu_raw_Table.h"
11 #if 0
12 #include "tables/St_mwc_raw_Table.h"
13 #endif
14 #include "tables/St_dst_TrgDet_Table.h"
15 #define PREPOST 11
16 
17 void St_trg_Maker::SecondDstDaq2003(St_dst_L0_Trigger *dst2) {
18  int i;
19 
20  dst_L0_Trigger_st *tt = dst2->GetTable();
21  tt->TrgToken = mS2003->EvtDesc.TrgToken;
22  tt->TriggerActionWd = mActionWord;
23  tt->DSMInput = mS2003->EvtDesc.DSMInput;
24  tt->DSMAddress = mS2003->EvtDesc.DSMAddress;
25  tt->TriggerWd = mS2003->EvtDesc.TriggerWord;
26  tt->DetectorBusy = mS2003->EvtDesc.modifiedBusyStatus;
27  tt->addBits = mS2003->EvtDesc.addBits;
28  for(i=0;i<32;i++) tt->CPA[i]=mS2003->TrgSum.DSMdata.CPA[i];
29  tt->MWC_CTB_mul = mS2003->TrgSum.DSMdata.lastDSM[2];
30  tt->MWC_CTB_dipole = 0;
31  tt->MWC_CTB_topology = 0;
32  tt->MWC_CTB_moment = 0;
33 }
34 
36 void St_trg_Maker::CtbMwcDaq2003(St_dst_TrgDet *dst1) {
37  int npre,npost,pp,tray,slat;
38  dst_TrgDet_st *tt = dst1->GetTable();
39 
40  tt->bunchXing_lo=mS2003->EvtDesc.bunchXing_lo;
41  tt->bunchXing_hi=(mS2003->EvtDesc.bunchXing_hi)&(0xFFFF);
42  npre=mS2003->EvtDesc.npre;
43  npost=mS2003->EvtDesc.npost;
44  tt->npre=npre;
45  tt->npost=npost;
46  for(pp=0;pp<1+npre+npost;pp++) {
47  assert(pp<PREPOST);
48  // CTB information
49  for(slat=0;slat<2;slat++) {
50  for(tray=0;tray<120;tray++) {
51  tt->nCtb[tray][slat][pp]=mS2003->rawTriggerDet[pp].CTB[ctbmap[tray][slat]];
52  tt->timeCtb[tray][slat][pp]=0;
53  }
54  }
55 #if 0
56  // MWC information
57  int i,subsector,sector;
58  for(sector=0;sector<24;sector++) {
59  for(subsector=0;subsector<4;subsector++) {
60  tt->nMwc[sector][subsector][pp]=mS2003->rawTriggerDet[pp].MWC[mwcmap[sector][subsector]];
61  }
62  }
63  for(i=0;i<16;i++) tt->ctbaux[i][pp]=mS2003->rawTriggerDet[pp].CTB[auxctbmap[i]];
64  for(i=0;i<32;i++) tt->mwcaux[i][pp]=mS2003->rawTriggerDet[pp].MWC[auxmwcmap[i]];
65 #endif
66  }
67 }
68 
69 Int_t St_trg_Maker::SanityCheck2003() {
70  unsigned short x;
71  x=mS2003->TrgSum.L1SumBytes; assert(x==0x0084||x==0x8400);
72  x=mS2003->TrgSum.L2SumBytes; assert(x==0x0084||x==0x8400);
73  return kStOK;
74 }
75 
77 #ifdef LATER_THAN_YEAR_2000 // Year 2000 trgStructures.h does not have BEMC.
78 #define BYTESPERDSM 16 //The number of output bytes the 20 signals are packed into
79 typedef unsigned char byte;
80 
81 int tower_map[10] = {0,1,2,3,4,5,6,7,8,9}; // Corrected per Jenn Klay in her email of Fri, 22 Feb 2002.
82 int swapByteOrder[16] = {7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8};
83 
84 //dsm_to_patch follows the numbering scheme in the offline software, since
85 //it fills a table that is used in offline. The numbers correspond to the
86 //numbering of the EMC Crates with respect to the Tower ID's from Jose
87 //Riso, which seems to count backward. i.e. Patch 1 contains Tower 4800,
88 //while Patch 300 contains Tower 1. J.L. Klay 18-Feb-2002
90 int AA_dsm_to_patch[5] = {0,0,15,16,17}; //AuAu 2001
91 int pp_dsm_to_patch[7] = {0,0,15,28,16,29,17}; //pp 2001-02: (After 1-Dec-2001)
93 //See below - timestamp check determines which one to use
94 
95 void St_trg_Maker::Emc2003(St_dst_TrgDet *dst1) {
96  dst_TrgDet_st *tt = dst1->GetTable();
97 
98  int NUMDSM;
99 
100  //Check timestamp of events to decide which mapping to use
101  //pp_dsm_to_patch[7] for after 01-Dec-2001, AA_dsm_to_patch[5] for before that date
102  EventReader *er=fVictorPrelim->getEventReader();
103  EventInfo info=er->getEventInfo();
104  std::time_t utime = info.UnixTime;
105  std::tm *time = gmtime(&utime);
106  int year=1900+time->tm_year;
107  int month=1+time->tm_mon;
108  int day=time->tm_mday;
109  char text1[80];
110  sprintf(text1,"%04d%02d%02d",year,month,day);
111  unsigned int date=atoi(text1);
112  if (date < 20011201) { //Before 01-Dec-2001
113  NUMDSM = 5;
114  } else {
115  NUMDSM = 7;
116  }
117  byte dsmval[NUMDSM][BYTESPERDSM];
118  byte val[BYTESPERDSM];
119  byte hi_tower,tower_sum;
120  int i,j,k,index,nt,patch,sort;
121 
122  for (i=0; i<NUMDSM ; i++) { //Fill dsm info, including L1 & L2
123  for (j=0; j < BYTESPERDSM; j++) {
124  index = (i*16) + j;
125  dsmval[i][j] = mS2003->rawTriggerDet[0].BEMC[index];
126 // if (mS2003->rawTriggerDet[0].BEMC[index]!=0)
127 // printf("dsmval[%2d][%2d]= %2d",i,j,dsmval[i][j]);
128  }
129  }
130 
131  for (i=2; i<NUMDSM; i++) { //Loop through L0 DSMs, skipping L1 and L2
132  //Convert the DSM output byte ordering to EMC software ordering
133  if (date < 20011201) {
134  patch = AA_dsm_to_patch[i]; //AuAu run had 5 boards
135  } else {
136  patch = pp_dsm_to_patch[i]; //pp run had 7 boards
137  }
138  for (j=0; j<BYTESPERDSM; j++) {
139  k = swapByteOrder[j];
140  val[k] = dsmval[i][j];
141  }
142  nt = 0; //tower counter withing DSM - 10 max
143  //Unpack the bits into 20 signals and store in table
144  for (index=0; index<5; index++) {
145  k=index*3;
146 
147  hi_tower = (val[k] & 0x3f);
148  tower_sum = ((val[k]>>6) & 0x3) + ((val[k+1] & 0xF)<<2);
149 
150  sort = tower_map[nt] + 10*patch;
151  assert(sort>=0&&sort<300); // The limit 300 is in the idl file for dst_TrgDet.
152  tt->emcHiTower[sort] = hi_tower;
153  tt->emcTrigPatch[sort] = tower_sum;
154  //printf("emcHiTower[%2d] = %2d, ",sort,hi_tower);
155  //printf("emcTowerSum[%2d] = %2d\n",sort,tower_sum);
156  nt += 1;
157 
158  hi_tower = ((val[k+1]>>4) & 0xF) + ((val[k+2] & 0x3)<<4);
159  tower_sum = ((val[k+2]>>2) & 0x3F);
160 
161  sort = tower_map[nt] + 10*patch;
162  assert(sort>=0&&sort<300);
163  tt->emcHiTower[sort] = hi_tower;
164  tt->emcTrigPatch[sort] = tower_sum;
165  nt += 1;
166  //printf("emcHiTower[%2d] = %2d, ",sort,hi_tower);
167  //printf("emcTowerSum[%2d] = %2d\n",sort,tower_sum);
168  }
169  }
170 }
171 #endif // LATER_THAN_YEAR_2000
172 
174 // comment 77y: "action word has 9 as first hex digit and last bit lit, and trigger word
175 // is 0xf200" from Bill Love (email Nov 9 2001).
176 
177 int St_trg_Maker::Daq2003(St_DataSet *herb,St_dst_TrgDet *dst1,St_dst_L0_Trigger *dst2,
178  St_dst_L1_Trigger *dst3,St_dst_L2_Trigger *dst4) {
179 
180  char *ptr,isLaser=0,isPhysics=0,isPulser=0,thisEventOk=0;
181  fVictorPrelim=(StDAQReader*)(herb->GetObject()); assert(fVictorPrelim);
182  fVictor=fVictorPrelim->getTRGReader(); assert(fVictor);
183 
184  // No TRG bank in .daq file. Perhaps a pedestal or laser run?
185  assert(fVictor->thereIsTriggerData());
186 
187  // StTRGReader *St_trg_Maker::fVictor;
188  // TRG_Reader *StTRGReader::fTRGImpReader;
189  // Bank_TRGD *TRG_Reader::pBankTRGD;
190 
191  ptr=(char*)(fVictor->getData());
192  assert(ptr);
193  mS2003=(TrgDataType2003*)ptr;
194  mActionWord=
195  ( (unsigned short)(mS2003->EvtDesc.actionWdTrgCommand) * 16 * 16 * 16 ) +
196  ( (unsigned short)(mS2003->EvtDesc.actionWdDaqCommand) * 16 * 16 ) +
197  ( mS2003->EvtDesc.actionWdDetectorBitMask & 0x00ff );
198  // Int_t Iret = SanityCheck2003();
199  // if (Iret != kStOK) {
200  // printf("St_trg_Maker:: Daq2003 : failed L1/L2 summary sanity check.\n");
201  // return Iret;
202  // }
203 
204  // printf("St_trg_Maker:: Daq2003 : passed L1/L2 summary sanity check.\n");
205  LOG_INFO << Form("Daq2003 : ActionWrdCommand is 0x%0x TriggerWord 0x%0x",
206  mS2003->EvtDesc.actionWdTrgCommand,
207  mS2003->EvtDesc.TriggerWord) << endm;
208 
209 
210  if( (((mActionWord)&0xf000)==0x9000 ) &&
211  (((mActionWord)&0x0001)==0x0001 ) //&&
212  //( mS2003->EvtDesc.TriggerWord ==0xf200 )
213  ) isLaser=7;
214 
215  // See comment 77y above.
216  if(mActionWord>>12==4) isPhysics=7;
217  if(mS2003->EvtDesc.TriggerWord==0xf101) isPulser=7;
218 
219  if((m_Mode )==0) thisEventOk=7;
220  if((m_Mode&1)&&isPhysics) thisEventOk=7;
221  if((m_Mode&2)&&isLaser) thisEventOk=7;
222  if((m_Mode&4)&&isPulser) thisEventOk=7;
223 
224 
225  const char *oo = "unknown";
226  if(isPhysics) oo="Physics";
227  if(isLaser) oo="Laser";
228  if(isPulser) oo="Pulser";
229 
230  LOG_INFO <<Form("Daq2003 : %s event. TrgActionWd=0x%x. TriggerWd=0x%0x. Returning %s. m_Mode=%d.\n",
231  oo,mActionWord,
232  mS2003->EvtDesc.TriggerWord,
233  thisEventOk?"kStOK":"kStErr",
234  m_Mode) << endm;
235 
236  if (!thisEventOk) return kStErr; // Skip this event.
237 
238  // dumpDataToScreenAndExit();
239  VpdDaq2003(dst1); // The function
240  ZdcDaq2003(dst1); // St_trg_Maker::Sim
241  BbcDaq2003(dst1); // <--- this will be in as a hack
242  CtbMwcDaq2003(dst1); // has four lines
243  SecondDstDaq2003(dst2); // which are analogous to these four.
244  TakeCareOfL1andL2Daq2003(dst3,dst4);
245 #ifdef LATER_THAN_YEAR_2000 // Year 2000 trgStructures.h does not have BEMC.
246  Emc2003(dst1);
247 #endif
248 
249  // Request for a clear message
250  //if(Debug() > 0)
251  cout << "St_trg_Maker:: Daq2003 : Event has been accepted" << endl;
252  return kStOK;
253 }
254 
255 
256 void St_trg_Maker::TakeCareOfL1andL2Daq2003(St_dst_L1_Trigger *dst3,St_dst_L2_Trigger *dst4) {
257  int i;
258  dst_L1_Trigger_st *tt1 = dst3->GetTable();
259  dst_L2_Trigger_st *tt2 = dst4->GetTable();
260  for(i=0;i<32;i++) {
261  tt1->L1_result[i] = mS2003->TrgSum.L1Result[i];
262  tt2->L2_result[i] = mS2003->TrgSum.L2Result[i];
263  }
264 }
265 void St_trg_Maker::VpdDaq2003(St_dst_TrgDet *dst1) {
266  int i;
267  dst_TrgDet_st *tt = dst1->GetTable();
268  for(i=0;i<48;i++) {
269  tt->adcVPD[i]=0;
270  tt->timeVPD[i]=0;
271  }
272  tt->TimeEastVpd=0;
273  tt->TimeWestVpd=0;
274  tt->vertexZ=0;
275 }
276 void St_trg_Maker::ZdcDaq2003(St_dst_TrgDet *dst1) {
277  int i;
278  dst_TrgDet_st *tt = dst1->GetTable();
279  for(i=0;i<8;i++) tt->lastDSM[i]=mS2003->TrgSum.DSMdata.lastDSM[i];
280  for(i=0;i<16;i++) {
281  tt->adcZDC[i]=mS2003->rawTriggerDet[0].ZDC[i];
282  tt->tdcZDC[i]=0;
283  tt->BCdata[i]=mS2003->TrgSum.DSMdata.BCdata[i];
284  }
285  tt->adcZDCEast=mS2003->rawTriggerDet[0].ZDC[13];
286  tt->adcZDCWest=mS2003->rawTriggerDet[0].ZDC[10];
287  tt->adcZDCsum=mS2003->rawTriggerDet[0].ZDC[13]+mS2003->rawTriggerDet[0].ZDC[10];
288 }
289 
290 
292 void St_trg_Maker::BbcDaq2003(St_dst_TrgDet *dst1) {
293  int i;
294  dst_TrgDet_st *tt = dst1->GetTable();
295  for(i=0; i < 80 ;i++) {
296  tt->BBC[i] = (unsigned short) mS2003->rawTriggerDet[0].BBC[i];
297  //printf("DEBUG >>> %2.2d %d %c\n",i,tt->BBC[i],tt->BBC[i]);
298  }
299 }
300 
301 void St_trg_Maker::dumpDataToScreenAndExit2003() {
302  //int i;
303  exit(2);
304 }
305 
306 
Int_t m_Mode
counters
Definition: StMaker.h:81
void CtbMwcDaq2003(St_dst_TrgDet *dst1)
This method copies Ctb and Mwc trigger data to the dst_TrgDet_st table.
Definition: year2003.cxx:36
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:40
void BbcDaq2003(St_dst_TrgDet *dst)
Following this layout of one routine per trigger to recover.
Definition: year2003.cxx:292
Definition: Stypes.h:44