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