]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQADataMakerSteer.cxx
ACORDEv1 is now the default
[u/mrichter/AliRoot.git] / STEER / AliQADataMakerSteer.cxx
CommitLineData
312e6f8d 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/* $Id$ */
202374b1 17///////////////////////////////////////////////////////////////////////////////
18// //
19// class for running the QA makers //
20// //
21// AliQADataMakerSteer qas; //
22// qas.Run(AliQA::kRAWS, rawROOTFileName); //
23// qas.Run(AliQA::kHITS); //
24// qas.Run(AliQA::kSDIGITS); //
25// qas.Run(AliQA::kDIGITS); //
26// qas.Run(AliQA::kRECPOINTS); //
27// qas.Run(AliQA::kESDS); //
28// //
29///////////////////////////////////////////////////////////////////////////////
312e6f8d 30
4edbc5bc 31#include <TKey.h>
312e6f8d 32#include <TFile.h>
567d83d9 33#include <TFileMerger.h>
312e6f8d 34#include <TPluginManager.h>
35#include <TROOT.h>
36#include <TString.h>
37#include <TSystem.h>
38
4edbc5bc 39#include "AliCDBManager.h"
40#include "AliCDBEntry.h"
41#include "AliCDBId.h"
42#include "AliCDBMetaData.h"
940d8e5f 43#include "AliCodeTimer.h"
a2b64fbd 44#include "AliCorrQADataMakerRec.h"
0233bebf 45#include "AliDetectorRecoParam.h"
312e6f8d 46#include "AliESDEvent.h"
f451171e 47#include "AliGeomManager.h"
30bbd491 48#include "AliGlobalQADataMaker.h"
6441b07a 49#include "AliHeader.h"
312e6f8d 50#include "AliLog.h"
007fcebb 51#include "AliModule.h"
312e6f8d 52#include "AliQA.h"
04236e67 53#include "AliQADataMakerRec.h"
54#include "AliQADataMakerSim.h"
312e6f8d 55#include "AliQADataMakerSteer.h"
4ecde5fc 56#include "AliRawReaderDate.h"
57#include "AliRawReaderFile.h"
312e6f8d 58#include "AliRawReaderRoot.h"
59#include "AliRun.h"
60#include "AliRunLoader.h"
61
62ClassImp(AliQADataMakerSteer)
63
64//_____________________________________________________________________________
30bbd491 65AliQADataMakerSteer::AliQADataMakerSteer(char * mode, const char* gAliceFilename, const char * name, const char * title) :
312e6f8d 66 TNamed(name, title),
018c2b09 67 fCurrentEvent(0),
c65c502a 68 fCycleSame(kFALSE),
fff5167b 69 fDetectors("ALL"),
70 fDetectorsW("ALL"),
312e6f8d 71 fESD(NULL),
72 fESDTree(NULL),
312e6f8d 73 fGAliceFileName(gAliceFilename),
e30aef00 74 fFirstEvent(0),
30bbd491 75 fMaxEvents(0),
76 fMode(mode),
774ac967 77 fNumberOfEvents(999999),
940d8e5f 78 fRecoParam(),
30bbd491 79 fRunNumber(0),
312e6f8d 80 fRawReader(NULL),
6441b07a 81 fRawReaderDelete(kTRUE),
940d8e5f 82 fRunLoader(NULL),
a2b64fbd 83 fTasks("")
312e6f8d 84{
85 // default ctor
f0c6fb4b 86 fMaxEvents = fNumberOfEvents ;
312e6f8d 87 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4d52736b 88 if (IsSelected(AliQA::GetDetName(iDet))) {
89 fLoader[iDet] = NULL ;
90 fQADataMaker[iDet] = NULL ;
91 fQACycles[iDet] = 999999 ;
92 }
312e6f8d 93 }
94}
95
96//_____________________________________________________________________________
97AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
98 TNamed(qas),
018c2b09 99 fCurrentEvent(qas.fCurrentEvent),
c65c502a 100 fCycleSame(kFALSE),
fff5167b 101 fDetectors(qas.fDetectors),
102 fDetectorsW(qas.fDetectorsW),
312e6f8d 103 fESD(NULL),
104 fESDTree(NULL),
312e6f8d 105 fGAliceFileName(qas.fGAliceFileName),
e30aef00 106 fFirstEvent(qas.fFirstEvent),
30bbd491 107 fMaxEvents(qas.fMaxEvents),
108 fMode(qas.fMode),
312e6f8d 109 fNumberOfEvents(qas.fNumberOfEvents),
940d8e5f 110 fRecoParam(),
111 fRunNumber(qas.fRunNumber),
312e6f8d 112 fRawReader(NULL),
6441b07a 113 fRawReaderDelete(kTRUE),
940d8e5f 114 fRunLoader(NULL),
a2b64fbd 115 fTasks(qas.fTasks)
312e6f8d 116{
117 // cpy ctor
118 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
119 fLoader[iDet] = qas.fLoader[iDet] ;
120 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
121 fQACycles[iDet] = qas.fQACycles[iDet] ;
122 }
123}
124
125//_____________________________________________________________________________
126AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
127{
128 // assignment operator
129 this->~AliQADataMakerSteer() ;
130 new(this) AliQADataMakerSteer(qas) ;
131 return *this ;
132}
133
134//_____________________________________________________________________________
135AliQADataMakerSteer::~AliQADataMakerSteer()
136{
137 // dtor
57e8b77b 138 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
139 if (IsSelected(AliQA::GetDetName(iDet))) {
4d52736b 140 fLoader[iDet] = NULL;
141 if (fQADataMaker[iDet]) {
142 (fQADataMaker[iDet])->Finish() ;
fa18368b 143 delete fQADataMaker[iDet] ;
4d52736b 144 }
57e8b77b 145 }
146 }
57e8b77b 147 if (fRawReaderDelete) {
148 fRunLoader = NULL ;
149 delete fRawReader ;
150 fRawReader = NULL ;
151 }
312e6f8d 152}
153
4d52736b 154//_____________________________________________________________________________
30bbd491 155Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX_t taskIndex)
4d52736b 156{
157 // Runs all the QA data Maker for every detector
95932286 158
4d52736b 159 Bool_t rv = kFALSE ;
4d52736b 160 // Fill QA data in event loop
95932286 161 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
018c2b09 162 fCurrentEvent++ ;
4d52736b 163 // Get the event
a6f6970e 164 if ( iEvent%10 == 0 )
165 AliInfo(Form("processing event %d", iEvent));
4d52736b 166 if ( taskIndex == AliQA::kRAWS ) {
167 if ( !fRawReader->NextEvent() )
168 break ;
169 } else if ( taskIndex == AliQA::kESDS ) {
774ac967 170 if ( fESDTree->GetEntry(iEvent) == 0 )
171 break ;
4d52736b 172 } else {
774ac967 173 if ( fRunLoader->GetEvent(iEvent) != 0 )
174 break ;
4d52736b 175 }
56f4f5f4 176 // loop over active loaders
30bbd491 177 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
178 if (IsSelected(AliQA::GetDetName(iDet))) {
179 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
180 if ( qadm->IsCycleDone() ) {
181 qadm->EndOfCycle(AliQA::kRAWS) ;
182 qadm->StartOfCycle(AliQA::kRAWS) ;
183 }
c5595529 184 TTree * data = NULL ;
30bbd491 185 AliLoader* loader = GetLoader(qadm->GetUniqueID());
186 switch (taskIndex) {
940d8e5f 187 case AliQA::kNULLTASKINDEX :
188 break ;
30bbd491 189 case AliQA::kRAWS :
190 qadm->Exec(taskIndex, fRawReader) ;
191 break ;
192 case AliQA::kHITS :
c5595529 193 if( loader ) {
194 loader->LoadHits() ;
195 data = loader->TreeH() ;
196 if ( ! data ) {
197 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
198 break ;
199 }
200 }
201 qadm->Exec(taskIndex, data) ;
30bbd491 202 break ;
203 case AliQA::kSDIGITS :
c5595529 204 if( loader ) {
205 loader->LoadSDigits() ;
206 data = loader->TreeS() ;
207 if ( ! data ) {
208 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
209 break ;
210 }
211 }
212 qadm->Exec(taskIndex, data) ;
30bbd491 213 break;
214 case AliQA::kDIGITS :
c5595529 215 if( loader ) {
216 loader->LoadDigits() ;
217 data = loader->TreeD() ;
218 if ( ! data ) {
219 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
220 break ;
221 }
222 }
223 qadm->Exec(taskIndex, data) ;
30bbd491 224 break;
225 case AliQA::kRECPOINTS :
c5595529 226 if( loader ) {
227 loader->LoadRecPoints() ;
228 data = loader->TreeR() ;
229 if (!data) {
230 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
231 break ;
232 }
233 }
234 qadm->Exec(taskIndex, data) ;
235 break;
30bbd491 236 case AliQA::kTRACKSEGMENTS :
237 break;
238 case AliQA::kRECPARTICLES :
239 break;
240 case AliQA::kESDS :
241 qadm->Exec(taskIndex, fESD) ;
242 break;
243 case AliQA::kNTASKINDEX :
244 break;
245 } //task switch
246 }
4d52736b 247 } // detector loop
248 } // event loop
30bbd491 249 // Save QA data for all detectors
250 rv = Finish(taskIndex) ;
54b7165d 251
252 if ( taskIndex == AliQA::kRAWS )
253 fRawReader->RewindEvents() ;
fff5167b 254
4d52736b 255 return rv ;
256}
257
4edbc5bc 258//_____________________________________________________________________________
30bbd491 259Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX_t taskIndex)
4edbc5bc 260{
261 // write output to file for all detectors
30bbd491 262 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
263 if (IsSelected(AliQA::GetDetName(iDet))) {
264 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
265 qadm->EndOfCycle(taskIndex) ;
266 }
267 }
4edbc5bc 268 return kTRUE ;
269}
270
271//_____________________________________________________________________________
96d67a8d 272TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const
4edbc5bc 273{
274 // Retrieve the list of QA data for a given detector and a given task
f73f556a 275 TObjArray * rv = NULL ;
605cb8bb 276 if ( !strlen(AliQA::GetQARefStorage()) ) {
f73f556a 277 AliError("No storage defined, use AliQA::SetQARefStorage") ;
278 return NULL ;
279 }
4edbc5bc 280 AliCDBManager* man = AliCDBManager::Instance() ;
f73f556a 281 if ( ! man->IsDefaultStorageSet() ) {
11032e1d 282 TString tmp(AliQA::GetQARefDefaultStorage()) ;
283 tmp.Append(year) ;
284 tmp.Append("/") ;
285 man->SetDefaultStorage(tmp.Data()) ;
96d67a8d 286 man->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
f73f556a 287 }
614a7f99 288 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ;
289 AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ;
290 AliCDBEntry* entry = man->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
4edbc5bc 291 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
292 if ( listDetQAD )
f73f556a 293 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
4edbc5bc 294 return rv ;
295}
296
312e6f8d 297//_____________________________________________________________________________
298AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
299{
300 // get the loader for a detector
56f4f5f4 301
c5595529 302 if ( !fRunLoader || iDet == AliQA::kCORR)
56f4f5f4 303 return NULL ;
312e6f8d 304
305 TString detName = AliQA::GetDetName(iDet) ;
306 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
307 if (fLoader[iDet])
308 return fLoader[iDet] ;
309
310 // load the QA data maker object
311 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
312 TString loaderName = "Ali" + detName + "Loader" ;
313
314 AliLoader * loader = NULL ;
315 // first check if a plugin is defined for the quality assurance data maker
316 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
317 // if not, add a plugin for it
318 if (!pluginHandler) {
319 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
320 TString libs = gSystem->GetLibraries() ;
321 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
322 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
323 } else {
324 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
325 }
326 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
327 }
328 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
329 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
330 }
331 if (loader)
332 fLoader[iDet] = loader ;
333 return loader ;
334}
335
336//_____________________________________________________________________________
30bbd491 337AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet)
312e6f8d 338{
339 // get the quality assurance data maker for a detector
340
341 if (fQADataMaker[iDet])
342 return fQADataMaker[iDet] ;
343
344 AliQADataMaker * qadm = NULL ;
345
30bbd491 346 if (iDet == AliQA::kGLOBAL) { //Global QA
347 qadm = new AliGlobalQADataMaker();
7c37c363 348 qadm->SetName(AliQA::GetDetName(iDet));
349 qadm->SetUniqueID(iDet);
30bbd491 350 fQADataMaker[iDet] = qadm;
351 return qadm;
352 }
353
a2b64fbd 354 if (iDet == AliQA::kCORR) { //the data maker for correlations among detectors
355 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
356 qadm->SetName(AliQA::GetDetName(iDet));
357 qadm->SetUniqueID(iDet);
358 fQADataMaker[iDet] = qadm;
359 return qadm;
360 }
361
30bbd491 362 // load the QA data maker object
363 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
364 TString detName = AliQA::GetDetName(iDet) ;
365 TString tmp(fMode) ;
366 if (tmp.Contains("sim"))
367 tmp.ReplaceAll("s", "S") ;
368 else if (tmp.Contains("rec"))
369 tmp.ReplaceAll("r", "R") ;
370
371 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
372
373 // first check if a plugin is defined for the quality assurance data maker
374 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
375 // if not, add a plugin for it
376 if (!pluginHandler) {
377 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
378 TString libs = gSystem->GetLibraries() ;
379 if (libs.Contains("lib" + detName + fMode + ".so") || (gSystem->Load("lib" + detName + fMode + ".so") >= 0)) {
380 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
381 } else {
382 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
312e6f8d 383 }
30bbd491 384 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
385 }
386 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
387 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
312e6f8d 388 }
940d8e5f 389 if (qadm) {
940d8e5f 390 qadm->SetName(AliQA::GetDetName(iDet));
391 qadm->SetUniqueID(iDet);
7c37c363 392 fQADataMaker[iDet] = qadm ;
940d8e5f 393 }
394
30bbd491 395 return qadm ;
312e6f8d 396}
397
940d8e5f 398//_____________________________________________________________________________
399void AliQADataMakerSteer::EndOfCycle(TObjArray * detArray)
400{
401 // End of cycle QADataMakers
402
403 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
404 if (IsSelected(AliQA::GetDetName(iDet))) {
405 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
406 if (!qadm)
407 continue ;
408 // skip non active detectors
409 if (detArray) {
410 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
411 if (!det || !det->IsActive())
412 continue ;
413 }
414 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
415 if ( fTasks.Contains(Form("%d", taskIndex)) )
416 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
417 }
418 qadm->Finish();
419 }
420 }
421}
422
312e6f8d 423//_____________________________________________________________________________
30bbd491 424Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX_t taskIndex, const char * input )
312e6f8d 425{
426 // Initialize the event source and QA data makers
427
194bc923 428 //fTasks = AliQA::GetTaskName(taskIndex) ;
940d8e5f 429
6441b07a 430 if (taskIndex == AliQA::kRAWS) {
431 if (!fRawReader) {
e64fcb90 432 fRawReader = AliRawReader::Create(input);
4ecde5fc 433 }
940d8e5f 434 if ( ! fRawReader )
312e6f8d 435 return kFALSE ;
fff5167b 436 fRawReaderDelete = kTRUE ;
312e6f8d 437 fRawReader->NextEvent() ;
438 fRunNumber = fRawReader->GetRunNumber() ;
04236e67 439 AliCDBManager::Instance()->SetRun(fRunNumber) ;
312e6f8d 440 fRawReader->RewindEvents();
441 fNumberOfEvents = 999999 ;
f0c6fb4b 442 if ( fMaxEvents < 0 )
443 fMaxEvents = fNumberOfEvents ;
444 } else if (taskIndex == AliQA::kESDS) {
940d8e5f 445 fTasks = AliQA::GetTaskName(AliQA::kESDS) ;
ad265f3e 446 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
447 TFile * esdFile = TFile::Open("AliESDs.root") ;
448 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
04236e67 449 if ( !fESDTree ) {
450 AliError("esdTree not found") ;
451 return kFALSE ;
452 } else {
453 fESD = new AliESDEvent() ;
454 fESD->ReadFromTree(fESDTree) ;
455 fESDTree->GetEntry(0) ;
456 fRunNumber = fESD->GetRunNumber() ;
457 fNumberOfEvents = fESDTree->GetEntries() ;
f0c6fb4b 458 if ( fMaxEvents < 0 )
459 fMaxEvents = fNumberOfEvents ;
04236e67 460 }
ad265f3e 461 } else {
462 AliError("AliESDs.root not found") ;
463 return kFALSE ;
464 }
b37ee1e8 465 } else {
774ac967 466 if ( !InitRunLoader() ) {
467 AliWarning("No Run Loader not found") ;
312e6f8d 468 } else {
312e6f8d 469 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
f0c6fb4b 470 if ( fMaxEvents < 0 )
471 fMaxEvents = fNumberOfEvents ;
312e6f8d 472 }
ad265f3e 473 }
fff5167b 474
56f4f5f4 475 // Get Detectors
476 TObjArray* detArray = NULL ;
477 if (fRunLoader) // check if RunLoader exists
b37ee1e8 478 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
56f4f5f4 479 detArray = fRunLoader->GetAliRun()->Detectors() ;
b37ee1e8 480 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
481 }
30bbd491 482
483 // Initialize all QA data makers for all detectors
484 fRunNumber = AliCDBManager::Instance()->GetRun() ;
485 if ( ! AliGeomManager::GetGeometry() )
486 AliGeomManager::LoadGeometry() ;
487
dfe289e9 488 InitQADataMaker(fRunNumber, fRecoParam, fCycleSame, kTRUE, detArray) ;
940d8e5f 489 return kTRUE ;
490}
491
492//_____________________________________________________________________________
493void AliQADataMakerSteer::InitQADataMaker(UInt_t run, const AliRecoParam & par, Bool_t sameCycle, Bool_t startOption, TObjArray * detArray)
494{
495 // Initializes The QADataMaker for all active detectors and for all active tasks
496
56f4f5f4 497 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4d52736b 498 if (IsSelected(AliQA::GetDetName(iDet))) {
30bbd491 499 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
4d52736b 500 if (!qadm) {
fff5167b 501 AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
502 fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ;
4d52736b 503 } else {
fff5167b 504 AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ;
56f4f5f4 505 // skip non active detectors
506 if (detArray) {
507 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
508 if (!det || !det->IsActive())
509 continue ;
510 }
940d8e5f 511 // Set default reco params
512 qadm->SetRecoParam(par.GetDetRecoParam(iDet));
513 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
514 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
515 qadm->Init(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), run, GetQACycles(qadm->GetUniqueID())) ;
516 if (startOption) {
517 qadm->StartOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), sameCycle) ;
518 sameCycle = kTRUE ;
519 }
520 }
521 }
4d52736b 522 }
312e6f8d 523 }
940d8e5f 524 }
312e6f8d 525}
526
a2b64fbd 527
312e6f8d 528//_____________________________________________________________________________
529Bool_t AliQADataMakerSteer::InitRunLoader()
530{
531 // get or create the run loader
532 if (fRunLoader) {
c65c502a 533 fCycleSame = kTRUE ;
e4a998ed 534 } else {
535 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
536 // load all base libraries to get the loader classes
537 TString libs = gSystem->GetLibraries() ;
538 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
539 if (!IsSelected(AliQA::GetDetName(iDet)))
540 continue ;
541 TString detName = AliQA::GetDetName(iDet) ;
542 if (detName == "HLT")
543 continue;
544 if (libs.Contains("lib" + detName + "base.so"))
545 continue;
546 gSystem->Load("lib" + detName + "base.so");
547 }
548 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
549 if (!fRunLoader) {
550 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
551 return kFALSE;
552 }
553 fRunLoader->CdGAFile();
554 if (fRunLoader->LoadgAlice() == 0) {
555 gAlice = fRunLoader->GetAliRun();
556 }
557
558 if (!gAlice) {
559 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
560 return kFALSE;
561 }
4d52736b 562
e4a998ed 563 } else { // galice.root does not exist
564 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
312e6f8d 565 return kFALSE;
566 }
e4a998ed 567 }
312e6f8d 568
e4a998ed 569 if (!fRunNumber) {
570 fRunLoader->LoadHeader();
571 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
572 }
573 return kTRUE;
312e6f8d 574}
575
04236e67 576//_____________________________________________________________________________
577Bool_t AliQADataMakerSteer::IsSelected(const char * det)
578{
579 // check whether detName is contained in detectors
580 // if yes, it is removed from detectors
581
56f4f5f4 582 Bool_t rv = kFALSE;
04236e67 583 const TString detName(det) ;
a2b64fbd 584 // always activates Correlation
585 if ( detName.Contains(AliQA::GetDetName(AliQA::kCORR))) {
586 rv = kTRUE ;
587 } else {
588 // check if all detectors are selected
589 if (fDetectors.Contains("ALL")) {
590 fDetectors = "ALL";
591 rv = kTRUE;
592 } else if ((fDetectors.CompareTo(detName) == 0) ||
593 fDetectors.BeginsWith(detName+" ") ||
594 fDetectors.EndsWith(" "+detName) ||
595 fDetectors.Contains(" "+detName+" ")) {
596 rv = kTRUE;
597 }
598 }
04236e67 599 return rv ;
600}
601
312e6f8d 602//_____________________________________________________________________________
4edbc5bc 603Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
f5464b75 604{
605 // Merge data from all the cycles from all detectors in one single file per run
606 // Merge the QA results from all the data chunks in one run
607 Bool_t rv = MergeData(runNumber) ;
608 rv *= MergeResults(runNumber) ;
609 return rv ;
610}
611
612
613//_____________________________________________________________________________
614Bool_t AliQADataMakerSteer::MergeData(const Int_t runNumber) const
315bba70 615{
567d83d9 616 // Merge all the cycles from all detectors in one single file per run
614a7f99 617 TString cmd ;
f5464b75 618 if (runNumber == -1)
614a7f99 619 cmd = Form(".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
f5464b75 620 else
621 cmd = Form(".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
614a7f99 622 gROOT->ProcessLine(cmd.Data()) ;
567d83d9 623 ifstream in("tempo.txt") ;
624 const Int_t runMax = 10 ;
625 TString file[AliQA::kNDET*runMax] ;
95932286 626 Int_t run[AliQA::kNDET*runMax] = {-1} ;
567d83d9 627
628 Int_t index = 0 ;
629 while ( 1 ) {
4edbc5bc 630 in >> file[index] ;
567d83d9 631 if ( !in.good() )
632 break ;
e5dedfe2 633 AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ;
634 index++ ;
4edbc5bc 635 }
636
637 if ( index == 0 ) {
638 AliError(Form("run number %d not found", runNumber)) ;
639 return kFALSE ;
567d83d9 640 }
4edbc5bc 641
fff5167b 642 Int_t runIndex = 0 ;
643 Int_t runIndexMax = 0 ;
614a7f99 644 TString stmp(Form(".%s.", AliQA::GetQADataFileName())) ;
dbf9dc0d 645 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
567d83d9 646 TString tmp(file[ifile]) ;
647 tmp.ReplaceAll(".root", "") ;
648 TString det = tmp(0, tmp.Index(".")) ;
4edbc5bc 649 tmp.Remove(0, tmp.Index(stmp)+4) ;
567d83d9 650 TString ttmp = tmp(0, tmp.Index(".")) ;
651 Int_t newRun = ttmp.Atoi() ;
fff5167b 652 for (Int_t irun = 0; irun <= runIndexMax; irun++) {
436a9f16 653 if (newRun == run[irun])
654 break ;
567d83d9 655 run[runIndex] = newRun ;
567d83d9 656 runIndex++ ;
657 }
fff5167b 658 runIndexMax = runIndex ;
659 ttmp = tmp(tmp.Index(".")+1, tmp.Length()) ;
567d83d9 660 Int_t cycle = ttmp.Atoi() ;
fff5167b 661 AliDebug(1, Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ;
567d83d9 662 }
fff5167b 663 for (Int_t irun = 0 ; irun < runIndexMax ; irun++) {
567d83d9 664 TFileMerger merger ;
f5464b75 665 TString outFileName(Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),run[irun]));
614a7f99 666 merger.OutputFile(outFileName.Data()) ;
567d83d9 667 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
614a7f99 668 TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), run[irun])) ;
567d83d9 669 TString tmp(file[ifile]) ;
fff5167b 670 if (tmp.Contains(pattern)) {
567d83d9 671 merger.AddFile(tmp) ;
fff5167b 672 }
567d83d9 673 }
674 merger.Merge() ;
675 }
676
677 return kTRUE ;
315bba70 678}
679
f5464b75 680//_____________________________________________________________________________
681Bool_t AliQADataMakerSteer::MergeResults(const Int_t runNumber) const
682{
683 // Merge the QA result from all the data chunks in a run
684 TString cmd ;
685 cmd = Form(".! ls %s*.root > tempo.txt", AliQA::GetQADataFileName()) ;
686 gROOT->ProcessLine(cmd.Data()) ;
687 ifstream in("tempo.txt") ;
688 const Int_t chunkMax = 100 ;
689 TString fileList[chunkMax] ;
690
691 Int_t index = 0 ;
692 while ( 1 ) {
693 TString file ;
694 in >> fileList[index] ;
695 if ( !in.good() )
696 break ;
697 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
698 index++ ;
699 }
700
701 if ( index == 0 ) {
702 AliError("No QA Result File found") ;
703 return kFALSE ;
704 }
705
706 TFileMerger merger ;
707 TString outFileName(Form("Merged.%s.Result.%d.root", AliQA::GetQADataFileName(), runNumber));
708 merger.OutputFile(outFileName.Data()) ;
709 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
710 TString file = fileList[ifile] ;
711 merger.AddFile(file) ;
712 }
713 merger.Merge() ;
714
715 return kTRUE ;
716}
717
c65c502a 718//_____________________________________________________________________________
fff5167b 719void AliQADataMakerSteer::Reset(const Bool_t sameCycle)
c65c502a 720{
721 // Reset the default data members
c65c502a 722
30bbd491 723 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
724 if (IsSelected(AliQA::GetDetName(iDet))) {
725 AliQADataMaker * qadm = GetQADataMaker(iDet);
726 qadm->Reset(sameCycle);
727 }
56f4f5f4 728 }
6441b07a 729 if (fRawReaderDelete) {
730 delete fRawReader ;
731 fRawReader = NULL ;
732 }
c65c502a 733
fff5167b 734 fCycleSame = sameCycle ;
c65c502a 735 fESD = NULL ;
736 fESDTree = NULL ;
30bbd491 737 //fFirst = kTRUE ;
774ac967 738 fNumberOfEvents = 999999 ;
c65c502a 739}
740
6441b07a 741//_____________________________________________________________________________
7c002d48 742TString AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
6441b07a 743{
744 //Runs all the QA data Maker for Raws only
7c002d48 745
746 fCycleSame = sameCycle ;
747 fRawReader = rawReader ;
4d52736b 748 fDetectors = detectors ;
7c002d48 749 fDetectorsW = detectors ;
750
95932286 751 AliCDBManager* man = AliCDBManager::Instance() ;
7930d770 752
95932286 753 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
95932286 754 rawReader->NextEvent() ;
755 man->SetRun(fRawReader->GetRunNumber()) ;
756 rawReader->RewindEvents() ;
757 }
758
30bbd491 759 if ( !Init(AliQA::kRAWS) )
ea9ce23f 760 return kFALSE ;
761 fRawReaderDelete = kFALSE ;
762
30bbd491 763 DoIt(AliQA::kRAWS) ;
e5dedfe2 764 return fDetectorsW ;
04236e67 765}
766
767//_____________________________________________________________________________
7c002d48 768TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
04236e67 769{
770 //Runs all the QA data Maker for Raws only
7c002d48 771
772 fCycleSame = sameCycle ;
04236e67 773 fDetectors = detectors ;
e5dedfe2 774 fDetectorsW = detectors ;
04236e67 775
95932286 776 AliCDBManager* man = AliCDBManager::Instance() ;
95932286 777 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
778 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
779 if ( ! rl ) {
780 AliFatal("galice.root file not found in current directory") ;
781 } else {
782 rl->CdGAFile() ;
783 rl->LoadgAlice() ;
784 if ( ! rl->GetAliRun() ) {
785 AliFatal("AliRun not found in galice.root") ;
786 } else {
787 rl->LoadHeader() ;
788 man->SetRun(rl->GetHeader()->GetRun());
789 }
790 }
791 }
792
30bbd491 793 if ( !Init(AliQA::kRAWS, fileName) )
ea9ce23f 794 return kFALSE ;
795
30bbd491 796 DoIt(AliQA::kRAWS) ;
fff5167b 797 return fDetectorsW ;
6441b07a 798}
799
312e6f8d 800//_____________________________________________________________________________
7c002d48 801TString AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
312e6f8d 802{
803 // Runs all the QA data Maker for every detector
7c002d48 804
805 fCycleSame = sameCycle ;
806 fDetectors = detectors ;
807 fDetectorsW = detectors ;
808
65c771ca 809 AliCDBManager* man = AliCDBManager::Instance() ;
95932286 810 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
811 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
812 if ( ! rl ) {
813 AliFatal("galice.root file not found in current directory") ;
814 } else {
815 rl->CdGAFile() ;
816 rl->LoadgAlice() ;
817 if ( ! rl->GetAliRun() ) {
efb37e8e 818 AliInfo("AliRun not found in galice.root") ;
95932286 819 } else {
820 rl->LoadHeader() ;
821 man->SetRun(rl->GetHeader()->GetRun()) ;
822 }
823 }
824 }
825
ea9ce23f 826
940d8e5f 827 if ( taskIndex == AliQA::kNULLTASKINDEX) {
194bc923 828 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
829 if ( fTasks.Contains(Form("%d", task)) ) {
830 if ( !Init(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
831 return kFALSE ;
940d8e5f 832 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
194bc923 833 }
834 }
835 } else {
836 if ( !Init(taskIndex, fileName) )
837 return kFALSE ;
838 DoIt(taskIndex) ;
839 }
4d52736b 840
e5dedfe2 841 return fDetectorsW ;
6441b07a 842
14e1eccc 843}
4edbc5bc 844
940d8e5f 845//_____________________________________________________________________________
846void AliQADataMakerSteer::RunOneEvent(AliRawReader * rawReader)
847{
848 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
849
850 AliCodeTimerAuto("") ;
a2b64fbd 851 if (fTasks.Contains(Form("%d", AliQA::kRAWS))){
852 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
853 if (!IsSelected(AliQA::GetDetName(iDet)))
854 continue;
855 AliQADataMaker *qadm = GetQADataMaker(iDet);
856 if (!qadm)
857 continue;
858 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
940d8e5f 859 qadm->Exec(AliQA::kRAWS, rawReader) ;
a2b64fbd 860 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
940d8e5f 861 }
a2b64fbd 862 }
940d8e5f 863}
864
865//_____________________________________________________________________________
866void AliQADataMakerSteer::RunOneEvent(AliESDEvent *& esd)
867{
868 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
869
870 AliCodeTimerAuto("") ;
a2b64fbd 871 if (fTasks.Contains(Form("%d", AliQA::kESDS))) {
872 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
873 if (!IsSelected(AliQA::GetDetName(iDet)))
874 continue;
875 AliQADataMaker *qadm = GetQADataMaker(iDet);
876 if (!qadm)
877 continue;
878 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
940d8e5f 879 qadm->Exec(AliQA::kESDS, esd) ;
a2b64fbd 880 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
940d8e5f 881 }
882 }
883}
884
885//_____________________________________________________________________________
886void AliQADataMakerSteer::RunOneEventInOneDetector(Int_t det, TTree * tree)
887{
888 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
889 AliCodeTimerAuto("") ;
a2b64fbd 890 if (fTasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
891 if (!IsSelected(AliQA::GetDetName(det))) {
892 AliQADataMaker *qadm = GetQADataMaker(det);
893 if (qadm) {
894 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
895 qadm->Exec(AliQA::kRECPOINTS, tree) ;
940d8e5f 896 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
897 }
898 }
899 }
900}
901
4edbc5bc 902//_____________________________________________________________________________
11032e1d 903Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const char * year, const Int_t cycleNumber, const char * detectors) const
4edbc5bc 904{
905 // take the locasl QA data merge into a single file and save in OCDB
906 Bool_t rv = kTRUE ;
907 TString tmp(AliQA::GetQARefStorage()) ;
908 if ( tmp.IsNull() ) {
909 AliError("No storage defined, use AliQA::SetQARefStorage") ;
910 return kFALSE ;
911 }
912 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
913 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
914 return kFALSE ;
915 }
916 TString sdet(detectors) ;
917 sdet.ToUpper() ;
918 TFile * inputFile ;
919 if ( sdet.Contains("ALL") ) {
920 rv = Merge(runNumber) ;
921 if ( ! rv )
922 return kFALSE ;
614a7f99 923 TString inputFileName(Form("Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber)) ;
924 inputFile = TFile::Open(inputFileName.Data()) ;
11032e1d 925 rv = SaveIt2OCDB(runNumber, inputFile, year) ;
4edbc5bc 926 } else {
927 for (Int_t index = 0; index < AliQA::kNDET; index++) {
928 if (sdet.Contains(AliQA::GetDetName(index))) {
614a7f99 929 TString inputFileName(Form("%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber)) ;
930 inputFile = TFile::Open(inputFileName.Data()) ;
11032e1d 931 rv *= SaveIt2OCDB(runNumber, inputFile, year) ;
4edbc5bc 932 }
933 }
934 }
935 return rv ;
936}
937
938//_____________________________________________________________________________
11032e1d 939Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year) const
4edbc5bc 940{
941 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
942 Bool_t rv = kTRUE ;
943 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
944 AliCDBManager* man = AliCDBManager::Instance() ;
f73f556a 945 if ( ! man->IsDefaultStorageSet() ) {
a681ca96 946 TString tmp( AliQA::GetQARefStorage() ) ;
947 if ( tmp.Contains(AliQA::GetLabLocalOCDB()) )
948 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
949 else {
605cb8bb 950 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
951 tmp1.Append(year) ;
952 tmp1.Append("?user=alidaq") ;
953 man->SetDefaultStorage(tmp1.Data()) ;
a681ca96 954 }
f73f556a 955 }
a681ca96 956 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
04236e67 957 if(man->GetRun() < 0)
958 man->SetRun(runNumber);
959
11032e1d 960 AliCDBMetaData mdr ;
961 mdr.SetResponsible("yves schutz");
962
4edbc5bc 963 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
964 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
965 if ( detDir ) {
966 AliInfo(Form("Entering %s", detDir->GetName())) ;
614a7f99 967 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ;
968 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
4edbc5bc 969 TList * listDetQAD = new TList() ;
614a7f99 970 TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ;
11032e1d 971 mdr.SetComment("HMPID QA stuff");
4edbc5bc 972 listDetQAD->SetName(listName) ;
973 TList * taskList = detDir->GetListOfKeys() ;
974 TIter nextTask(taskList) ;
975 TKey * taskKey ;
976 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
977 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
978 AliInfo(Form("Saving %s", taskDir->GetName())) ;
f73f556a 979 TObjArray * listTaskQAD = new TObjArray(100) ;
4edbc5bc 980 listTaskQAD->SetName(taskKey->GetName()) ;
981 listDetQAD->Add(listTaskQAD) ;
982 TList * histList = taskDir->GetListOfKeys() ;
983 TIter nextHist(histList) ;
984 TKey * histKey ;
985 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
986 TObject * odata = taskDir->Get(histKey->GetName()) ;
a681ca96 987 if ( !odata ) {
988 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
989 } else {
4edbc5bc 990 AliInfo(Form("Adding %s", histKey->GetName())) ;
a681ca96 991 if ( odata->IsA()->InheritsFrom("TH1") ) {
992 AliInfo(Form("Adding %s", histKey->GetName())) ;
993 TH1 * hdata = static_cast<TH1*>(odata) ;
994 listTaskQAD->Add(hdata) ;
995 }
4edbc5bc 996 }
997 }
998 }
4edbc5bc 999 man->Put(listDetQAD, idr, &mdr) ;
1000 }
1001 }
1002 return rv ;
1003}
a6f6970e 1004
940d8e5f 1005//_____________________________________________________________________________
1006void AliQADataMakerSteer::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
1007{
1008 // Set custom reconstruction parameters for a given detector
1009 // Single set of parameters for all the events
194bc923 1010 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
940d8e5f 1011 if(!strcmp(detector, AliQA::GetDetName(iDet))) {
1012 par->SetAsDefault();
1013 fRecoParam.AddDetRecoParam(iDet,par);
1014 break;
1015 }
1016 }
1017}
1018
1019