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