StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Stl3CounterMaker.cxx
1 //*-- Author :Christof Struck
2 //
4 // //
5 // Stl3CounterMaker //
6 // //
7 // calculates trigger counters //
8 // - nProcessed //
9 // - nAccepted //
10 // - nBuild //
11 // for each l3 algorithm switched on for the given run //
12 // and the global counters //
13 // - nProcessed //
14 // - nReconstructed //
15 // and writes this to the database on a daq-file basis //
16 // //
18 //
19 //
20 // $Id: Stl3CounterMaker.cxx,v 1.10 2017/04/26 21:15:16 perev Exp $
21 //
22 // $Log: Stl3CounterMaker.cxx,v $
23 // Revision 1.10 2017/04/26 21:15:16 perev
24 // Hide m_Debug
25 //
26 // Revision 1.9 2008/01/23 19:10:32 fine
27 // Fix the lost L3_Reader class definition
28 //
29 // Revision 1.8 2007/04/28 17:56:23 perev
30 // Redundant StChain.h removed
31 //
32 // Revision 1.7 2003/09/02 18:00:16 perev
33 // gcc 3.2 updates + WarnOff
34 //
35 // Revision 1.6 2002/04/19 22:24:21 perev
36 // fixes for ROOT/3.02.07
37 //
38 // Revision 1.5 2002/03/07 22:03:41 struck
39 // major update: using new NotifyMe() to get input filename, allows to run on
40 // more than one input file in a chain, two output tables separated into two files
41 // and put into dedicated dir StarDb/RunLog_l3
42 //
43 // Revision 1.4 2002/02/26 21:40:38 struck
44 // move GetDataSet("StDAQReader") from Init() to Make(), solves a seg. fault in current dev release
45 //
46 // Revision 1.3 2002/02/20 23:31:10 struck
47 // final tune-up
48 //
49 // Revision 1.2 2002/02/20 22:09:49 struck
50 // added some debugging info
51 //
52 // Revision 1.1 2002/02/13 22:36:31 struck
53 // major code clean-up for Stl3RawReaderMaker, first version of Stl3CounterMaker
54 //
55 //
56 //
58 
59 
60 #include <stdlib.h>
61 #include <Stiostream.h>
62 #include "Stiostream.h"
63 #include "Stl3CounterMaker.h"
64 #include "St_DataSetIter.h"
65 #include "StMessMgr.h"
66 #include "StIOMaker/StIOMaker.h"
67 #include "StDAQMaker/StDAQReader.h"
68 #include "StDaqLib/L3/L3_Reader.hh"
69 #include "tables/St_l3RunSummary_Table.h"
70 #include "tables/St_l3AlgorithmInfo_Table.h"
71 #include "tables/St_l3AlgorithmCount_Table.h"
72 #include "tables/St_l3GlobalCounter_Table.h"
73 #include "Rtypes.h"
74 #include "TSystem.h"
75 
76 ClassImp(Stl3CounterMaker)
77 
78 //_____________________________________________________________________________
79 Stl3CounterMaker::Stl3CounterMaker(const char *name):StMaker(name){
80  // l3Counter constructor
81 }
82 
83 //_____________________________________________________________________________
84 Stl3CounterMaker::~Stl3CounterMaker(){
85 }
86 
87 
88 //_____________________________________________________________________________
89 Int_t Stl3CounterMaker::Init(){
90  // Init - is a first method the top level StChain calls to initialize all its makers
91 
92  //cout << "\n=======>> Stl3CounterMaker::Init()" << endl;
93 
94 
95  // set switches
96  mL3On = kFALSE;
97  mStoreDbTables = kTRUE;
98 
99  //SetDebug(1);
100 
101  // get notice from IOmaker
102  StIOMaker* IOMaker = (StIOMaker*)GetMaker("IO"); // for doEvents.C
103  if(!IOMaker) IOMaker = (StIOMaker*)GetMaker("inputStream"); // for bfc.C
104  if (IOMaker) {
105  IOMaker->SetNotify("OpenFile", this);
106  IOMaker->SetNotify("CloseFile", this);
107  }
108  else
109  cout << "Stl3CounterMaker::Init(): Could not SetNotify for IOMaker." << endl;
110 
111 
112  // reset database pointer
113  mDbSet = 0;
114 
115  // get new database tables
116  mAlgorithmCounterTable = new St_l3AlgorithmCount("l3AlgorithmCount", 1);
117  mGlobalCounterTable = new St_l3GlobalCounter("l3GlobalCounter", 1);
118 
119  // reset database tables
120  l3GlobalCounter_st totalCounterRow;
121  totalCounterRow.runNumber = 0;
122  totalCounterRow.fileNumber = 0;
123  totalCounterRow.nProcessed = 0;
124  totalCounterRow.nReconstructed = 0;
125  mGlobalCounterTable->AddAt(&totalCounterRow);
126 
127  for (int i=0; i<MaxNumberOfAlgorithms; i++) {
128  l3AlgorithmCount_st totalAlgCounterRow;
129  totalAlgCounterRow.runNumber = 0;
130  totalAlgCounterRow.algId = 0;
131  totalAlgCounterRow.fileNumber = 0;
132  totalAlgCounterRow.nProcessed = 0;
133  totalAlgCounterRow.nAccept = 0;
134  totalAlgCounterRow.nBuild = 0;
135  mAlgorithmCounterTable->AddAt(&totalAlgCounterRow);
136  }
137 
138  mNumberOfGl3Nodes = 0;
139  mNumberOfAlgorithms = 0;
140  mEventCounter = 0;
141 
142  // reset counter
143  for (int i=0; i<MaxNumberOfGl3Nodes; i++) {
144  mGlobalCounter[i].nProcessed = 0;
145  mGlobalCounter[i].nReconstructed = 0;
146  for (int j=0; j<MaxNumberOfAlgorithms; j++) {
147  mAlgorithmCounter[i][j].algId = 0;
148  mAlgorithmCounter[i][j].nProcessed = 0;
149  mAlgorithmCounter[i][j].nAccept = 0;
150  mAlgorithmCounter[i][j].nBuild = 0;
151  }
152  }
153 
154  // return
155  return StMaker::Init();
156 }
157 
158 
159 //_____________________________________________________________________________
160 void Stl3CounterMaker::NotifyMe(const char *about,const void *info)
161 {
162  //cout << "\n=======>> Stl3CounterMaker::NotifyMe()" << endl;
163  //cout << " about: " << about << ", info: " << ((char*) info) << endl;
164 
165  if (strcmp("CloseFile", about)==0) {
166  if (!mStoreDbTables) return;
167  else WriteTable();
168  }
169  if (strcmp("OpenFile", about)==0) {
170  mDaqFileName =((char*)info);
171  InitTable();
172  }
173 }
174 
175 
176 //_____________________________________________________________________________
177 Int_t Stl3CounterMaker::InitTable()
178 {
179  //cout << "\n=======>> Stl3CounterMaker::InitTable()" << endl;
180 
181  // extract file sequence number
182  TString seq(mDaqFileName(mDaqFileName.Index("_physics_"), 30));
183  if (seq.Contains(".daq")) {
184  TString fileNo = seq(21,4);
185  TString rowNo = seq(9,7);
186  mDaqFileSequenceNumber = atoi(fileNo.Data());
187  mRunNumber = atoi(rowNo.Data());
188  }
189  else {
190  mDaqFileSequenceNumber = 999;
191  mRunNumber = 9999999;
192  cout << "Stl3CounterMaker::InitTable(): Could not extract daq file run/sequence number." << endl;
193  }
194  if (Debug()) cout << "run number: " << mRunNumber << ", sequence number: " << mDaqFileSequenceNumber << endl;
195 
196 
197  // reset database tables
198  l3GlobalCounter_st* totalCounter = (l3GlobalCounter_st*) mGlobalCounterTable->GetTable();
199  mAlgorithmCounterTable->SetNRows(MaxNumberOfAlgorithms);
200  l3AlgorithmCount_st* totalAlgCounter = (l3AlgorithmCount_st*) mAlgorithmCounterTable->GetTable();
201 
202  totalCounter->runNumber = mRunNumber;
203  totalCounter->fileNumber = mDaqFileSequenceNumber;
204  totalCounter->nProcessed = 0;
205  totalCounter->nReconstructed = 0;
206 
207  for (int i=0; i<MaxNumberOfAlgorithms; i++) {
208  totalAlgCounter[i].runNumber = mRunNumber;
209  totalAlgCounter[i].fileNumber = mDaqFileSequenceNumber;
210  totalAlgCounter[i].algId = 0;
211  totalAlgCounter[i].nProcessed = 0;
212  totalAlgCounter[i].nAccept = 0;
213  totalAlgCounter[i].nBuild = 0;
214  }
215 
216  // reset counters
217  for (int i=0; i<MaxNumberOfGl3Nodes; i++) {
218  mGlobalCounter[i].nProcessed = 0;
219  mGlobalCounter[i].nReconstructed = 0;
220  for (int j=0; j<MaxNumberOfAlgorithms; j++) {
221  mAlgorithmCounter[i][j].algId = 0;
222  mAlgorithmCounter[i][j].nProcessed = 0;
223  mAlgorithmCounter[i][j].nAccept = 0;
224  mAlgorithmCounter[i][j].nBuild = 0;
225  }
226  }
227 
228  return 0;
229 }
230 
231 
232 //_____________________________________________________________________________
234 {
235  //
236  // Make - this method is called in loop for each event
237  //
238  cout << "Now we start l3Counter Maker. \n" ;
239 
240 
241  // get the l3 daqreader
242  // make Connection to raw data
243  DAQReaderSet = GetDataSet("StDAQReader");
244  if (!DAQReaderSet) {
245  gMessMgr->Error() << "Stl3CounterMaker::Make(): no DaqReader found!" << endm;
246  return kStWarn;
247  }
248  StDAQReader *daqReader = (StDAQReader*)(DAQReaderSet->GetObject()) ;
249  if (daqReader) {
250  ml3reader = daqReader->getL3Reader();
251 
252  if (ml3reader) {
253 
254  // set flag L3 ON
255  mL3On = kTRUE;
256 
257  // debug output
258  if (Debug()) {
259  if (ml3reader->getGlobalTrackReader())
260  cout << ml3reader->getGlobalTrackReader()->getNumberOfTracks()
261  << " global tracks found.\n";
262  }
263 
264  if (GetCounters()) {
265  gMessMgr->Error("Stl3CounterMaker: problems getting l3 counters.");
266  return kStErr;
267  }
268 
269  } // if (ml3reader)
270 
271  else {
272  // if L3 is on for this run
273  // crash chain
274  if (mL3On) {
275  cout << "ERROR: L3 is ON, but no l3 data found in this event." << endl;
276  return kStErr;
277  }
278  // if L3 is off so far
279  // it may be switched off for this run
280  // so don't crash the chain
281  else {
282  cout << "WARNING: no l3 data found." << endl;
283  return kStWarn;
284  }
285  }
286 
287  } // if (daqReader)
288 
289  // go home
290  return kStOk;
291 }
292 
293 
294 
295 //_____________________________________________________________________________
296 
297 Int_t Stl3CounterMaker::GetCounters()
298 {
299 
300  // get Gl3AlgorithmReader
301  Gl3AlgorithmReader* gl3Reader = ml3reader->getGl3AlgorithmReader();
302  if (!gl3Reader) {
303  cout << "ERROR: L3 is ON, but L3 summary data is missing!" << endl;
304  return 1;
305  }
306 
307  // check data
308  // L3_summary.on==0 indicates that the event crashed in
309  // L3 online and raw data contains no valid information for us
310  if (ml3reader->getL3_Summary()->on == 0) {
311  cout << "Warning: L3 crashed online on this event, no usefull information."
312  << endl;
313  return 0;
314  }
315 
316  // get database info
317  mDbSet = GetDataBase("RunLog/l3");
318  // if we didn't get the db use maximum values as default
319  if (mDbSet) {
320  // get number of gl3 nodes
321  TTable* l3runSummaryTable = (TTable* )mDbSet->Find("l3RunSummary");
322  // database can be there, but no tables :-(
323  if (l3runSummaryTable) {
324  l3RunSummary_st* data = (l3RunSummary_st* )l3runSummaryTable->GetArray();
325  mNumberOfGl3Nodes = data->nGl3Nodes;
326  if (Debug()) {
327  cout << "database: runNumber = " << data->runNumber << endl;
328  cout << "database: nGl3Nodes = " << data->nGl3Nodes << endl;
329  }
330  // check limit
331  if (mNumberOfGl3Nodes>MaxNumberOfGl3Nodes) {
332  cout << " ERROR: number of gl3 nodes too high: db -> " << mNumberOfGl3Nodes
333  << " max -> " << MaxNumberOfGl3Nodes << endl;
334  return 1;
335  }
336  }
337  else {
338  mNumberOfGl3Nodes = MaxNumberOfGl3Nodes;
339  cout << " no table entry for this run in 'l3RunSummary' found!" << endl;
340  cout << " using default values." << endl;
341  }
342  }
343  else {
344  mNumberOfGl3Nodes = MaxNumberOfGl3Nodes;
345  cout << " no database 'Runlog/l3' found!" << endl;
346  cout << " using default values." << endl;
347  }
348 
349  // gl3 node which built this event
350  int gl3Id = ml3reader->getGl3Id();
351 
352  // number of algorithms
353  mNumberOfAlgorithms = gl3Reader->getNumberofAlgorithms();
354 
355  // check number of algorithms and gl3 node id
356  if (mNumberOfAlgorithms >= MaxNumberOfAlgorithms) {
357  cout << "ERROR: number of algorithms exceeds limit: found "
358  << mNumberOfAlgorithms << ", limit " << MaxNumberOfAlgorithms
359  << endl;
360  return 1;
361  }
362  if (gl3Id<=0 || gl3Id>= MaxNumberOfGl3Nodes) {
363  cout << "ERROR: gl3 id exceeds limit: found "
364  << gl3Id << ", limit " << MaxNumberOfGl3Nodes
365  << endl;
366  return 1;
367  }
368 
369  //--------------------------
370  // now do the bookkeeping
371  // and fill the results
372  // directly into the db tables
373  //--------------------------
374 
375  // increase the event counter
376  mEventCounter++;
377 
378  // first: global counter
379  mGlobalCounter[gl3Id-1].nProcessed = gl3Reader->getNumberOfProcessedEvents();
380  mGlobalCounter[gl3Id-1].nReconstructed = gl3Reader->getNumberOfReconstructedEvents();
381  // second: algorithm counter
382  Algorithm_Data* algData = gl3Reader->getAlgorithmData();
383  for (int i=0; i<mNumberOfAlgorithms; i++) {
384  mAlgorithmCounter[gl3Id-1][i].algId = algData[i].algId;
385  mAlgorithmCounter[gl3Id-1][i].nProcessed = algData[i].nProcessed;
386  mAlgorithmCounter[gl3Id-1][i].nAccept = algData[i].nAccept;
387  mAlgorithmCounter[gl3Id-1][i].nBuild = algData[i].nBuild;
388  }
389 
390  // get total counters
391  // and put them into the db tables
392  l3GlobalCounter_st* totalCounter = (l3GlobalCounter_st*) mGlobalCounterTable->GetTable();
393  mAlgorithmCounterTable->SetNRows(mNumberOfAlgorithms);
394  l3AlgorithmCount_st* totalAlgCounter = (l3AlgorithmCount_st*) mAlgorithmCounterTable->GetTable();
395 
396  totalCounter->nProcessed = 0;
397  totalCounter->nReconstructed = 0;
398 
399  for (int i=0; i<mNumberOfAlgorithms; i++) {
400  totalAlgCounter[i].algId = 0;
401  totalAlgCounter[i].nProcessed = 0;
402  totalAlgCounter[i].nAccept = 0;
403  totalAlgCounter[i].nBuild = 0;
404  }
405 
406 
407  for (int i=0; i<mNumberOfGl3Nodes; i++) {
408  // if one gl3 node wasn't seen so far,
409  // the counters are still undefined
410  if (mGlobalCounter[i].nProcessed==0 && mEventCounter<(2*mNumberOfGl3Nodes)) {
411  totalCounter->nProcessed = -1;
412  totalCounter->nReconstructed = -1;
413  for (int j=0; j<mNumberOfAlgorithms; j++) {
414  totalAlgCounter[j].algId = mAlgorithmCounter[gl3Id-1][j].algId;
415  totalAlgCounter[j].nProcessed = -1;
416  totalAlgCounter[j].nAccept = -1;
417  totalAlgCounter[j].nBuild = -1;
418  }
419  break;
420  }
421  // summ-up the counters of all gl3 nodes
422  // we have seen so far after #(mNumberOfGl3Nodes*2) events
423  totalCounter->nProcessed += mGlobalCounter[i].nProcessed;
424  totalCounter->nReconstructed += mGlobalCounter[i].nReconstructed;
425  for (int k=0; k<mNumberOfAlgorithms; k++) {
426  totalAlgCounter[k].algId = mAlgorithmCounter[gl3Id-1][k].algId;
427  totalAlgCounter[k].nProcessed += mAlgorithmCounter[i][k].nProcessed;
428  totalAlgCounter[k].nAccept += mAlgorithmCounter[i][k].nAccept;
429  totalAlgCounter[k].nBuild += mAlgorithmCounter[i][k].nBuild;
430  }
431  }
432 
433  // debugging
434  if (Debug()) {
435  cout << " Global counters: nProcessed = " << totalCounter->nProcessed
436  << ", nReconstructed = " << totalCounter->nReconstructed << endl;
437  cout << " algId\tnProcessed\tnAccept\tnBuild" << endl;
438  for (int k=0; k<mNumberOfAlgorithms; k++) {
439  cout << totalAlgCounter[k].algId << "\t"
440  << totalAlgCounter[k].nProcessed << "\t"
441  << totalAlgCounter[k].nAccept << "\t"
442  << totalAlgCounter[k].nBuild << endl;
443  }
444  cout << " ------------------------------------ " << endl;
445  }
446 
447 
448  // all right go home
449  return 0 ;
450 }
451 
452 
453 
454 //____________________________________________________________________________
456 {
457 
458  if (!mStoreDbTables) return 0;
459  else WriteTable();
460 
461  return 0;
462 }
463 
464 
465 //____________________________________________________________________________
466 Int_t Stl3CounterMaker::WriteTable()
467 {
468  // write db tables into seperate files
469  // (for technical reasons)
470  char filename[80];
471 
472  // dump global counters
473  sprintf(filename,"./StarDb/RunLog_l3/l3counters_glob.%08d.%06d.C",GetDate(),GetTime());
474  TString dirname = gSystem->DirName(filename);
475 
476  if (Debug()) cout << "Stl3CounterMaker::WriteTable(): output dir: " << dirname.Data() << endl;
477 
478  if (gSystem->OpenDirectory(dirname.Data())==0) {
479  if (gSystem->mkdir(dirname.Data())) {
480  cout << "Stl3CounterMaker::WriteTable(): Directory " << dirname << " creation failed" << endl;
481  cout << "Stl3CounterMaker::WriteTable(): Putting l3counters_glob.C in current directory" << endl;
482  for (int i=0;i<80;i++) filename[i]=0;
483  sprintf(filename,"l3counters_glob.%08d.%06d.C",GetDate(),GetTime());
484  }
485  }
486  ofstream *out = new ofstream(filename);
487  mGlobalCounterTable->SavePrimitive(*out,"");
488  delete out;
489 
490  // dump algorithm counters
491  sprintf(filename,"./StarDb/RunLog_l3/l3counters_algo.%08d.%06d.C",GetDate(),GetTime());
492  dirname = gSystem->DirName(filename);
493 
494  if (Debug()) cout << "Stl3CounterMaker::WriteTable(): output dir: " << dirname.Data() << endl;
495 
496  if (gSystem->OpenDirectory(dirname.Data())==0) {
497  if (gSystem->mkdir(dirname.Data())) {
498  cout << "Stl3CounterMaker::WriteTable(): Directory " << dirname << " creation failed" << endl;
499  cout << "Stl3CounterMaker::WriteTable(): Putting l3counters_algo.C in current directory" << endl;
500  for (int i=0;i<80;i++) filename[i]=0;
501  sprintf(filename,"l3counters_algo.%08d.%06d.C",GetDate(),GetTime());
502  }
503  }
504  out = new ofstream(filename);
505  mAlgorithmCounterTable->SavePrimitive(*out,"");
506  delete out;
507 
508  return 0;
509 }
virtual Int_t Finish()
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:42
virtual Int_t Make()
Definition: TTable.h:48
Definition: Stypes.h:44
Definition: Stypes.h:41
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362