00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00055
00056
00057 #include <stdlib.h>
00058 #include <Stiostream.h>
00059 #include "Stiostream.h"
00060 #include "Stl3CounterMaker.h"
00061 #include "St_DataSetIter.h"
00062 #include "StMessMgr.h"
00063 #include "StIOMaker/StIOMaker.h"
00064 #include "StDAQMaker/StDAQReader.h"
00065 #include "StDaqLib/L3/L3_Reader.hh"
00066 #include "tables/St_l3RunSummary_Table.h"
00067 #include "tables/St_l3AlgorithmInfo_Table.h"
00068 #include "tables/St_l3AlgorithmCount_Table.h"
00069 #include "tables/St_l3GlobalCounter_Table.h"
00070 #include "Rtypes.h"
00071 #include "TSystem.h"
00072
00073 ClassImp(Stl3CounterMaker)
00074
00075
00076 Stl3CounterMaker::Stl3CounterMaker(const char *name):StMaker(name){
00077
00078 }
00079
00080
00081 Stl3CounterMaker::~Stl3CounterMaker(){
00082 }
00083
00084
00085
00086 Int_t Stl3CounterMaker::Init(){
00087
00088
00089
00090
00091
00092
00093 mL3On = kFALSE;
00094 mStoreDbTables = kTRUE;
00095
00096
00097
00098
00099 StIOMaker* IOMaker = (StIOMaker*)GetMaker("IO");
00100 if(!IOMaker) IOMaker = (StIOMaker*)GetMaker("inputStream");
00101 if (IOMaker) {
00102 IOMaker->SetNotify("OpenFile", this);
00103 IOMaker->SetNotify("CloseFile", this);
00104 }
00105 else
00106 cout << "Stl3CounterMaker::Init(): Could not SetNotify for IOMaker." << endl;
00107
00108
00109
00110 mDbSet = 0;
00111
00112
00113 mAlgorithmCounterTable = new St_l3AlgorithmCount("l3AlgorithmCount", 1);
00114 mGlobalCounterTable = new St_l3GlobalCounter("l3GlobalCounter", 1);
00115
00116
00117 l3GlobalCounter_st totalCounterRow;
00118 totalCounterRow.runNumber = 0;
00119 totalCounterRow.fileNumber = 0;
00120 totalCounterRow.nProcessed = 0;
00121 totalCounterRow.nReconstructed = 0;
00122 mGlobalCounterTable->AddAt(&totalCounterRow);
00123
00124 for (int i=0; i<MaxNumberOfAlgorithms; i++) {
00125 l3AlgorithmCount_st totalAlgCounterRow;
00126 totalAlgCounterRow.runNumber = 0;
00127 totalAlgCounterRow.algId = 0;
00128 totalAlgCounterRow.fileNumber = 0;
00129 totalAlgCounterRow.nProcessed = 0;
00130 totalAlgCounterRow.nAccept = 0;
00131 totalAlgCounterRow.nBuild = 0;
00132 mAlgorithmCounterTable->AddAt(&totalAlgCounterRow);
00133 }
00134
00135 mNumberOfGl3Nodes = 0;
00136 mNumberOfAlgorithms = 0;
00137 mEventCounter = 0;
00138
00139
00140 for (int i=0; i<MaxNumberOfGl3Nodes; i++) {
00141 mGlobalCounter[i].nProcessed = 0;
00142 mGlobalCounter[i].nReconstructed = 0;
00143 for (int j=0; j<MaxNumberOfAlgorithms; j++) {
00144 mAlgorithmCounter[i][j].algId = 0;
00145 mAlgorithmCounter[i][j].nProcessed = 0;
00146 mAlgorithmCounter[i][j].nAccept = 0;
00147 mAlgorithmCounter[i][j].nBuild = 0;
00148 }
00149 }
00150
00151
00152 return StMaker::Init();
00153 }
00154
00155
00156
00157 void Stl3CounterMaker::NotifyMe(const char *about,const void *info)
00158 {
00159
00160
00161
00162 if (strcmp("CloseFile", about)==0) {
00163 if (!mStoreDbTables) return;
00164 else WriteTable();
00165 }
00166 if (strcmp("OpenFile", about)==0) {
00167 mDaqFileName =((char*)info);
00168 InitTable();
00169 }
00170 }
00171
00172
00173
00174 Int_t Stl3CounterMaker::InitTable()
00175 {
00176
00177
00178
00179 TString seq(mDaqFileName(mDaqFileName.Index("_physics_"), 30));
00180 if (seq.Contains(".daq")) {
00181 TString fileNo = seq(21,4);
00182 TString rowNo = seq(9,7);
00183 mDaqFileSequenceNumber = atoi(fileNo.Data());
00184 mRunNumber = atoi(rowNo.Data());
00185 }
00186 else {
00187 mDaqFileSequenceNumber = 999;
00188 mRunNumber = 9999999;
00189 cout << "Stl3CounterMaker::InitTable(): Could not extract daq file run/sequence number." << endl;
00190 }
00191 if (m_DebugLevel) cout << "run number: " << mRunNumber << ", sequence number: " << mDaqFileSequenceNumber << endl;
00192
00193
00194
00195 l3GlobalCounter_st* totalCounter = (l3GlobalCounter_st*) mGlobalCounterTable->GetTable();
00196 mAlgorithmCounterTable->SetNRows(MaxNumberOfAlgorithms);
00197 l3AlgorithmCount_st* totalAlgCounter = (l3AlgorithmCount_st*) mAlgorithmCounterTable->GetTable();
00198
00199 totalCounter->runNumber = mRunNumber;
00200 totalCounter->fileNumber = mDaqFileSequenceNumber;
00201 totalCounter->nProcessed = 0;
00202 totalCounter->nReconstructed = 0;
00203
00204 for (int i=0; i<MaxNumberOfAlgorithms; i++) {
00205 totalAlgCounter[i].runNumber = mRunNumber;
00206 totalAlgCounter[i].fileNumber = mDaqFileSequenceNumber;
00207 totalAlgCounter[i].algId = 0;
00208 totalAlgCounter[i].nProcessed = 0;
00209 totalAlgCounter[i].nAccept = 0;
00210 totalAlgCounter[i].nBuild = 0;
00211 }
00212
00213
00214 for (int i=0; i<MaxNumberOfGl3Nodes; i++) {
00215 mGlobalCounter[i].nProcessed = 0;
00216 mGlobalCounter[i].nReconstructed = 0;
00217 for (int j=0; j<MaxNumberOfAlgorithms; j++) {
00218 mAlgorithmCounter[i][j].algId = 0;
00219 mAlgorithmCounter[i][j].nProcessed = 0;
00220 mAlgorithmCounter[i][j].nAccept = 0;
00221 mAlgorithmCounter[i][j].nBuild = 0;
00222 }
00223 }
00224
00225 return 0;
00226 }
00227
00228
00229
00230 Int_t Stl3CounterMaker::Make()
00231 {
00232
00233
00234
00235 cout << "Now we start l3Counter Maker. \n" ;
00236
00237
00238
00239
00240 DAQReaderSet = GetDataSet("StDAQReader");
00241 if (!DAQReaderSet) {
00242 gMessMgr->Error() << "Stl3CounterMaker::Make(): no DaqReader found!" << endm;
00243 return kStWarn;
00244 }
00245 StDAQReader *daqReader = (StDAQReader*)(DAQReaderSet->GetObject()) ;
00246 if (daqReader) {
00247 ml3reader = daqReader->getL3Reader();
00248
00249 if (ml3reader) {
00250
00251
00252 mL3On = kTRUE;
00253
00254
00255 if (m_DebugLevel) {
00256 if (ml3reader->getGlobalTrackReader())
00257 cout << ml3reader->getGlobalTrackReader()->getNumberOfTracks()
00258 << " global tracks found.\n";
00259 }
00260
00261 if (GetCounters()) {
00262 gMessMgr->Error("Stl3CounterMaker: problems getting l3 counters.");
00263 return kStErr;
00264 }
00265
00266 }
00267
00268 else {
00269
00270
00271 if (mL3On) {
00272 cout << "ERROR: L3 is ON, but no l3 data found in this event." << endl;
00273 return kStErr;
00274 }
00275
00276
00277
00278 else {
00279 cout << "WARNING: no l3 data found." << endl;
00280 return kStWarn;
00281 }
00282 }
00283
00284 }
00285
00286
00287 return kStOk;
00288 }
00289
00290
00291
00292
00293
00294 Int_t Stl3CounterMaker::GetCounters()
00295 {
00296
00297
00298 Gl3AlgorithmReader* gl3Reader = ml3reader->getGl3AlgorithmReader();
00299 if (!gl3Reader) {
00300 cout << "ERROR: L3 is ON, but L3 summary data is missing!" << endl;
00301 return 1;
00302 }
00303
00304
00305
00306
00307 if (ml3reader->getL3_Summary()->on == 0) {
00308 cout << "Warning: L3 crashed online on this event, no usefull information."
00309 << endl;
00310 return 0;
00311 }
00312
00313
00314 mDbSet = GetDataBase("RunLog/l3");
00315
00316 if (mDbSet) {
00317
00318 TTable* l3runSummaryTable = (TTable* )mDbSet->Find("l3RunSummary");
00319
00320 if (l3runSummaryTable) {
00321 l3RunSummary_st* data = (l3RunSummary_st* )l3runSummaryTable->GetArray();
00322 mNumberOfGl3Nodes = data->nGl3Nodes;
00323 if (m_DebugLevel) {
00324 cout << "database: runNumber = " << data->runNumber << endl;
00325 cout << "database: nGl3Nodes = " << data->nGl3Nodes << endl;
00326 }
00327
00328 if (mNumberOfGl3Nodes>MaxNumberOfGl3Nodes) {
00329 cout << " ERROR: number of gl3 nodes too high: db -> " << mNumberOfGl3Nodes
00330 << " max -> " << MaxNumberOfGl3Nodes << endl;
00331 return 1;
00332 }
00333 }
00334 else {
00335 mNumberOfGl3Nodes = MaxNumberOfGl3Nodes;
00336 cout << " no table entry for this run in 'l3RunSummary' found!" << endl;
00337 cout << " using default values." << endl;
00338 }
00339 }
00340 else {
00341 mNumberOfGl3Nodes = MaxNumberOfGl3Nodes;
00342 cout << " no database 'Runlog/l3' found!" << endl;
00343 cout << " using default values." << endl;
00344 }
00345
00346
00347 int gl3Id = ml3reader->getGl3Id();
00348
00349
00350 mNumberOfAlgorithms = gl3Reader->getNumberofAlgorithms();
00351
00352
00353 if (mNumberOfAlgorithms >= MaxNumberOfAlgorithms) {
00354 cout << "ERROR: number of algorithms exceeds limit: found "
00355 << mNumberOfAlgorithms << ", limit " << MaxNumberOfAlgorithms
00356 << endl;
00357 return 1;
00358 }
00359 if (gl3Id<=0 || gl3Id>= MaxNumberOfGl3Nodes) {
00360 cout << "ERROR: gl3 id exceeds limit: found "
00361 << gl3Id << ", limit " << MaxNumberOfGl3Nodes
00362 << endl;
00363 return 1;
00364 }
00365
00366
00367
00368
00369
00370
00371
00372
00373 mEventCounter++;
00374
00375
00376 mGlobalCounter[gl3Id-1].nProcessed = gl3Reader->getNumberOfProcessedEvents();
00377 mGlobalCounter[gl3Id-1].nReconstructed = gl3Reader->getNumberOfReconstructedEvents();
00378
00379 Algorithm_Data* algData = gl3Reader->getAlgorithmData();
00380 for (int i=0; i<mNumberOfAlgorithms; i++) {
00381 mAlgorithmCounter[gl3Id-1][i].algId = algData[i].algId;
00382 mAlgorithmCounter[gl3Id-1][i].nProcessed = algData[i].nProcessed;
00383 mAlgorithmCounter[gl3Id-1][i].nAccept = algData[i].nAccept;
00384 mAlgorithmCounter[gl3Id-1][i].nBuild = algData[i].nBuild;
00385 }
00386
00387
00388
00389 l3GlobalCounter_st* totalCounter = (l3GlobalCounter_st*) mGlobalCounterTable->GetTable();
00390 mAlgorithmCounterTable->SetNRows(mNumberOfAlgorithms);
00391 l3AlgorithmCount_st* totalAlgCounter = (l3AlgorithmCount_st*) mAlgorithmCounterTable->GetTable();
00392
00393 totalCounter->nProcessed = 0;
00394 totalCounter->nReconstructed = 0;
00395
00396 for (int i=0; i<mNumberOfAlgorithms; i++) {
00397 totalAlgCounter[i].algId = 0;
00398 totalAlgCounter[i].nProcessed = 0;
00399 totalAlgCounter[i].nAccept = 0;
00400 totalAlgCounter[i].nBuild = 0;
00401 }
00402
00403
00404 for (int i=0; i<mNumberOfGl3Nodes; i++) {
00405
00406
00407 if (mGlobalCounter[i].nProcessed==0 && mEventCounter<(2*mNumberOfGl3Nodes)) {
00408 totalCounter->nProcessed = -1;
00409 totalCounter->nReconstructed = -1;
00410 for (int j=0; j<mNumberOfAlgorithms; j++) {
00411 totalAlgCounter[j].algId = mAlgorithmCounter[gl3Id-1][j].algId;
00412 totalAlgCounter[j].nProcessed = -1;
00413 totalAlgCounter[j].nAccept = -1;
00414 totalAlgCounter[j].nBuild = -1;
00415 }
00416 break;
00417 }
00418
00419
00420 totalCounter->nProcessed += mGlobalCounter[i].nProcessed;
00421 totalCounter->nReconstructed += mGlobalCounter[i].nReconstructed;
00422 for (int k=0; k<mNumberOfAlgorithms; k++) {
00423 totalAlgCounter[k].algId = mAlgorithmCounter[gl3Id-1][k].algId;
00424 totalAlgCounter[k].nProcessed += mAlgorithmCounter[i][k].nProcessed;
00425 totalAlgCounter[k].nAccept += mAlgorithmCounter[i][k].nAccept;
00426 totalAlgCounter[k].nBuild += mAlgorithmCounter[i][k].nBuild;
00427 }
00428 }
00429
00430
00431 if (m_DebugLevel) {
00432 cout << " Global counters: nProcessed = " << totalCounter->nProcessed
00433 << ", nReconstructed = " << totalCounter->nReconstructed << endl;
00434 cout << " algId\tnProcessed\tnAccept\tnBuild" << endl;
00435 for (int k=0; k<mNumberOfAlgorithms; k++) {
00436 cout << totalAlgCounter[k].algId << "\t"
00437 << totalAlgCounter[k].nProcessed << "\t"
00438 << totalAlgCounter[k].nAccept << "\t"
00439 << totalAlgCounter[k].nBuild << endl;
00440 }
00441 cout << " ------------------------------------ " << endl;
00442 }
00443
00444
00445
00446 return 0 ;
00447 }
00448
00449
00450
00451
00452 Int_t Stl3CounterMaker::Finish()
00453 {
00454
00455 if (!mStoreDbTables) return 0;
00456 else WriteTable();
00457
00458 return 0;
00459 }
00460
00461
00462
00463 Int_t Stl3CounterMaker::WriteTable()
00464 {
00465
00466
00467 char filename[80];
00468
00469
00470 sprintf(filename,"./StarDb/RunLog_l3/l3counters_glob.%08d.%06d.C",GetDate(),GetTime());
00471 TString dirname = gSystem->DirName(filename);
00472
00473 if (Debug()) cout << "Stl3CounterMaker::WriteTable(): output dir: " << dirname.Data() << endl;
00474
00475 if (gSystem->OpenDirectory(dirname.Data())==0) {
00476 if (gSystem->mkdir(dirname.Data())) {
00477 cout << "Stl3CounterMaker::WriteTable(): Directory " << dirname << " creation failed" << endl;
00478 cout << "Stl3CounterMaker::WriteTable(): Putting l3counters_glob.C in current directory" << endl;
00479 for (int i=0;i<80;i++) filename[i]=0;
00480 sprintf(filename,"l3counters_glob.%08d.%06d.C",GetDate(),GetTime());
00481 }
00482 }
00483 ofstream *out = new ofstream(filename);
00484 mGlobalCounterTable->SavePrimitive(*out,"");
00485 delete out;
00486
00487
00488 sprintf(filename,"./StarDb/RunLog_l3/l3counters_algo.%08d.%06d.C",GetDate(),GetTime());
00489 dirname = gSystem->DirName(filename);
00490
00491 if (Debug()) cout << "Stl3CounterMaker::WriteTable(): output dir: " << dirname.Data() << endl;
00492
00493 if (gSystem->OpenDirectory(dirname.Data())==0) {
00494 if (gSystem->mkdir(dirname.Data())) {
00495 cout << "Stl3CounterMaker::WriteTable(): Directory " << dirname << " creation failed" << endl;
00496 cout << "Stl3CounterMaker::WriteTable(): Putting l3counters_algo.C in current directory" << endl;
00497 for (int i=0;i<80;i++) filename[i]=0;
00498 sprintf(filename,"l3counters_algo.%08d.%06d.C",GetDate(),GetTime());
00499 }
00500 }
00501 out = new ofstream(filename);
00502 mAlgorithmCounterTable->SavePrimitive(*out,"");
00503 delete out;
00504
00505 return 0;
00506 }