StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
St2eemcFeeRawMaker.cxx
1 // *-- Author : J.Balewski, R.Fatemi
2 //
3 // $Id: St2eemcFeeRawMaker.cxx,v 1.16 2012/12/12 22:02:49 fisyak Exp $
4 
5 #ifdef __APPLE__
6 #include <sys/types.h>
7 #endif
8 #include <Stiostream.h>
9 #include <math.h>
10 
11 #include "StEventTypes.h"
12 #include "StEvent.h"
13 #include <TTree.h>
14 
15 #include "St2eemcFeeRawMaker.h"
16 
17 #include "StEEmcUtil/database/StEEmcDb.h"
18 #include "StEEmcUtil/database/EEmcDbItem.h"
19 #include "EEfeeRaw/EEfeeDataBlock.h"
20 #include "EEfeeRaw/EEfeeRawEvent.h"
21 #include "EEfeeRaw/EEmcEventHeader.h"
22 #include "EEfeeRaw/EEname2Index.h"
23 
24 
25 ClassImp(St2eemcFeeRawMaker)
26 
27 //_____________________________________________________________________
28 St2eemcFeeRawMaker::St2eemcFeeRawMaker(const char *name):StMaker(name){
29  moutTTree=0;
30  meeDb=0;
31  meveTT=new EEfeeRawEvent();
32  mrunTT=new EEmcEventHeader();
33  mNFeeCrate=6; // max numbers of FEE Data blocks
34 }
35 
36 //___________________________________________________________
37 St2eemcFeeRawMaker::~St2eemcFeeRawMaker(){
38  // outTTree->Show(1);
39  // outTTree->Print();
40  delete mrunTT;
41  delete meveTT;
42  delete [] mcrateData;
43 }
44 
45 
46 //__________________________________________________
47 //__________________________________________________
48 //__________________________________________________
49 
50 Int_t St2eemcFeeRawMaker::Init(){
51  meeDb = (StEEmcDb*)this->GetDataSet("StEEmcDb");
52  assert(moutTTree); // all should be initialized prior to use
53  assert(meeDb); // --||--
54  assert(meveTT); // --||--
55  assert(mrunTT); // --||--
56  assert(mNFeeCrate>0); // --||--
57  mcrateData=new EEfeeDataBlock[mNFeeCrate];
58 
59  // assigne eveTT with output TTree
60  // assigne runTT with output TTree
61 
62  moutTTree->Branch("head","EEmcEventHeader",&mrunTT,16000,99);
63  //printf("aa runHead Branch added \n");
64 
65  moutTTree->Branch("evt","EEfeeRawEvent",&meveTT,16000,99);
66  // printf("aa eve-Tbranch added \n");
67 
68 
69  return StMaker::Init();
70 }
71 
72 
73 //___________________________________________________
74 //___________________________________________________
75 //___________________________________________________
76 
77 Int_t St2eemcFeeRawMaker::InitRun (int runNumber){
78 
79  StEvent* mEvent = (StEvent*)GetInputDS("StEvent");
80  assert(mEvent); // fix your chain or open the right event file
81  LOG_INFO<<Form("\n%s accessing StEvent ID=%d\n",GetName(),mEvent->id())<<endm;
82  LOG_INFO<<Form("StEvent time=%d, ID=%d, runID=%d\n",(int)mEvent->time(),(int)mEvent->id(),(int)mEvent->runId())<<endm;
83 
84  mrunTT->setTimeStamp(this->GetDBTime().Convert());
85  mrunTT->setProcessingTime(time(0));
86  char text[200];
87  sprintf(text," M-C event file, run=%d , created by %s",mEvent->runId(),GetName());
88  mrunTT->setComment(text);
89  mrunTT->print();
90 
91  LOG_INFO<<Form("\n%s::InitRun(%d) list DB content \n",GetName(),runNumber)<<endm;
92  //meeDb->print();
93  return kStOK;
94 }
95 
96 
97 //____________________________________________________
98 //____________________________________________________
99 //____________________________________________________
101 
102  StEvent* mEvent = (StEvent*)GetInputDS("StEvent");
103  assert(mEvent);// fix your chain or open the right event file
104  LOG_INFO<<Form("\n%s accesing StEvent ID=%d\n",GetName(),mEvent->id())<<endm;
105 
106  StEmcCollection* emcCollection = mEvent->emcCollection();
107  // StEmcDetector* twB = emcCollection->detector(kBarrelEmcTowerId);
108  // assert(twB);
109 
110  StEmcDetector* twE = emcCollection->detector(kEndcapEmcTowerId);
111  if(!twE) {
112  LOG_WARN<<"No EEMC twE hits, skip event"<<endm;
113  return kStOK;
114  }
115 
116  // ....... Access DB lookup table
117 
118  // const StEEmcDb::NameXchanItem* index2chan=meeDb->getIndex2chan();
119 
120  // ....... Initialize header of new TTree record ..........
121  int nDrop=0; //counts MC hits not assigned to crate/chan
122  int icr;
123  UShort_t head[4];
124 
125  UChar_t token=(int)mEvent->id()%256;
126  for(icr=0;icr<mNFeeCrate;icr++) {
127  int crateID=icr+1;
128  mcrateData[icr].clear();
129  // crateData[icr].print();// should be empty
130  int j;
131  for(j=0;j<2;j++) head[j]=((0xa+j)<<8) +crateID;
132  head[2]= token;
133  head[3]=(UChar_t)crateID;// + (mEvent->id()%(1<<4))<<8;
134  // printf(" iHead: raw[4]/hex= %x %x %x %x \n",head[0],head[1],head[2],head[3]);
135  mcrateData[icr].setHead(head);
136  }
137 
138  // ....... Copy data to Local EEfeeDataBlock's .................
139 
140  int i;
141  LOG_INFO<<Form("%s:: E_EMC Tower HITS ... %d\n",GetName(),twE->numberOfModules())<<endm;
142  for ( i = 0; i < (int)twE->numberOfModules(); i++) { // The E-EMC modules
143  // printf("AAA %d\n",i);
144  StEmcModule* stmod = twE->module(i);
145  if(stmod==0) continue;
146  StSPtrVecEmcRawHit& emcTowerHits = stmod->hits();
147  LOG_INFO<<Form("bbb i=%d %d\n",i,emcTowerHits.size())<<endm;
148 
149  uint j;
150  for ( j = 0; j < emcTowerHits.size(); j++) {
151  int adc= emcTowerHits[j]->adc();
152  int sec= emcTowerHits[j]->module()+1;
153  int sub= emcTowerHits[j]->sub()+'A';
154  int eta= emcTowerHits[j]->eta()+1;
155  float energy=emcTowerHits[j]->energy();
156 
157  const EEmcDbItem *dbItem=meeDb->getT(sec,sub,eta);
158  assert(dbItem); // fatal error in EEmcDb-maker
159 
160  int chan=dbItem->chan;
161  int slot=dbItem->crate;
162  // adc=adc+(int)dbItem->ped; // add pedestal for each channel
163  // tmp
164 
165  LOG_INFO<<Form("j=%d, sec=%d, sub=%c, eta=%d rawAdc=%d energy =%g -->crate/chan=%d/%d\n",j,sec,sub,eta,adc,energy,slot,chan)<<endm;
166 
167 
168  // record this entry
169  if(adc<=0) continue;
170  if(chan<0 || slot<0) { nDrop++; continue;}
171  icr=slot-1;
172  assert(icr>=0);
173  assert(icr<mNFeeCrate);
174  mcrateData[icr].setData(chan,adc);// printf(" record icr=%d dac=%d\n",icr,adc);
175  }
176  }
177 
178  // ....... Store local EEfeeDataBlock's in TTree .................
179  meveTT->clear(); // clear current TTree-event
180  meveTT->setID(mEvent->id());
181  int n1=0;
182  for(icr=0;icr<mNFeeCrate;icr++) {
183  if(mcrateData[icr].getNData(0)<=0) continue; // empty data block
184 
185  LOG_INFO<<Form("SS crateID=%d, Npositive=%d\n",icr+1,mcrateData[icr].getNData(0))<<endm;
186  // crateData[icr].print(0);
187  meveTT->addFeeDataBlock(mcrateData+icr);
188  n1++;
189  }
190  // mrunTT->print();
191  // eveTT->print();
192 
193  moutTTree->Fill();
194 
195  // eveTT->print(1);
196  LOG_INFO<<Form("%s:: stored TTree with %d=%d data blocks, ID=%d \n",GetName(),n1,meveTT->block->GetEntries(),meveTT->getID())<<endm;
197 
198 
199  return kStOK;
200 }
201 
202 
203 
204 
205 // $Log: St2eemcFeeRawMaker.cxx,v $
206 // Revision 1.16 2012/12/12 22:02:49 fisyak
207 // add sys/types.h include for APPLE
208 //
209 // Revision 1.15 2009/02/04 20:33:28 ogrebeny
210 // Moved the EEMC database functionality from StEEmcDbMaker to StEEmcUtil/database. See ticket http://www.star.bnl.gov/rt2/Ticket/Display.html?id=1388
211 //
212 // Revision 1.14 2007/05/30 02:38:43 balewski
213 // replace printf -->LOG_XXX
214 //
215 // Revision 1.13 2004/04/12 16:20:14 balewski
216 // DB cleanup & update
217 //
218 // Revision 1.12 2003/11/17 15:47:04 balewski
219 // fix of bug
220 //
221 // Revision 1.11 2003/09/02 17:57:55 perev
222 // gcc 3.2 updates + WarnOff
223 //
224 // Revision 1.10 2003/04/16 20:33:56 balewski
225 // small fixes in eemc daq reader
226 //
227 // Revision 1.9 2003/03/26 21:16:42 balewski
228 // *** empty log message ***
229 //
230 // Revision 1.8 2003/03/25 18:30:21 balewski
231 // towards EEMC daq reader
232 //
233 // Revision 1.7 2003/03/22 19:37:24 balewski
234 // *** empty log message ***
235 //
236 // Revision 1.6 2003/03/07 15:35:53 balewski
237 // towards EEMC daq reader
238 //
239 // Revision 1.5 2003/02/21 22:21:39 balewski
240 // time stamp added
241 //
242 // Revision 1.4 2003/02/18 22:01:47 balewski
243 // fixes
244 //
245 // Revision 1.3 2003/02/18 19:56:07 balewski
246 // add pedestals
247 //
248 // Revision 1.2 2003/02/17 18:45:40 balewski
249 // change names
250 //
251 // Revision 1.1 2003/01/28 23:15:25 balewski
252 // start
253 //
254 // Revision 1.1 2002/12/17 19:41:35 balewski
255 // separated from EEmc to avoid some dependeces during compilation
256 //
257 // Revision 1.2 2002/12/05 14:21:58 balewski
258 // cleanup, time stamp corrected
259 //
260 // Revision 1.1 2002/11/30 23:00:28 balewski
261 // male poprawki
262 //
virtual Int_t InitRun(int runumber)
to change time stamp in TTree
virtual const char * GetName() const
special overload
Definition: StMaker.cxx:237
Definition: Stypes.h:40
int chan
hardware channel
Definition: EEmcDbItem.h:28