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