- Three classes by MinJung Kweon AliHFEpriVtx, AliHFEsecVtx and AliHFEmcQA for primar...
[u/mrichter/AliRoot.git] / STEER / AliQAManager.cxx
CommitLineData
2e331c8b 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: AliQAManager.cxx 30894 2009-02-05 13:46:48Z schutz $ */
17///////////////////////////////////////////////////////////////////////////////
18// //
19// class for running the QA makers //
20// //
21// AliQAManager qas; //
4e25ac79 22// qas.Run(AliQAv1::kRAWS, rawROOTFileName); //
23// qas.Run(AliQAv1::kHITS); //
24// qas.Run(AliQAv1::kSDIGITS); //
25// qas.Run(AliQAv1::kDIGITS); //
26// qas.Run(AliQAv1::kRECPOINTS); //
27// qas.Run(AliQAv1::kESDS); //
2e331c8b 28// //
29///////////////////////////////////////////////////////////////////////////////
30
fec0891b 31#include <TCanvas.h>
2e331c8b 32#include <TKey.h>
33#include <TFile.h>
34#include <TFileMerger.h>
149a2367 35#include <TGrid.h>
36#include <TGridCollection.h>
37#include <TGridResult.h>
2e331c8b 38#include <TPluginManager.h>
39#include <TROOT.h>
40#include <TString.h>
41#include <TSystem.h>
42
43#include "AliCDBManager.h"
44#include "AliCDBEntry.h"
45#include "AliCDBId.h"
46#include "AliCDBMetaData.h"
47#include "AliCodeTimer.h"
48#include "AliCorrQADataMakerRec.h"
49#include "AliDetectorRecoParam.h"
50#include "AliESDEvent.h"
51#include "AliGeomManager.h"
52#include "AliGlobalQADataMaker.h"
53#include "AliHeader.h"
54#include "AliLog.h"
55#include "AliModule.h"
4e25ac79 56#include "AliQAv1.h"
2e331c8b 57#include "AliQADataMakerRec.h"
58#include "AliQADataMakerSim.h"
59#include "AliQAManager.h"
60#include "AliRawReaderDate.h"
61#include "AliRawReaderFile.h"
62#include "AliRawReaderRoot.h"
63#include "AliRun.h"
64#include "AliRunLoader.h"
65#include "AliRunTag.h"
66
67ClassImp(AliQAManager)
68AliQAManager* AliQAManager::fgQAInstance = 0x0;
69
70//_____________________________________________________________________________
71AliQAManager::AliQAManager() :
72 AliCDBManager(),
73 fCurrentEvent(0),
74 fCycleSame(kFALSE),
75 fDetectors("ALL"),
76 fDetectorsW("ALL"),
77 fESD(NULL),
78 fESDTree(NULL),
79 fGAliceFileName(""),
80 fFirstEvent(0),
81 fMaxEvents(0),
82 fMode(""),
83 fNumberOfEvents(999999),
84 fRecoParam(),
85 fRunNumber(0),
86 fRawReader(NULL),
87 fRawReaderDelete(kTRUE),
88 fRunLoader(NULL),
bc8761a0 89 fTasks(""),
fec0891b 90 fEventSpecie(AliRecoParam::kDefault),
91 fPrintImage(kTRUE)
2e331c8b 92{
93 // default ctor
94 fMaxEvents = fNumberOfEvents ;
95 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 96 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 97 fLoader[iDet] = NULL ;
98 fQADataMaker[iDet] = NULL ;
99 fQACycles[iDet] = 999999 ;
2e331c8b 100 }
101 }
75373542 102 SetWriteExpert() ;
2e331c8b 103}
104
105//_____________________________________________________________________________
eca4fa66 106AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
2e331c8b 107 AliCDBManager(),
108 fCurrentEvent(0),
109 fCycleSame(kFALSE),
110 fDetectors("ALL"),
111 fDetectorsW("ALL"),
112 fESD(NULL),
113 fESDTree(NULL),
114 fGAliceFileName(gAliceFilename),
115 fFirstEvent(0),
116 fMaxEvents(0),
117 fMode(mode),
118 fNumberOfEvents(999999),
119 fRecoParam(),
120 fRunNumber(0),
121 fRawReader(NULL),
122 fRawReaderDelete(kTRUE),
123 fRunLoader(NULL),
bc8761a0 124 fTasks(""),
fec0891b 125 fEventSpecie(AliRecoParam::kDefault),
126 fPrintImage(kTRUE)
2e331c8b 127{
128 // default ctor
129 fMaxEvents = fNumberOfEvents ;
130 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 131 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 132 fLoader[iDet] = NULL ;
133 fQADataMaker[iDet] = NULL ;
134 fQACycles[iDet] = 999999 ;
65660bf3 135 }
136 }
75373542 137 SetWriteExpert() ;
fec0891b 138 if (fMode.Contains("sim"))
139 fMode.ReplaceAll("s", "S") ;
140 else if (fMode.Contains("rec"))
141 fMode.ReplaceAll("r", "R") ;
2e331c8b 142}
143
144//_____________________________________________________________________________
145AliQAManager::AliQAManager(const AliQAManager & qas) :
146 AliCDBManager(),
147 fCurrentEvent(qas.fCurrentEvent),
148 fCycleSame(kFALSE),
149 fDetectors(qas.fDetectors),
150 fDetectorsW(qas.fDetectorsW),
151 fESD(NULL),
152 fESDTree(NULL),
153 fGAliceFileName(qas.fGAliceFileName),
154 fFirstEvent(qas.fFirstEvent),
155 fMaxEvents(qas.fMaxEvents),
156 fMode(qas.fMode),
157 fNumberOfEvents(qas.fNumberOfEvents),
158 fRecoParam(),
159 fRunNumber(qas.fRunNumber),
160 fRawReader(NULL),
161 fRawReaderDelete(kTRUE),
162 fRunLoader(NULL),
bc8761a0 163 fTasks(qas.fTasks),
fec0891b 164 fEventSpecie(qas.fEventSpecie),
165 fPrintImage(qas.fPrintImage)
166
2e331c8b 167{
168 // cpy ctor
169 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
170 fLoader[iDet] = qas.fLoader[iDet] ;
171 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
172 fQACycles[iDet] = qas.fQACycles[iDet] ;
173 fQAWriteExpert[iDet] = qas.fQAWriteExpert[iDet] ;
174 }
175}
176
177//_____________________________________________________________________________
178AliQAManager & AliQAManager::operator = (const AliQAManager & qas)
179{
180 // assignment operator
181 this->~AliQAManager() ;
182 new(this) AliQAManager(qas) ;
183 return *this ;
184}
185
186//_____________________________________________________________________________
187AliQAManager::~AliQAManager()
188{
189 // dtor
190 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 191 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 192 fLoader[iDet] = NULL;
193 if (fQADataMaker[iDet]) {
194 (fQADataMaker[iDet])->Finish() ;
195 delete fQADataMaker[iDet] ;
196 }
197 }
198 }
199 if (fRawReaderDelete) {
200 fRunLoader = NULL ;
201 delete fRawReader ;
202 fRawReader = NULL ;
203 }
fec0891b 204 TCanvas fakeCanvas ;
205 if (fPrintImage)
206 fakeCanvas.Print(Form("%s%s%d.%s]", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat()));
2e331c8b 207}
208
209//_____________________________________________________________________________
4e25ac79 210Bool_t AliQAManager::DoIt(const AliQAv1::TASKINDEX_t taskIndex)
2e331c8b 211{
212 // Runs all the QA data Maker for every detector
213
214 Bool_t rv = kFALSE ;
215 // Fill QA data in event loop
216 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
217 fCurrentEvent++ ;
218 // Get the event
219 if ( iEvent%10 == 0 )
5379c4a3 220 AliDebug(AliQAv1::GetQADebugLevel(), Form("processing event %d", iEvent));
4e25ac79 221 if ( taskIndex == AliQAv1::kRAWS ) {
2e331c8b 222 if ( !fRawReader->NextEvent() )
223 break ;
4e25ac79 224 } else if ( taskIndex == AliQAv1::kESDS ) {
2e331c8b 225 if ( fESDTree->GetEntry(iEvent) == 0 )
226 break ;
227 } else {
228 if ( fRunLoader->GetEvent(iEvent) != 0 )
229 break ;
230 }
231 // loop over active loaders
232 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 233 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 234 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
235 if (!qadm) continue; // This detector doesn't have any QA (for example, HLT)
236 if ( qadm->IsCycleDone() ) {
237 qadm->EndOfCycle(taskIndex) ;
238 }
239 TTree * data = NULL ;
240 AliLoader* loader = GetLoader(qadm->GetUniqueID());
241 switch (taskIndex) {
4e25ac79 242 case AliQAv1::kNULLTASKINDEX :
2e331c8b 243 break ;
4e25ac79 244 case AliQAv1::kRAWS :
2e331c8b 245 qadm->Exec(taskIndex, fRawReader) ;
246 break ;
4e25ac79 247 case AliQAv1::kHITS :
2e331c8b 248 if( loader ) {
249 loader->LoadHits() ;
250 data = loader->TreeH() ;
251 if ( ! data ) {
4e25ac79 252 AliWarning(Form(" Hit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 253 break ;
254 }
eca4fa66 255 qadm->Exec(taskIndex, data) ;
2e331c8b 256 }
2e331c8b 257 break ;
4e25ac79 258 case AliQAv1::kSDIGITS :
2e331c8b 259 if( loader ) {
260 loader->LoadSDigits() ;
261 data = loader->TreeS() ;
262 if ( ! data ) {
4e25ac79 263 AliWarning(Form(" SDigit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 264 break ;
265 }
eca4fa66 266 qadm->Exec(taskIndex, data) ;
2e331c8b 267 }
2e331c8b 268 break;
4e25ac79 269 case AliQAv1::kDIGITS :
fec0891b 270 if( loader ) {
271 loader->LoadDigits() ;
272 data = loader->TreeD() ;
273 if ( ! data ) {
274 AliWarning(Form(" Digit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
275 break ;
276 }
eca4fa66 277 qadm->Exec(taskIndex, data) ;
fec0891b 278 }
eca4fa66 279 break;
fec0891b 280 case AliQAv1::kDIGITSR :
281 if( loader ) {
282 loader->LoadDigits() ;
283 data = loader->TreeD() ;
284 if ( ! data ) {
285 AliWarning(Form(" Digit Tree not found for %s", AliQAv1::GetDetName(iDet))) ;
286 break ;
287 }
eca4fa66 288 qadm->Exec(taskIndex, data) ;
fec0891b 289 }
2e331c8b 290 break;
4e25ac79 291 case AliQAv1::kRECPOINTS :
2e331c8b 292 if( loader ) {
293 loader->LoadRecPoints() ;
294 data = loader->TreeR() ;
295 if (!data) {
4e25ac79 296 AliWarning(Form("RecPoints not found for %s", AliQAv1::GetDetName(iDet))) ;
2e331c8b 297 break ;
298 }
eca4fa66 299 qadm->Exec(taskIndex, data) ;
2e331c8b 300 }
2e331c8b 301 break;
4e25ac79 302 case AliQAv1::kTRACKSEGMENTS :
2e331c8b 303 break;
4e25ac79 304 case AliQAv1::kRECPARTICLES :
2e331c8b 305 break;
4e25ac79 306 case AliQAv1::kESDS :
2e331c8b 307 qadm->Exec(taskIndex, fESD) ;
308 break;
4e25ac79 309 case AliQAv1::kNTASKINDEX :
2e331c8b 310 break;
311 } //task switch
312 }
313 } // detector loop
314 Increment() ;
315 } // event loop
316 // Save QA data for all detectors
317 rv = Finish(taskIndex) ;
318
4e25ac79 319 if ( taskIndex == AliQAv1::kRAWS )
2e331c8b 320 fRawReader->RewindEvents() ;
321
322 return rv ;
323}
324
325//_____________________________________________________________________________
4e25ac79 326Bool_t AliQAManager::Finish(const AliQAv1::TASKINDEX_t taskIndex)
2e331c8b 327{
328 // write output to file for all detectors
329 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 330 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 331 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
332 if (qadm)
333 qadm->EndOfCycle(taskIndex) ;
334 }
335 }
336 return kTRUE ;
337}
338
339//_____________________________________________________________________________
fec0891b 340TObjArray * AliQAManager::GetFromOCDB(AliQAv1::DETECTORINDEX_t det, AliQAv1::TASKINDEX_t task, const Char_t * year) const
2e331c8b 341{
342 // Retrieve the list of QA data for a given detector and a given task
343 TObjArray * rv = NULL ;
4e25ac79 344 if ( !strlen(AliQAv1::GetQARefStorage()) ) {
345 AliError("No storage defined, use AliQAv1::SetQARefStorage") ;
2e331c8b 346 return NULL ;
347 }
348 if ( ! IsDefaultStorageSet() ) {
4e25ac79 349 TString tmp(AliQAv1::GetQARefDefaultStorage()) ;
2e331c8b 350 tmp.Append(year) ;
351 tmp.Append("/") ;
352 Instance()->SetDefaultStorage(tmp.Data()) ;
4e25ac79 353 Instance()->SetSpecificStorage(Form("%s/*", AliQAv1::GetQAName()), AliQAv1::GetQARefStorage()) ;
2e331c8b 354 }
4e25ac79 355 TString detOCDBDir(Form("%s/%s/%s", AliQAv1::GetQAName(), AliQAv1::GetDetName((Int_t)det), AliQAv1::GetRefOCDBDirName())) ;
5379c4a3 356 AliDebug(AliQAv1::GetQADebugLevel(), Form("Retrieving reference data from %s/%s for %s", AliQAv1::GetQARefStorage(), detOCDBDir.Data(), AliQAv1::GetTaskName(task).Data())) ;
2e331c8b 357 AliCDBEntry* entry = QAManager()->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
eca4fa66 358 TList * listDetQAD = static_cast<TList *>(entry->GetObject()) ;
2e331c8b 359 if ( listDetQAD )
eca4fa66 360 rv = static_cast<TObjArray *>(listDetQAD->FindObject(AliQAv1::GetTaskName(task))) ;
2e331c8b 361 return rv ;
362}
363
364//_____________________________________________________________________________
fec0891b 365TCanvas ** AliQAManager::GetImage(Char_t * detName)
366{
367 // retrieves QA Image for the given detector
368 TCanvas ** rv = NULL ;
369 Int_t detIndex = AliQAv1::GetDetIndex(detName) ;
370 AliQADataMaker * qadm = GetQADataMaker(detIndex) ;
371 rv = qadm->GetImage() ;
372 return rv ;
373}
374
375//_____________________________________________________________________________
2e331c8b 376AliLoader * AliQAManager::GetLoader(Int_t iDet)
377{
378 // get the loader for a detector
379
4e25ac79 380 if ( !fRunLoader || iDet == AliQAv1::kCORR)
2e331c8b 381 return NULL ;
382
4e25ac79 383 TString detName = AliQAv1::GetDetName(iDet) ;
2e331c8b 384 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
385 if (fLoader[iDet])
386 return fLoader[iDet] ;
387
388 // load the QA data maker object
389 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
390 TString loaderName = "Ali" + detName + "Loader" ;
391
392 AliLoader * loader = NULL ;
393 // first check if a plugin is defined for the quality assurance data maker
394 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
395 // if not, add a plugin for it
396 if (!pluginHandler) {
5379c4a3 397 AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", loaderName.Data())) ;
2e331c8b 398 TString libs = gSystem->GetLibraries() ;
399 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
400 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
401 } else {
402 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
403 }
404 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
405 }
406 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
407 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
408 }
409 if (loader)
410 fLoader[iDet] = loader ;
411 return loader ;
412}
413
414//_____________________________________________________________________________
4e25ac79 415AliQAv1 * AliQAManager::GetQA(UInt_t run, UInt_t evt)
2e331c8b 416{
417// retrieves the QA object stored in a file named "Run{run}.Event{evt}_1.ESD.tag.root"
fec0891b 418 Char_t * fileName = Form("Run%d.Event%d_1.ESD.tag.root", run, evt) ;
2e331c8b 419 TFile * tagFile = TFile::Open(fileName) ;
420 if ( !tagFile ) {
421 AliError(Form("File %s not found", fileName)) ;
422 return NULL ;
423 }
eca4fa66 424 TTree * tagTree = static_cast<TTree *>(tagFile->Get("T")) ;
2e331c8b 425 if ( !tagTree ) {
426 AliError(Form("Tree T not found in %s", fileName)) ;
427 tagFile->Close() ;
428 return NULL ;
429 }
430 AliRunTag * tag = new AliRunTag ;
431 tagTree->SetBranchAddress("AliTAG", &tag) ;
432 tagTree->GetEntry(evt) ;
4e25ac79 433 AliQAv1 * qa = AliQAv1::Instance(tag->GetQALength(), tag->GetQAArray(), tag->GetESLength(), tag->GetEventSpecies()) ;
2e331c8b 434 tagFile->Close() ;
435 return qa ;
436}
437
438//_____________________________________________________________________________
439AliQADataMaker * AliQAManager::GetQADataMaker(const Int_t iDet)
440{
441 // get the quality assurance data maker for a detector
442
eca4fa66 443 AliQADataMaker * qadm = fQADataMaker[iDet] ;
444
445 if (qadm) {
446
5e232cd6 447 qadm->SetEventSpecie(fEventSpecie) ;
bc8761a0 448 if ( qadm->GetRecoParam() )
eca4fa66 449 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
5e232cd6 450 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
2e331c8b 451
eca4fa66 452 } else if (iDet == AliQAv1::kGLOBAL) { //Global QA
453
454 qadm = new AliGlobalQADataMaker();
4e25ac79 455 qadm->SetName(AliQAv1::GetDetName(iDet));
2e331c8b 456 qadm->SetUniqueID(iDet);
457 fQADataMaker[iDet] = qadm;
5e232cd6 458 qadm->SetEventSpecie(fEventSpecie) ;
bc8761a0 459 if ( qadm->GetRecoParam() )
5e232cd6 460 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
461 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
2e331c8b 462
eca4fa66 463 } else if (iDet == AliQAv1::kCORR && strcmp(GetMode(), "Rec") == 0 ) { //the data maker for correlations among detectors
464 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
4e25ac79 465 qadm->SetName(AliQAv1::GetDetName(iDet));
2e331c8b 466 qadm->SetUniqueID(iDet);
eca4fa66 467 fQADataMaker[iDet] = qadm;
5e232cd6 468 qadm->SetEventSpecie(fEventSpecie) ;
bc8761a0 469 if ( qadm->GetRecoParam() )
5e232cd6 470 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
471 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
2e331c8b 472
eca4fa66 473 } else {
474
475 // load the QA data maker object
476 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
477 TString detName = AliQAv1::GetDetName(iDet) ;
478 TString qadmName = "Ali" + detName + "QADataMaker" + GetMode() ;
479
480 // first check if a plugin is defined for the quality assurance data maker
481 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
482 // if not, add a plugin for it
483 if (!pluginHandler) {
484 AliDebug(AliQAv1::GetQADebugLevel(), Form("defining plugin for %s", qadmName.Data())) ;
485 TString libs = gSystem->GetLibraries() ;
486 if (libs.Contains("lib" + detName + GetMode() + ".so") || (gSystem->Load("lib" + detName + GetMode() + ".so") >= 0)) {
487 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
488 } else {
489 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
490 }
491 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
492 }
493 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
494 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
495 }
496 if (qadm) {
497 qadm->SetName(AliQAv1::GetDetName(iDet));
498 qadm->SetUniqueID(iDet);
499 fQADataMaker[iDet] = qadm ;
500 qadm->SetEventSpecie(fEventSpecie) ;
501 if ( qadm->GetRecoParam() )
502 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
503 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
504 }
505 }
2e331c8b 506 return qadm ;
507}
508
509//_____________________________________________________________________________
510void AliQAManager::EndOfCycle(TObjArray * detArray)
511{
512 // End of cycle QADataMakers
513
fec0891b 514 if (fPrintImage) {
515 TCanvas fakeCanvas ;
516 fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())) ;
517 }
2e331c8b 518 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 519 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 520 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
521 if (!qadm)
522 continue ;
523 // skip non active detectors
524 if (detArray) {
4e25ac79 525 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQAv1::GetDetName(iDet))) ;
2e331c8b 526 if (!det || !det->IsActive())
527 continue ;
528 }
fec0891b 529 qadm->SetPrintImage(fPrintImage) ;
eca4fa66 530
4e25ac79 531 for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
2e331c8b 532 if ( fTasks.Contains(Form("%d", taskIndex)) )
4e25ac79 533 qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
2e331c8b 534 }
535 qadm->Finish();
536 }
537 }
538}
539
540//_____________________________________________________________________________
541void AliQAManager::EndOfCycle(TString detectors)
542{
543 // End of cycle QADataMakers
544
fec0891b 545 if (fPrintImage) {
546 TCanvas fakeCanvas ;
547 fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())) ;
548 }
549 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 550 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 551 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
552 if (!qadm)
553 continue ;
554 // skip non active detectors
4e25ac79 555 if (!detectors.Contains(AliQAv1::GetDetName(iDet)))
2e331c8b 556 continue ;
fec0891b 557 qadm->SetPrintImage(fPrintImage) ;
4e25ac79 558 for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
2e331c8b 559 if ( fTasks.Contains(Form("%d", taskIndex)) )
4e25ac79 560 qadm->EndOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex))) ;
2e331c8b 561 }
562 qadm->Finish();
563 }
564 }
565}
566
567//_____________________________________________________________________________
568void AliQAManager::Increment()
569{
570 // Increments the cycle counter for all QA Data Makers
571 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 572 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 573 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
574 if (qadm)
575 qadm->Increment() ;
576 }
577 }
578}
579
580//_____________________________________________________________________________
fec0891b 581Bool_t AliQAManager::InitQA(const AliQAv1::TASKINDEX_t taskIndex, const Char_t * input )
2e331c8b 582{
583 // Initialize the event source and QA data makers
584
585 fTasks += Form("%d", taskIndex) ;
586
4e25ac79 587 if (taskIndex == AliQAv1::kRAWS) {
2e331c8b 588 if (!fRawReader) {
589 fRawReader = AliRawReader::Create(input);
590 }
591 if ( ! fRawReader )
592 return kFALSE ;
593 fRawReaderDelete = kTRUE ;
594 fRawReader->NextEvent() ;
595 fRunNumber = fRawReader->GetRunNumber() ;
596 SetRun(fRunNumber) ;
597 fRawReader->RewindEvents();
598 fNumberOfEvents = 999999 ;
599 if ( fMaxEvents < 0 )
600 fMaxEvents = fNumberOfEvents ;
4e25ac79 601 } else if (taskIndex == AliQAv1::kESDS) {
602 fTasks = AliQAv1::GetTaskName(AliQAv1::kESDS) ;
2e331c8b 603 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
604 TFile * esdFile = TFile::Open("AliESDs.root") ;
eca4fa66 605 fESDTree = static_cast<TTree *> (esdFile->Get("esdTree")) ;
2e331c8b 606 if ( !fESDTree ) {
607 AliError("esdTree not found") ;
608 return kFALSE ;
609 } else {
610 fESD = new AliESDEvent() ;
611 fESD->ReadFromTree(fESDTree) ;
612 fESDTree->GetEntry(0) ;
613 fRunNumber = fESD->GetRunNumber() ;
614 fNumberOfEvents = fESDTree->GetEntries() ;
615 if ( fMaxEvents < 0 )
616 fMaxEvents = fNumberOfEvents ;
617 }
618 } else {
619 AliError("AliESDs.root not found") ;
620 return kFALSE ;
621 }
622 } else {
623 if ( !InitRunLoader() ) {
624 AliWarning("No Run Loader not found") ;
625 } else {
626 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
627 if ( fMaxEvents < 0 )
628 fMaxEvents = fNumberOfEvents ;
629 }
630 }
631
632 // Get Detectors
633 TObjArray* detArray = NULL ;
634 if (fRunLoader) // check if RunLoader exists
635 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
636 detArray = fRunLoader->GetAliRun()->Detectors() ;
637 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
638 }
639
640 // Initialize all QA data makers for all detectors
641 fRunNumber = AliCDBManager::Instance()->GetRun() ;
642 if ( ! AliGeomManager::GetGeometry() )
643 AliGeomManager::LoadGeometry() ;
644
645 InitQADataMaker(fRunNumber, detArray) ; //, fCycleSame, kTRUE, detArray) ;
fec0891b 646 if (fPrintImage) {
647 TCanvas fakeCanvas ;
648 fakeCanvas.Print(Form("%s%s%d.%s[", AliQAv1::GetImageFileName(), GetMode(), fRunNumber, AliQAv1::GetImageFileFormat())) ;
649 }
2e331c8b 650 return kTRUE ;
651}
652
653//_____________________________________________________________________________
654void AliQAManager::InitQADataMaker(UInt_t run, TObjArray * detArray)
655{
656 // Initializes The QADataMaker for all active detectors and for all active tasks
fec0891b 657 fRunNumber = run ;
2e331c8b 658 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 659 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 660 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
661 if (!qadm) {
4e25ac79 662 AliError(Form("AliQADataMaker not found for %s", AliQAv1::GetDetName(iDet))) ;
663 fDetectorsW.ReplaceAll(AliQAv1::GetDetName(iDet), "") ;
2e331c8b 664 } else {
665 if (fQAWriteExpert[iDet])
666 qadm->SetWriteExpert() ;
5379c4a3 667 AliDebug(AliQAv1::GetQADebugLevel(), Form("Data Maker found for %s %d", qadm->GetName(), qadm->WriteExpert())) ;
2e331c8b 668 // skip non active detectors
669 if (detArray) {
4e25ac79 670 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQAv1::GetDetName(iDet))) ;
2e331c8b 671 if (!det || !det->IsActive())
672 continue ;
673 }
2e331c8b 674 // Set default reco params
675 Bool_t sameCycle = kFALSE ;
4e25ac79 676 for (UInt_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
2e331c8b 677 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
4e25ac79 678 qadm->Init(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex)), GetQACycles(qadm->GetUniqueID())) ;
679 qadm->StartOfCycle(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(taskIndex)), run, sameCycle) ;
2e331c8b 680 sameCycle = kTRUE ;
681 }
682 }
683 }
684 }
685 }
686}
687
688
689//_____________________________________________________________________________
690Bool_t AliQAManager::InitRunLoader()
691{
692 // get or create the run loader
693 if (fRunLoader) {
694 fCycleSame = kTRUE ;
695 } else {
696 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
697 // load all base libraries to get the loader classes
698 TString libs = gSystem->GetLibraries() ;
699 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 700 if (!IsSelected(AliQAv1::GetDetName(iDet)))
2e331c8b 701 continue ;
4e25ac79 702 TString detName = AliQAv1::GetDetName(iDet) ;
2e331c8b 703 if (detName == "HLT")
704 continue;
705 if (libs.Contains("lib" + detName + "base.so"))
706 continue;
707 gSystem->Load("lib" + detName + "base.so");
708 }
709 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
710 if (!fRunLoader) {
711 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
712 return kFALSE;
713 }
714 fRunLoader->CdGAFile();
715 if (fRunLoader->LoadgAlice() == 0) {
716 gAlice = fRunLoader->GetAliRun();
717 }
718
719 if (!gAlice) {
720 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
721 return kFALSE;
722 }
723
724 } else { // galice.root does not exist
725 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
726 return kFALSE;
727 }
728 }
729
730 if (!fRunNumber) {
731 fRunLoader->LoadHeader();
732 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
733 }
734 return kTRUE;
735}
736
737//_____________________________________________________________________________
fec0891b 738Bool_t AliQAManager::IsSelected(const Char_t * det)
2e331c8b 739{
740 // check whether detName is contained in detectors
741 // if yes, it is removed from detectors
742
743 Bool_t rv = kFALSE;
744 const TString detName(det) ;
745 // always activates Correlation
4e25ac79 746 if ( detName.Contains(AliQAv1::GetDetName(AliQAv1::kCORR))) {
2e331c8b 747 rv = kTRUE ;
748 } else {
749 // check if all detectors are selected
750 if (fDetectors.Contains("ALL")) {
751 fDetectors = "ALL";
752 rv = kTRUE;
753 } else if ((fDetectors.CompareTo(detName) == 0) ||
754 fDetectors.BeginsWith(detName+" ") ||
755 fDetectors.EndsWith(" "+detName) ||
756 fDetectors.Contains(" "+detName+" ")) {
757 rv = kTRUE;
758 }
759 }
760 return rv ;
761}
762
763//_____________________________________________________________________________
87da0921 764Bool_t AliQAManager::Merge(Int_t runNumber, const char *fileName) const
2e331c8b 765{
bededc30 766 // Merge data from all detectors from a given run in one single file
87da0921 767 // Merge the QA results from all the data chunks in one run
768 // The 'fileName' is name of the output file with merged QA data
bededc30 769 if ( runNumber == -1)
770 runNumber = fRunNumber ;
87da0921 771 Bool_t rv = MergeData(runNumber,fileName) ;
bededc30 772 //rv *= MergeResults(runNumber) ; // not needed for the time being
2e331c8b 773 return rv ;
774}
775
149a2367 776//______________________________________________________________________
fec0891b 777Bool_t AliQAManager::MergeXML(const Char_t * collectionFile, const Char_t * subFile, const Char_t * outFile)
149a2367 778{
779 // merges files listed in a xml collection
780 // usage Merge(collection, outputFile))
781 // collection: is a xml collection
782
783 Bool_t rv = kFALSE ;
784
785 if ( strstr(collectionFile, ".xml") == 0 ) {
786 AliError("Input collection file must be an \".xml\" file\n") ;
787 return kFALSE ;
788 }
789
790 if ( !gGrid )
791 TGrid::Connect("alien://");
792 if ( !gGrid )
793 return kFALSE ;
794
795 // Open the file collection
5e232cd6 796 AliInfoClass(Form("*** Create Collection ***\n*** Wk-Dir = |%s| \n*** Coll = |%s| \n",gSystem->WorkingDirectory(), collectionFile));
149a2367 797
bededc30 798 TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\")",collectionFile));
149a2367 799 TGridResult* result = collection->GetGridResult("", 0, 0);
800
801 Int_t index = 0 ;
fec0891b 802 const Char_t * turl ;
adae62c9 803 TFileMerger merger(kFALSE) ;
149a2367 804 if (!outFile) {
805 TString tempo(collectionFile) ;
806 if ( subFile)
807 tempo.ReplaceAll(".xml", subFile) ;
808 else
809 tempo.ReplaceAll(".xml", "_Merged.root") ;
810 outFile = tempo.Data() ;
811 }
812 merger.OutputFile(outFile) ;
813
814 while ( (turl = result->GetKey(index, "turl")) ) {
fec0891b 815 Char_t * file ;
149a2367 816 if ( subFile )
817 file = Form("%s#%s", turl, subFile) ;
818 else
819 file = Form("%s", turl) ;
820
5379c4a3 821 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s\n", file)) ;
149a2367 822 merger.AddFile(file) ;
823 index++ ;
824 }
825
826 if (index)
827 merger.Merge() ;
828
5379c4a3 829 AliDebug(AliQAv1::GetQADebugLevel(), Form("Files merged into %s\n", outFile)) ;
149a2367 830
831 rv = kFALSE;
832 return rv ;
833}
834
2e331c8b 835//_____________________________________________________________________________
69a898e3 836void AliQAManager::MergeCustom() const
837{
838 // Custom Merge of QA data from all detectors for all runs in one single file
839 // search all the run numbers
840 // search all the run numbers
841 gROOT->ProcessLine(".! ls *QA*.root > QAtempo.txt") ;
842 TString QAfile ;
843 FILE * QAfiles = fopen("QAtempo.txt", "r") ;
844 Int_t index = 0 ;
845 TList srunList ;
846 TIter nextRun(&srunList) ;
847 TObjString * srun = NULL ;
848 Int_t loRun = 999999999 ;
849 Int_t hiRun = 0 ;
850 while ( QAfile.Gets(QAfiles) ) {
851 Bool_t runExist = kFALSE ;
852 TString srunNew(QAfile(QAfile.Index("QA.")+3, QAfile.Index(".root")-(QAfile.Index("QA.")+3))) ;
853 Int_t cuRun = srunNew.Atoi() ;
854 if (cuRun < loRun)
855 loRun = cuRun ;
856 if (cuRun > hiRun)
857 hiRun = cuRun ;
eca4fa66 858 while ( (srun = static_cast<TObjString *> (nextRun())) ) {
69a898e3 859 if ( cuRun == (srun->String()).Atoi() ) {
860 runExist = kTRUE ;
861 break ;
862 }
863 }
864 nextRun.Reset() ;
865 if ( ! runExist )
866 srunList.Add(new TObjString(srunNew.Data()));
867 }
868 nextRun.Reset() ;
869 Int_t runNumber = 0 ;
4e25ac79 870 TFile mergedFile(Form("Merged.%s.Data.root", AliQAv1::GetQADataFileName()), "RECREATE") ;
69a898e3 871 TH1I * hisRun = new TH1I("hLMR", "List of merged runs", hiRun-loRun+10, loRun, hiRun+10) ;
872 // create the structure into the merged file
4e25ac79 873 for (Int_t iDet = 0; iDet < AliQAv1::kNDET ; iDet++) {
874 TDirectory * detDir = mergedFile.mkdir(AliQAv1::GetDetName(iDet)) ;
875 for (Int_t taskIndex = 0; taskIndex < AliQAv1::kNTASKINDEX; taskIndex++) {
69a898e3 876 detDir->cd() ;
4e25ac79 877 TDirectory * taskDir = gDirectory->mkdir(AliQAv1::GetTaskName(taskIndex)) ;
69a898e3 878 for (Int_t es = 0 ; es < AliRecoParam::kNSpecies ; es++) {
879 taskDir->cd() ;
880 TDirectory * esDir = gDirectory->mkdir(AliRecoParam::GetEventSpecieName(es)) ;
881 esDir->cd() ;
4e25ac79 882 gDirectory->mkdir(AliQAv1::GetExpert()) ;
69a898e3 883 }
884 }
885 }
eca4fa66 886 while ( (srun = static_cast<TObjString *> (nextRun())) ) {
69a898e3 887 runNumber = (srun->String()).Atoi() ;
888 hisRun->Fill(runNumber) ;
5379c4a3 889 AliDebug(AliQAv1::GetQADebugLevel(), Form("Merging run number %d", runNumber)) ;
69a898e3 890 // search all QA files for runNumber in the current directory
fec0891b 891 Char_t * fileList[AliQAv1::kNDET] ;
69a898e3 892 index = 0 ;
4e25ac79 893 for (Int_t iDet = 0; iDet < AliQAv1::kNDET ; iDet++) {
fec0891b 894 Char_t * file = gSystem->Which(gSystem->WorkingDirectory(), Form("%s.%s.%d.root", AliQAv1::GetDetName(iDet), AliQAv1::GetQADataFileName(), runNumber));
69a898e3 895 if (file)
896 fileList[index++] = file ;
897 }
898 if ( index == 0 ) {
899 AliError("No QA data file found\n") ;
900 return ;
901 }
902 for ( Int_t i = 0 ; i < index ; i++) {
903 TFile * inFile = TFile::Open(fileList[i]) ;
904 TList * listOfKeys =inFile->GetListOfKeys() ;
905 TIter nextkey(listOfKeys) ;
906 TObject * obj1 ;
907 TString dirName("") ;
908 while ( (obj1 = nextkey()) ) {
909 TDirectory * directoryDet = inFile->GetDirectory(obj1->GetName()) ;
910 if ( directoryDet ) {
5379c4a3 911 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s dir = %s", inFile->GetName(), directoryDet->GetName())) ;
69a898e3 912 dirName += Form("%s/", directoryDet->GetName() ) ;
913 directoryDet->cd() ;
914 TList * listOfTasks = directoryDet->GetListOfKeys() ;
915 TIter nextTask(listOfTasks) ;
916 TObject * obj2 ;
917 while ( (obj2 = nextTask()) ) {
918 TDirectory * directoryTask = directoryDet->GetDirectory(obj2->GetName()) ;
919 if ( directoryTask ) {
920 dirName += Form("%s", obj2->GetName()) ;
5379c4a3 921 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s", dirName.Data())) ;
69a898e3 922 directoryTask->cd() ;
923 TList * listOfEventSpecie = directoryTask->GetListOfKeys() ;
924 TIter nextEventSpecie(listOfEventSpecie) ;
925 TObject * obj3 ;
926 while ( (obj3 = nextEventSpecie()) ) {
927 TDirectory * directoryEventSpecie = directoryTask->GetDirectory(obj3->GetName()) ;
928 if ( directoryEventSpecie ) {
929 dirName += Form("/%s/", obj3->GetName()) ;
5379c4a3 930 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s\n", dirName.Data())) ;
69a898e3 931 directoryEventSpecie->cd() ;
932 // histograms are here
933 TDirectory * mergedDirectory = mergedFile.GetDirectory(dirName.Data()) ;
934 TList * listOfData = directoryEventSpecie->GetListOfKeys() ;
935 TIter nextData(listOfData) ;
936 TKey * key ;
eca4fa66 937 while ( (key = static_cast<TKey *>(nextData())) ) {
69a898e3 938 TString className(key->GetClassName()) ;
939 if ( className.Contains("TH") || className.Contains("TProfile") ) {
eca4fa66 940 TH1 * histIn = static_cast<TH1*> (key->ReadObj()) ;
941 TH1 * histOu = static_cast<TH1*> (mergedDirectory->FindObjectAny(histIn->GetName())) ;
5379c4a3 942 AliDebug(AliQAv1::GetQADebugLevel(), Form("%s %x %x\n", key->GetName(), histIn, histOu)) ;
69a898e3 943 mergedDirectory->cd() ;
944 if ( ! histOu ) {
945 histIn->Write() ;
946 } else {
947 histOu->Add(histIn) ;
948 histOu->Write(histOu->GetName(), kOverwrite) ;
949 }
950 }
951 else if ( className.Contains("TDirectoryFile") ) {
952 TDirectory * dirExpert = directoryEventSpecie->GetDirectory(key->GetName()) ;
953 dirExpert->cd() ;
954 TDirectory * mergedDirectoryExpert = mergedDirectory->GetDirectory(dirExpert->GetName()) ;
955 TList * listOfExpertData = dirExpert->GetListOfKeys() ;
956 TIter nextExpertData(listOfExpertData) ;
957 TKey * keykey ;
eca4fa66 958 while ( (keykey = static_cast<TKey *>(nextExpertData())) ) {
69a898e3 959 TString classNameExpert(keykey->GetClassName()) ;
960 if (classNameExpert.Contains("TH")) {
eca4fa66 961 TH1 * histInExpert = static_cast<TH1*> (keykey->ReadObj()) ;
962 TH1 * histOuExpert = static_cast<TH1*> (mergedDirectory->FindObjectAny(histInExpert->GetName())) ;
69a898e3 963 mergedDirectoryExpert->cd() ;
964 if ( ! histOuExpert ) {
965 histInExpert->Write() ;
966 } else {
967 histOuExpert->Add(histInExpert) ;
968 histOuExpert->Write(histOuExpert->GetName(), kOverwrite) ;
969 }
970 }
971 }
972 } else {
973 AliError(Form("No merge done for this object %s in %s", key->GetName(), dirName.Data())) ;
974 }
975 }
976 dirName.ReplaceAll(Form("/%s/",obj3->GetName()), "") ;
977 }
978 }
979 dirName.ReplaceAll(obj2->GetName(), "") ;
980 }
981 }
982 }
983 }
984 inFile->Close() ;
985 }
986 }
987 mergedFile.cd() ;
988 hisRun->Write() ;
989 mergedFile.Close() ;
990 srunList.Delete() ;
991}
992
993//_____________________________________________________________________________
87da0921 994Bool_t AliQAManager::MergeData(const Int_t runNumber, const char *fileName) const
2e331c8b 995{
bededc30 996 // Merge QA data from all detectors for a given run in one single file
997
87da0921 998 TFileMerger merger(kFALSE) ;
999 TString outFileName = fileName;
1000 if (outFileName.IsNull()) outFileName.Form("Merged.%s.Data.root",AliQAv1::GetQADataFileName());
2e331c8b 1001 merger.OutputFile(outFileName.Data()) ;
bededc30 1002 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
fec0891b 1003 Char_t * file = gSystem->Which(gSystem->WorkingDirectory(), Form("%s.%s.%d.root", AliQAv1::GetDetName(iDet), AliQAv1::GetQADataFileName(), runNumber));
bededc30 1004 if (file)
1005 merger.AddFile(file) ;
1006 }
2e331c8b 1007 merger.Merge() ;
1008 return kTRUE ;
1009}
1010
1011//_____________________________________________________________________________
1012Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
1013{
1014 // Merge the QA result from all the data chunks in a run
bededc30 1015 // to be revised whwn it will be used (see MergeData)
2e331c8b 1016 TString cmd ;
4e25ac79 1017 cmd = Form(".! ls %s*.root > tempo.txt", AliQAv1::GetQADataFileName()) ;
2e331c8b 1018 gROOT->ProcessLine(cmd.Data()) ;
1019 ifstream in("tempo.txt") ;
1020 const Int_t chunkMax = 100 ;
1021 TString fileList[chunkMax] ;
1022
1023 Int_t index = 0 ;
1024 while ( 1 ) {
1025 TString file ;
1026 in >> fileList[index] ;
1027 if ( !in.good() )
1028 break ;
5379c4a3 1029 AliDebug(AliQAv1::GetQADebugLevel(), Form("index = %d file = %s", index, (fileList[index].Data()))) ;
2e331c8b 1030 index++ ;
1031 }
1032
1033 if ( index == 0 ) {
1034 AliError("No QA Result File found") ;
1035 return kFALSE ;
1036 }
1037
1038 TFileMerger merger ;
fc07289e 1039 TString outFileName ;
1040 if (runNumber != -1)
4e25ac79 1041 outFileName = Form("Merged.%s.Result.%d.root",AliQAv1::GetQADataFileName(),runNumber);
fc07289e 1042 else
4e25ac79 1043 outFileName = Form("Merged.%s.Result.root",AliQAv1::GetQADataFileName());
2e331c8b 1044 merger.OutputFile(outFileName.Data()) ;
1045 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
1046 TString file = fileList[ifile] ;
1047 merger.AddFile(file) ;
1048 }
1049 merger.Merge() ;
1050
1051 return kTRUE ;
1052}
1053
1054//_____________________________________________________________________________
1055void AliQAManager::Reset(const Bool_t sameCycle)
1056{
1057 // Reset the default data members
1058
1059 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
4e25ac79 1060 if (IsSelected(AliQAv1::GetDetName(iDet))) {
2e331c8b 1061 AliQADataMaker * qadm = GetQADataMaker(iDet);
1062 qadm->Reset();
1063 }
1064 }
1065 if (fRawReaderDelete) {
1066 delete fRawReader ;
1067 fRawReader = NULL ;
1068 }
1069
1070 fCycleSame = sameCycle ;
1071 fESD = NULL ;
1072 fESDTree = NULL ;
1073 //fFirst = kTRUE ;
1074 fNumberOfEvents = 999999 ;
1075}
1076
1077//_____________________________________________________________________________
eca4fa66 1078AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
2e331c8b 1079{
1080 // returns AliQAManager instance (singleton)
1081
1082 if (!fgQAInstance) {
fec0891b 1083 if ( (strcmp(mode, "sim") != 0) && (strcmp(mode, "rec") != 0) )
1084 AliFatalClass("You must specify sim or rec") ;
2e331c8b 1085 fgQAInstance = new AliQAManager(mode) ;
1086 if (!entryCache)
1087 fgQAInstance->Init();
1088 else
1089 fgQAInstance->InitFromCache(entryCache,run);
1090 }
1091 return fgQAInstance;
1092}
1093
1094//_____________________________________________________________________________
fec0891b 1095TString AliQAManager::Run(const Char_t * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
2e331c8b 1096{
1097 //Runs all the QA data Maker for Raws only
1098
1099 fCycleSame = sameCycle ;
1100 fRawReader = rawReader ;
1101 fDetectors = detectors ;
1102 fDetectorsW = detectors ;
1103
1104 AliCDBManager* man = AliCDBManager::Instance() ;
1105
1106 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
1107 rawReader->NextEvent() ;
1108 man->SetRun(fRawReader->GetRunNumber()) ;
1109 rawReader->RewindEvents() ;
1110 }
1111
1112 if (!fCycleSame)
4e25ac79 1113 if ( !InitQA(AliQAv1::kRAWS) )
2e331c8b 1114 return kFALSE ;
1115 fRawReaderDelete = kFALSE ;
1116
4e25ac79 1117 DoIt(AliQAv1::kRAWS) ;
2e331c8b 1118 return fDetectorsW ;
1119}
1120
1121//_____________________________________________________________________________
fec0891b 1122TString AliQAManager::Run(const Char_t * detectors, const Char_t * fileName, const Bool_t sameCycle)
2e331c8b 1123{
1124 //Runs all the QA data Maker for Raws only
1125
1126 fCycleSame = sameCycle ;
1127 fDetectors = detectors ;
1128 fDetectorsW = detectors ;
1129
1130 AliCDBManager* man = AliCDBManager::Instance() ;
1131 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
1132 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
1133 if ( ! rl ) {
1134 AliFatal("galice.root file not found in current directory") ;
1135 } else {
1136 rl->CdGAFile() ;
1137 rl->LoadgAlice() ;
1138 if ( ! rl->GetAliRun() ) {
1139 AliFatal("AliRun not found in galice.root") ;
1140 } else {
1141 rl->LoadHeader() ;
1142 man->SetRun(rl->GetHeader()->GetRun());
1143 }
1144 }
1145 }
1146
1147 if (!fCycleSame)
4e25ac79 1148 if ( !InitQA(AliQAv1::kRAWS, fileName) )
2e331c8b 1149 return kFALSE ;
1150
4e25ac79 1151 DoIt(AliQAv1::kRAWS) ;
2e331c8b 1152 return fDetectorsW ;
1153}
1154
1155//_____________________________________________________________________________
fec0891b 1156TString AliQAManager::Run(const Char_t * detectors, const AliQAv1::TASKINDEX_t taskIndex, Bool_t const sameCycle, const Char_t * fileName )
2e331c8b 1157{
1158 // Runs all the QA data Maker for every detector
1159
1160 fCycleSame = sameCycle ;
1161 fDetectors = detectors ;
1162 fDetectorsW = detectors ;
1163
1164 AliCDBManager* man = AliCDBManager::Instance() ;
1165 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
1166 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
1167 if ( ! rl ) {
1168 AliFatal("galice.root file not found in current directory") ;
1169 } else {
1170 rl->CdGAFile() ;
1171 rl->LoadgAlice() ;
1172 if ( ! rl->GetAliRun() ) {
5379c4a3 1173 AliDebug(AliQAv1::GetQADebugLevel(), "AliRun not found in galice.root") ;
2e331c8b 1174 } else {
1175 rl->LoadHeader() ;
1176 man->SetRun(rl->GetHeader()->GetRun()) ;
1177 }
1178 }
1179 }
fec0891b 1180 if ( taskIndex == AliQAv1::kNULLTASKINDEX) {
4e25ac79 1181 for (UInt_t task = 0; task < AliQAv1::kNTASKINDEX; task++) {
2e331c8b 1182 if ( fTasks.Contains(Form("%d", task)) ) {
1183 if (!fCycleSame)
4e25ac79 1184 if ( !InitQA(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(task)), fileName) )
2e331c8b 1185 return kFALSE ;
4e25ac79 1186 DoIt(AliQAv1::GetTaskIndex(AliQAv1::GetTaskName(task))) ;
2e331c8b 1187 }
1188 }
1189 } else {
1190 if (! fCycleSame )
1191 if ( !InitQA(taskIndex, fileName) )
1192 return kFALSE ;
1193 DoIt(taskIndex) ;
1194 }
2e331c8b 1195 return fDetectorsW ;
2e331c8b 1196}
1197
1198//_____________________________________________________________________________
1199void AliQAManager::RunOneEvent(AliRawReader * rawReader)
1200{
1201 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
1202 if ( ! rawReader )
1203 return ;
1204 AliCodeTimerAuto("") ;
4e25ac79 1205 if (fTasks.Contains(Form("%d", AliQAv1::kRAWS))){
2e331c8b 1206 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 1207 if (!IsSelected(AliQAv1::GetDetName(iDet)))
2e331c8b 1208 continue;
1209 AliQADataMaker *qadm = GetQADataMaker(iDet);
1210 if (!qadm)
1211 continue;
1212 if ( qadm->IsCycleDone() ) {
1213 qadm->EndOfCycle() ;
1214 }
4e25ac79 1215 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
5e232cd6 1216 qadm->SetEventSpecie(fEventSpecie) ;
13a2370e 1217 if ( qadm->GetRecoParam() )
5e232cd6 1218 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
1219 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
4e25ac79 1220 qadm->Exec(AliQAv1::kRAWS, rawReader) ;
1221 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
2e331c8b 1222 }
1223 }
1224}
1225
1226//_____________________________________________________________________________
1227void AliQAManager::RunOneEvent(AliESDEvent *& esd)
1228{
1229 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
1230
1231 AliCodeTimerAuto("") ;
4e25ac79 1232 if (fTasks.Contains(Form("%d", AliQAv1::kESDS))) {
2e331c8b 1233 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 1234 if (!IsSelected(AliQAv1::GetDetName(iDet)))
2e331c8b 1235 continue;
1236 AliQADataMaker *qadm = GetQADataMaker(iDet);
1237 if (!qadm)
1238 continue;
5e232cd6 1239 qadm->SetEventSpecie(fEventSpecie) ;
82a30871 1240 if ( qadm->GetRecoParam() )
5e232cd6 1241 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
1242 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
2e331c8b 1243 if ( qadm->IsCycleDone() ) {
1244 qadm->EndOfCycle() ;
1245 }
4e25ac79 1246 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
1247 qadm->Exec(AliQAv1::kESDS, esd) ;
1248 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQAv1::GetDetName(iDet)));
2e331c8b 1249 }
1250 }
1251}
1252
1253//_____________________________________________________________________________
1254void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
1255{
1256 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
44ed7a66 1257
1258 TString test(tree->GetName()) ;
2e331c8b 1259 AliCodeTimerAuto("") ;
4e25ac79 1260 if (fTasks.Contains(Form("%d", AliQAv1::kRECPOINTS))) {
1261 if (IsSelected(AliQAv1::GetDetName(det))) {
2e331c8b 1262 AliQADataMaker *qadm = GetQADataMaker(det);
1263 if (qadm) {
5e232cd6 1264 qadm->SetEventSpecie(fEventSpecie) ;
82a30871 1265 if ( qadm->GetRecoParam() )
5e232cd6 1266 if ( AliRecoParam::Convert(qadm->GetRecoParam()->GetEventSpecie()) != AliRecoParam::kDefault)
1267 qadm->SetEventSpecie(qadm->GetRecoParam()->GetEventSpecie()) ;
2e331c8b 1268 if ( qadm->IsCycleDone() ) {
1269 qadm->EndOfCycle() ;
1270 }
4e25ac79 1271 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQAv1::GetDetName(det)));
44ed7a66 1272 if (test.Contains("TreeD")) {
1273 qadm->Exec(AliQAv1::kDIGITSR, tree) ;
44ed7a66 1274 } else if (test.Contains("TreeR")) {
1275 qadm->Exec(AliQAv1::kRECPOINTS, tree) ;
1276 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQAv1::GetDetName(det)));
1277 }
2e331c8b 1278 }
1279 }
1280 }
1281}
1282
1283//_____________________________________________________________________________
fec0891b 1284Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const Char_t * year, const Char_t * detectors) const
2e331c8b 1285{
1286 // take the locasl QA data merge into a single file and save in OCDB
1287 Bool_t rv = kTRUE ;
4e25ac79 1288 TString tmp(AliQAv1::GetQARefStorage()) ;
2e331c8b 1289 if ( tmp.IsNull() ) {
4e25ac79 1290 AliError("No storage defined, use AliQAv1::SetQARefStorage") ;
2e331c8b 1291 return kFALSE ;
1292 }
4e25ac79 1293 if ( !(tmp.Contains(AliQAv1::GetLabLocalOCDB()) || tmp.Contains(AliQAv1::GetLabAliEnOCDB())) ) {
1294 AliError(Form("%s is a wrong storage, use %s or %s", AliQAv1::GetQARefStorage(), AliQAv1::GetLabLocalOCDB().Data(), AliQAv1::GetLabAliEnOCDB().Data())) ;
2e331c8b 1295 return kFALSE ;
1296 }
1297 TString sdet(detectors) ;
1298 sdet.ToUpper() ;
1299 TFile * inputFile ;
1300 if ( sdet.Contains("ALL") ) {
1301 rv = Merge(runNumber) ;
1302 if ( ! rv )
1303 return kFALSE ;
4e25ac79 1304 TString inputFileName(Form("Merged.%s.Data.%d.root", AliQAv1::GetQADataFileName(), runNumber)) ;
2e331c8b 1305 inputFile = TFile::Open(inputFileName.Data()) ;
1306 rv = SaveIt2OCDB(runNumber, inputFile, year, es) ;
1307 } else {
4e25ac79 1308 for (Int_t index = 0; index < AliQAv1::kNDET; index++) {
1309 if (sdet.Contains(AliQAv1::GetDetName(index))) {
1310 TString inputFileName(Form("%s.%s.%d.root", AliQAv1::GetDetName(index), AliQAv1::GetQADataFileName(), runNumber)) ;
2e331c8b 1311 inputFile = TFile::Open(inputFileName.Data()) ;
1312 rv *= SaveIt2OCDB(runNumber, inputFile, year, es) ;
1313 }
1314 }
1315 }
1316 return rv ;
1317}
1318
1319//_____________________________________________________________________________
fec0891b 1320Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const Char_t * year, AliRecoParam::EventSpecie_t es) const
2e331c8b 1321{
1322 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
1323 Bool_t rv = kTRUE ;
5379c4a3 1324 AliDebug(AliQAv1::GetQADebugLevel(), Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQAv1::GetQARefStorage())) ;
2e331c8b 1325 if ( ! IsDefaultStorageSet() ) {
4e25ac79 1326 TString tmp( AliQAv1::GetQARefStorage() ) ;
1327 if ( tmp.Contains(AliQAv1::GetLabLocalOCDB()) )
1328 Instance()->SetDefaultStorage(AliQAv1::GetQARefStorage()) ;
2e331c8b 1329 else {
4e25ac79 1330 TString tmp1(AliQAv1::GetQARefDefaultStorage()) ;
2e331c8b 1331 tmp1.Append(year) ;
1332 tmp1.Append("?user=alidaq") ;
1333 Instance()->SetDefaultStorage(tmp1.Data()) ;
1334 }
1335 }
4e25ac79 1336 Instance()->SetSpecificStorage("*", AliQAv1::GetQARefStorage()) ;
2e331c8b 1337 if(GetRun() < 0)
1338 Instance()->SetRun(runNumber);
1339
1340 AliCDBMetaData mdr ;
1341 mdr.SetResponsible("yves schutz");
1342
4e25ac79 1343 for ( Int_t detIndex = 0 ; detIndex < AliQAv1::kNDET ; detIndex++) {
1344 TDirectory * detDir = inputFile->GetDirectory(AliQAv1::GetDetName(detIndex)) ;
2e331c8b 1345 if ( detDir ) {
5379c4a3 1346 AliDebug(AliQAv1::GetQADebugLevel(), Form("Entering %s", detDir->GetName())) ;
4e25ac79 1347 AliQAv1::SetQARefDataDirName(es) ;
1348 TString detOCDBDir(Form("%s/%s/%s", AliQAv1::GetDetName(detIndex), AliQAv1::GetRefOCDBDirName(), AliQAv1::GetRefDataDirName())) ;
2e331c8b 1349 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
1350 TList * listDetQAD = new TList() ;
4e25ac79 1351 TString listName(Form("%s QA data Reference", AliQAv1::GetDetName(detIndex))) ;
1352 mdr.SetComment(Form("%s QA stuff", AliQAv1::GetDetName(detIndex)));
2e331c8b 1353 listDetQAD->SetName(listName) ;
1354 TList * taskList = detDir->GetListOfKeys() ;
1355 TIter nextTask(taskList) ;
1356 TKey * taskKey ;
eca4fa66 1357 while ( (taskKey = static_cast<TKey*>(nextTask())) ) {
2e331c8b 1358 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
1359 TDirectory * esDir = taskDir->GetDirectory(AliRecoParam::GetEventSpecieName(es)) ;
5379c4a3 1360 AliDebug(AliQAv1::GetQADebugLevel(), Form("Saving %s", esDir->GetName())) ;
2e331c8b 1361 TObjArray * listTaskQAD = new TObjArray(100) ;
1362 listTaskQAD->SetName(Form("%s/%s", taskKey->GetName(), AliRecoParam::GetEventSpecieName(es))) ;
1363 listDetQAD->Add(listTaskQAD) ;
1364 TList * histList = esDir->GetListOfKeys() ;
1365 TIter nextHist(histList) ;
1366 TKey * histKey ;
eca4fa66 1367 while ( (histKey = static_cast<TKey*>(nextHist())) ) {
2e331c8b 1368 TObject * odata = esDir->Get(histKey->GetName()) ;
1369 if ( !odata ) {
1370 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1371 } else {
4e25ac79 1372 if ( AliQAv1::GetExpert() == histKey->GetName() ) {
2e331c8b 1373 TDirectory * expertDir = esDir->GetDirectory(histKey->GetName()) ;
1374 TList * expertHistList = expertDir->GetListOfKeys() ;
1375 TIter nextExpertHist(expertHistList) ;
1376 TKey * expertHistKey ;
eca4fa66 1377 while ( (expertHistKey = static_cast<TKey*>(nextExpertHist())) ) {
2e331c8b 1378 TObject * expertOdata = expertDir->Get(expertHistKey->GetName()) ;
1379 if ( !expertOdata ) {
1380 AliError(Form("%s in %s/%s/Expert returns a NULL pointer !!", expertHistKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1381 } else {
5379c4a3 1382 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", expertHistKey->GetName())) ;
2e331c8b 1383 if ( expertOdata->IsA()->InheritsFrom("TH1") ) {
5379c4a3 1384 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", expertHistKey->GetName())) ;
2e331c8b 1385 TH1 * hExpertdata = static_cast<TH1*>(expertOdata) ;
1386 listTaskQAD->Add(hExpertdata) ;
1387 }
1388 }
1389 }
1390 }
5379c4a3 1391 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", histKey->GetName())) ;
2e331c8b 1392 if ( odata->IsA()->InheritsFrom("TH1") ) {
5379c4a3 1393 AliDebug(AliQAv1::GetQADebugLevel(), Form("Adding %s", histKey->GetName())) ;
2e331c8b 1394 TH1 * hdata = static_cast<TH1*>(odata) ;
1395 listTaskQAD->Add(hdata) ;
1396 }
1397 }
1398 }
1399 }
1400 Instance()->Put(listDetQAD, idr, &mdr) ;
1401 }
1402 }
1403 return rv ;
1404}
1405
1406//_____________________________________________________________________________
1407void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1408{
4e25ac79 1409 // set the current event specie and inform AliQAv1 that this event specie has been encountered
bc8761a0 1410 fEventSpecie = es ;
4e25ac79 1411 AliQAv1::Instance()->SetEventSpecie(es) ;
2e331c8b 1412}
1413
1414//_____________________________________________________________________________
1415void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1416{
1417 // Set custom reconstruction parameters for a given detector
1418 // Single set of parameters for all the events
1419 GetQADataMaker(det)->SetRecoParam(par) ;
1420}
1421
75373542 1422//_____________________________________________________________________________
1423void AliQAManager::SetWriteExpert()
1424{
1425 // enable the writing of QA expert data
1426 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
4e25ac79 1427 if (IsSelected(AliQAv1::GetDetName(iDet)))
75373542 1428 fQAWriteExpert[iDet] = kTRUE ;
1429 }
1430}
7cade814 1431
1432//_____________________________________________________________________________
1433void AliQAManager::Destroy() {
1434// delete AliQAManager instance and
1435// all associated objects
1436
1437 if (fgQAInstance) {
eca4fa66 1438 delete fgQAInstance ;
1439 fgQAInstance = NULL ;
7cade814 1440 }
1441}
1442