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