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