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