]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAManager.cxx
merger methods for QA files
[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; //
22// qas.Run(AliQA::kRAWS, rawROOTFileName); //
23// qas.Run(AliQA::kHITS); //
24// qas.Run(AliQA::kSDIGITS); //
25// qas.Run(AliQA::kDIGITS); //
26// qas.Run(AliQA::kRECPOINTS); //
27// qas.Run(AliQA::kESDS); //
28// //
29///////////////////////////////////////////////////////////////////////////////
30
31#include <TKey.h>
32#include <TFile.h>
33#include <TFileMerger.h>
34#include <TPluginManager.h>
35#include <TROOT.h>
36#include <TString.h>
37#include <TSystem.h>
38
39#include "AliCDBManager.h"
40#include "AliCDBEntry.h"
41#include "AliCDBId.h"
42#include "AliCDBMetaData.h"
43#include "AliCodeTimer.h"
44#include "AliCorrQADataMakerRec.h"
45#include "AliDetectorRecoParam.h"
46#include "AliESDEvent.h"
47#include "AliGeomManager.h"
48#include "AliGlobalQADataMaker.h"
49#include "AliHeader.h"
50#include "AliLog.h"
51#include "AliModule.h"
52#include "AliQA.h"
53#include "AliQADataMakerRec.h"
54#include "AliQADataMakerSim.h"
55#include "AliQAManager.h"
56#include "AliRawReaderDate.h"
57#include "AliRawReaderFile.h"
58#include "AliRawReaderRoot.h"
59#include "AliRun.h"
60#include "AliRunLoader.h"
61#include "AliRunTag.h"
62
63ClassImp(AliQAManager)
64AliQAManager* AliQAManager::fgQAInstance = 0x0;
65
66//_____________________________________________________________________________
67AliQAManager::AliQAManager() :
68 AliCDBManager(),
69 fCurrentEvent(0),
70 fCycleSame(kFALSE),
71 fDetectors("ALL"),
72 fDetectorsW("ALL"),
73 fESD(NULL),
74 fESDTree(NULL),
75 fGAliceFileName(""),
76 fFirstEvent(0),
77 fMaxEvents(0),
78 fMode(""),
79 fNumberOfEvents(999999),
80 fRecoParam(),
81 fRunNumber(0),
82 fRawReader(NULL),
83 fRawReaderDelete(kTRUE),
84 fRunLoader(NULL),
85 fTasks(""),
86 fEventSpecie(AliRecoParam::kDefault)
87{
88 // default ctor
89 fMaxEvents = fNumberOfEvents ;
90 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
91 if (IsSelected(AliQA::GetDetName(iDet))) {
92 fLoader[iDet] = NULL ;
93 fQADataMaker[iDet] = NULL ;
94 fQACycles[iDet] = 999999 ;
95 fQAWriteExpert[iDet] = kTRUE ;
96 }
97 }
98}
99
100//_____________________________________________________________________________
101AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
102 AliCDBManager(),
103 fCurrentEvent(0),
104 fCycleSame(kFALSE),
105 fDetectors("ALL"),
106 fDetectorsW("ALL"),
107 fESD(NULL),
108 fESDTree(NULL),
109 fGAliceFileName(gAliceFilename),
110 fFirstEvent(0),
111 fMaxEvents(0),
112 fMode(mode),
113 fNumberOfEvents(999999),
114 fRecoParam(),
115 fRunNumber(0),
116 fRawReader(NULL),
117 fRawReaderDelete(kTRUE),
118 fRunLoader(NULL),
119 fTasks(""),
120 fEventSpecie(AliRecoParam::kDefault)
121{
122 // default ctor
123 fMaxEvents = fNumberOfEvents ;
124 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
125 if (IsSelected(AliQA::GetDetName(iDet))) {
126 fLoader[iDet] = NULL ;
127 fQADataMaker[iDet] = NULL ;
128 fQACycles[iDet] = 999999 ;
129 fQAWriteExpert[iDet] = kTRUE ;
65660bf3 130 }
131 }
2e331c8b 132}
133
134//_____________________________________________________________________________
135AliQAManager::AliQAManager(const AliQAManager & qas) :
136 AliCDBManager(),
137 fCurrentEvent(qas.fCurrentEvent),
138 fCycleSame(kFALSE),
139 fDetectors(qas.fDetectors),
140 fDetectorsW(qas.fDetectorsW),
141 fESD(NULL),
142 fESDTree(NULL),
143 fGAliceFileName(qas.fGAliceFileName),
144 fFirstEvent(qas.fFirstEvent),
145 fMaxEvents(qas.fMaxEvents),
146 fMode(qas.fMode),
147 fNumberOfEvents(qas.fNumberOfEvents),
148 fRecoParam(),
149 fRunNumber(qas.fRunNumber),
150 fRawReader(NULL),
151 fRawReaderDelete(kTRUE),
152 fRunLoader(NULL),
153 fTasks(qas.fTasks),
154 fEventSpecie(qas.fEventSpecie)
155{
156 // cpy ctor
157 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
158 fLoader[iDet] = qas.fLoader[iDet] ;
159 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
160 fQACycles[iDet] = qas.fQACycles[iDet] ;
161 fQAWriteExpert[iDet] = qas.fQAWriteExpert[iDet] ;
162 }
163}
164
165//_____________________________________________________________________________
166AliQAManager & AliQAManager::operator = (const AliQAManager & qas)
167{
168 // assignment operator
169 this->~AliQAManager() ;
170 new(this) AliQAManager(qas) ;
171 return *this ;
172}
173
174//_____________________________________________________________________________
175AliQAManager::~AliQAManager()
176{
177 // dtor
178 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
179 if (IsSelected(AliQA::GetDetName(iDet))) {
180 fLoader[iDet] = NULL;
181 if (fQADataMaker[iDet]) {
182 (fQADataMaker[iDet])->Finish() ;
183 delete fQADataMaker[iDet] ;
184 }
185 }
186 }
187 if (fRawReaderDelete) {
188 fRunLoader = NULL ;
189 delete fRawReader ;
190 fRawReader = NULL ;
191 }
192}
193
194//_____________________________________________________________________________
195Bool_t AliQAManager::DoIt(const AliQA::TASKINDEX_t taskIndex)
196{
197 // Runs all the QA data Maker for every detector
198
199 Bool_t rv = kFALSE ;
200 // Fill QA data in event loop
201 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
202 fCurrentEvent++ ;
203 // Get the event
204 if ( iEvent%10 == 0 )
205 AliInfo(Form("processing event %d", iEvent));
206 if ( taskIndex == AliQA::kRAWS ) {
207 if ( !fRawReader->NextEvent() )
208 break ;
209 } else if ( taskIndex == AliQA::kESDS ) {
210 if ( fESDTree->GetEntry(iEvent) == 0 )
211 break ;
212 } else {
213 if ( fRunLoader->GetEvent(iEvent) != 0 )
214 break ;
215 }
216 // loop over active loaders
217 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
218 if (IsSelected(AliQA::GetDetName(iDet))) {
219 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
220 if (!qadm) continue; // This detector doesn't have any QA (for example, HLT)
221 if ( qadm->IsCycleDone() ) {
222 qadm->EndOfCycle(taskIndex) ;
223 }
224 TTree * data = NULL ;
225 AliLoader* loader = GetLoader(qadm->GetUniqueID());
226 switch (taskIndex) {
227 case AliQA::kNULLTASKINDEX :
228 break ;
229 case AliQA::kRAWS :
230 qadm->Exec(taskIndex, fRawReader) ;
231 break ;
232 case AliQA::kHITS :
233 if( loader ) {
234 loader->LoadHits() ;
235 data = loader->TreeH() ;
236 if ( ! data ) {
237 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
238 break ;
239 }
240 }
241 qadm->Exec(taskIndex, data) ;
242 break ;
243 case AliQA::kSDIGITS :
244 if( loader ) {
245 loader->LoadSDigits() ;
246 data = loader->TreeS() ;
247 if ( ! data ) {
248 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
249 break ;
250 }
251 }
252 qadm->Exec(taskIndex, data) ;
253 break;
254 case AliQA::kDIGITS :
255 if( loader ) {
256 loader->LoadDigits() ;
257 data = loader->TreeD() ;
258 if ( ! data ) {
259 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
260 break ;
261 }
262 }
263 qadm->Exec(taskIndex, data) ;
264 break;
265 case AliQA::kRECPOINTS :
266 if( loader ) {
267 loader->LoadRecPoints() ;
268 data = loader->TreeR() ;
269 if (!data) {
270 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
271 break ;
272 }
273 }
274 qadm->Exec(taskIndex, data) ;
275 break;
276 case AliQA::kTRACKSEGMENTS :
277 break;
278 case AliQA::kRECPARTICLES :
279 break;
280 case AliQA::kESDS :
281 qadm->Exec(taskIndex, fESD) ;
282 break;
283 case AliQA::kNTASKINDEX :
284 break;
285 } //task switch
286 }
287 } // detector loop
288 Increment() ;
289 } // event loop
290 // Save QA data for all detectors
291 rv = Finish(taskIndex) ;
292
293 if ( taskIndex == AliQA::kRAWS )
294 fRawReader->RewindEvents() ;
295
296 return rv ;
297}
298
299//_____________________________________________________________________________
300Bool_t AliQAManager::Finish(const AliQA::TASKINDEX_t taskIndex)
301{
302 // write output to file for all detectors
303 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
304 if (IsSelected(AliQA::GetDetName(iDet))) {
305 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
306 if (qadm)
307 qadm->EndOfCycle(taskIndex) ;
308 }
309 }
310 return kTRUE ;
311}
312
313//_____________________________________________________________________________
314TObjArray * AliQAManager::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const
315{
316 // Retrieve the list of QA data for a given detector and a given task
317 TObjArray * rv = NULL ;
318 if ( !strlen(AliQA::GetQARefStorage()) ) {
319 AliError("No storage defined, use AliQA::SetQARefStorage") ;
320 return NULL ;
321 }
322 if ( ! IsDefaultStorageSet() ) {
323 TString tmp(AliQA::GetQARefDefaultStorage()) ;
324 tmp.Append(year) ;
325 tmp.Append("/") ;
326 Instance()->SetDefaultStorage(tmp.Data()) ;
327 Instance()->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
328 }
329 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ;
330 AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ;
331 AliCDBEntry* entry = QAManager()->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
332 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
333 if ( listDetQAD )
334 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
335 return rv ;
336}
337
338//_____________________________________________________________________________
339AliLoader * AliQAManager::GetLoader(Int_t iDet)
340{
341 // get the loader for a detector
342
343 if ( !fRunLoader || iDet == AliQA::kCORR)
344 return NULL ;
345
346 TString detName = AliQA::GetDetName(iDet) ;
347 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
348 if (fLoader[iDet])
349 return fLoader[iDet] ;
350
351 // load the QA data maker object
352 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
353 TString loaderName = "Ali" + detName + "Loader" ;
354
355 AliLoader * loader = NULL ;
356 // first check if a plugin is defined for the quality assurance data maker
357 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
358 // if not, add a plugin for it
359 if (!pluginHandler) {
360 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
361 TString libs = gSystem->GetLibraries() ;
362 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
363 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
364 } else {
365 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
366 }
367 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
368 }
369 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
370 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
371 }
372 if (loader)
373 fLoader[iDet] = loader ;
374 return loader ;
375}
376
377//_____________________________________________________________________________
378AliQA * AliQAManager::GetQA(UInt_t run, UInt_t evt)
379{
380// retrieves the QA object stored in a file named "Run{run}.Event{evt}_1.ESD.tag.root"
381 char * fileName = Form("Run%d.Event%d_1.ESD.tag.root", run, evt) ;
382 TFile * tagFile = TFile::Open(fileName) ;
383 if ( !tagFile ) {
384 AliError(Form("File %s not found", fileName)) ;
385 return NULL ;
386 }
387 TTree * tagTree = dynamic_cast<TTree *>(tagFile->Get("T")) ;
388 if ( !tagTree ) {
389 AliError(Form("Tree T not found in %s", fileName)) ;
390 tagFile->Close() ;
391 return NULL ;
392 }
393 AliRunTag * tag = new AliRunTag ;
394 tagTree->SetBranchAddress("AliTAG", &tag) ;
395 tagTree->GetEntry(evt) ;
396 AliQA * qa = AliQA::Instance(tag->GetQALength(), tag->GetQA(), tag->GetESLength(), tag->GetEventSpecies()) ;
397 tagFile->Close() ;
398 return qa ;
399}
400
401//_____________________________________________________________________________
402AliQADataMaker * AliQAManager::GetQADataMaker(const Int_t iDet)
403{
404 // get the quality assurance data maker for a detector
405
406 if (fQADataMaker[iDet]) {
407 fQADataMaker[iDet]->SetEventSpecie(fEventSpecie) ;
408 return fQADataMaker[iDet] ;
409 }
410
411 AliQADataMaker * qadm = NULL ;
412
413 if (iDet == AliQA::kGLOBAL) { //Global QA
414 qadm = new AliGlobalQADataMaker();
415 qadm->SetName(AliQA::GetDetName(iDet));
416 qadm->SetUniqueID(iDet);
417 fQADataMaker[iDet] = qadm;
418 qadm->SetEventSpecie(fEventSpecie) ;
419 return qadm;
420 }
421
422 if (iDet == AliQA::kCORR) { //the data maker for correlations among detectors
423 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
424 qadm->SetName(AliQA::GetDetName(iDet));
425 qadm->SetUniqueID(iDet);
426 fQADataMaker[iDet] = qadm;
427 qadm->SetEventSpecie(fEventSpecie) ;
428 return qadm;
429 }
430
431 // load the QA data maker object
432 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
433 TString detName = AliQA::GetDetName(iDet) ;
434 TString tmp(fMode) ;
435 if (tmp.Contains("sim"))
436 tmp.ReplaceAll("s", "S") ;
437 else if (tmp.Contains("rec"))
438 tmp.ReplaceAll("r", "R") ;
439
440 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
441
442 // first check if a plugin is defined for the quality assurance data maker
443 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
444 // if not, add a plugin for it
445 if (!pluginHandler) {
446 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
447 TString libs = gSystem->GetLibraries() ;
448 if (libs.Contains("lib" + detName + fMode + ".so") || (gSystem->Load("lib" + detName + fMode + ".so") >= 0)) {
449 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
450 } else {
451 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
452 }
453 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
454 }
455 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
456 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
457 }
458 if (qadm) {
459 qadm->SetName(AliQA::GetDetName(iDet));
460 qadm->SetUniqueID(iDet);
461 fQADataMaker[iDet] = qadm ;
462 qadm->SetEventSpecie(fEventSpecie) ;
463 }
464
465 return qadm ;
466}
467
468//_____________________________________________________________________________
469void AliQAManager::EndOfCycle(TObjArray * detArray)
470{
471 // End of cycle QADataMakers
472
473 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
474 if (IsSelected(AliQA::GetDetName(iDet))) {
475 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
476 if (!qadm)
477 continue ;
478 // skip non active detectors
479 if (detArray) {
480 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
481 if (!det || !det->IsActive())
482 continue ;
483 }
484 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
485 if ( fTasks.Contains(Form("%d", taskIndex)) )
486 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
487 }
488 qadm->Finish();
489 }
490 }
491}
492
493//_____________________________________________________________________________
494void AliQAManager::EndOfCycle(TString detectors)
495{
496 // End of cycle QADataMakers
497
498 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
499 if (IsSelected(AliQA::GetDetName(iDet))) {
500 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
501 if (!qadm)
502 continue ;
503 // skip non active detectors
504 if (!detectors.Contains(AliQA::GetDetName(iDet)))
505 continue ;
506 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
507 if ( fTasks.Contains(Form("%d", taskIndex)) )
508 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
509 }
510 qadm->Finish();
511 }
512 }
513}
514
515//_____________________________________________________________________________
516void AliQAManager::Increment()
517{
518 // Increments the cycle counter for all QA Data Makers
519 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
520 if (IsSelected(AliQA::GetDetName(iDet))) {
521 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
522 if (qadm)
523 qadm->Increment() ;
524 }
525 }
526}
527
528//_____________________________________________________________________________
529Bool_t AliQAManager::InitQA(const AliQA::TASKINDEX_t taskIndex, const char * input )
530{
531 // Initialize the event source and QA data makers
532
533 fTasks += Form("%d", taskIndex) ;
534
535 if (taskIndex == AliQA::kRAWS) {
536 if (!fRawReader) {
537 fRawReader = AliRawReader::Create(input);
538 }
539 if ( ! fRawReader )
540 return kFALSE ;
541 fRawReaderDelete = kTRUE ;
542 fRawReader->NextEvent() ;
543 fRunNumber = fRawReader->GetRunNumber() ;
544 SetRun(fRunNumber) ;
545 fRawReader->RewindEvents();
546 fNumberOfEvents = 999999 ;
547 if ( fMaxEvents < 0 )
548 fMaxEvents = fNumberOfEvents ;
549 } else if (taskIndex == AliQA::kESDS) {
550 fTasks = AliQA::GetTaskName(AliQA::kESDS) ;
551 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
552 TFile * esdFile = TFile::Open("AliESDs.root") ;
553 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
554 if ( !fESDTree ) {
555 AliError("esdTree not found") ;
556 return kFALSE ;
557 } else {
558 fESD = new AliESDEvent() ;
559 fESD->ReadFromTree(fESDTree) ;
560 fESDTree->GetEntry(0) ;
561 fRunNumber = fESD->GetRunNumber() ;
562 fNumberOfEvents = fESDTree->GetEntries() ;
563 if ( fMaxEvents < 0 )
564 fMaxEvents = fNumberOfEvents ;
565 }
566 } else {
567 AliError("AliESDs.root not found") ;
568 return kFALSE ;
569 }
570 } else {
571 if ( !InitRunLoader() ) {
572 AliWarning("No Run Loader not found") ;
573 } else {
574 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
575 if ( fMaxEvents < 0 )
576 fMaxEvents = fNumberOfEvents ;
577 }
578 }
579
580 // Get Detectors
581 TObjArray* detArray = NULL ;
582 if (fRunLoader) // check if RunLoader exists
583 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
584 detArray = fRunLoader->GetAliRun()->Detectors() ;
585 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
586 }
587
588 // Initialize all QA data makers for all detectors
589 fRunNumber = AliCDBManager::Instance()->GetRun() ;
590 if ( ! AliGeomManager::GetGeometry() )
591 AliGeomManager::LoadGeometry() ;
592
593 InitQADataMaker(fRunNumber, detArray) ; //, fCycleSame, kTRUE, detArray) ;
594 return kTRUE ;
595}
596
597//_____________________________________________________________________________
598void AliQAManager::InitQADataMaker(UInt_t run, TObjArray * detArray)
599{
600 // Initializes The QADataMaker for all active detectors and for all active tasks
601 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
602 if (IsSelected(AliQA::GetDetName(iDet))) {
603 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
604 if (!qadm) {
605 AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
606 fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ;
607 } else {
608 if (fQAWriteExpert[iDet])
609 qadm->SetWriteExpert() ;
610 AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ;
611 // skip non active detectors
612 if (detArray) {
613 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
614 if (!det || !det->IsActive())
615 continue ;
616 }
617 if (fQAWriteExpert[iDet]) qadm->SetWriteExpert() ;
618 // Set default reco params
619 Bool_t sameCycle = kFALSE ;
620 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
621 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
622 qadm->Init(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), GetQACycles(qadm->GetUniqueID())) ;
623 qadm->StartOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), run, sameCycle) ;
624 sameCycle = kTRUE ;
625 }
626 }
627 }
628 }
629 }
630}
631
632
633//_____________________________________________________________________________
634Bool_t AliQAManager::InitRunLoader()
635{
636 // get or create the run loader
637 if (fRunLoader) {
638 fCycleSame = kTRUE ;
639 } else {
640 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
641 // load all base libraries to get the loader classes
642 TString libs = gSystem->GetLibraries() ;
643 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
644 if (!IsSelected(AliQA::GetDetName(iDet)))
645 continue ;
646 TString detName = AliQA::GetDetName(iDet) ;
647 if (detName == "HLT")
648 continue;
649 if (libs.Contains("lib" + detName + "base.so"))
650 continue;
651 gSystem->Load("lib" + detName + "base.so");
652 }
653 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
654 if (!fRunLoader) {
655 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
656 return kFALSE;
657 }
658 fRunLoader->CdGAFile();
659 if (fRunLoader->LoadgAlice() == 0) {
660 gAlice = fRunLoader->GetAliRun();
661 }
662
663 if (!gAlice) {
664 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
665 return kFALSE;
666 }
667
668 } else { // galice.root does not exist
669 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
670 return kFALSE;
671 }
672 }
673
674 if (!fRunNumber) {
675 fRunLoader->LoadHeader();
676 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
677 }
678 return kTRUE;
679}
680
681//_____________________________________________________________________________
682Bool_t AliQAManager::IsSelected(const char * det)
683{
684 // check whether detName is contained in detectors
685 // if yes, it is removed from detectors
686
687 Bool_t rv = kFALSE;
688 const TString detName(det) ;
689 // always activates Correlation
690 if ( detName.Contains(AliQA::GetDetName(AliQA::kCORR))) {
691 rv = kTRUE ;
692 } else {
693 // check if all detectors are selected
694 if (fDetectors.Contains("ALL")) {
695 fDetectors = "ALL";
696 rv = kTRUE;
697 } else if ((fDetectors.CompareTo(detName) == 0) ||
698 fDetectors.BeginsWith(detName+" ") ||
699 fDetectors.EndsWith(" "+detName) ||
700 fDetectors.Contains(" "+detName+" ")) {
701 rv = kTRUE;
702 }
703 }
704 return rv ;
705}
706
707//_____________________________________________________________________________
708Bool_t AliQAManager::Merge(const Int_t runNumber) const
709{
710 // Merge data from all the cycles from all detectors in one single file per run
711 // Merge the QA results from all the data chunks in one run
712 Bool_t rv = MergeData(runNumber) ;
713 rv *= MergeResults(runNumber) ;
714 return rv ;
715}
716
717
718//_____________________________________________________________________________
719Bool_t AliQAManager::MergeData(const Int_t runNumber) const
720{
721 // Merge all the cycles from all detectors in one single file per run
722 TString cmd ;
fc07289e 723 if (runNumber != -1)
2e331c8b 724 cmd = Form(".! ls *%s*.%d.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
725 else
726 cmd = Form(".! ls *%s*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
727 gROOT->ProcessLine(cmd.Data()) ;
728 ifstream in("tempo.txt") ;
729 const Int_t runMax = 10 ;
730 TString file[AliQA::kNDET*runMax] ;
731
732 Int_t index = 0 ;
733 while ( 1 ) {
734 in >> file[index] ;
735 if ( !in.good() )
736 break ;
737 AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ;
738 index++ ;
739 }
740
741 if ( index == 0 ) {
742 AliError(Form("run number %d not found", runNumber)) ;
743 return kFALSE ;
744 }
745
746 TFileMerger merger ;
fc07289e 747 TString outFileName ;
748 if (runNumber != -1)
749 outFileName = Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),runNumber);
750 else
751 outFileName = Form("Merged.%s.Data.root",AliQA::GetQADataFileName());
2e331c8b 752 merger.OutputFile(outFileName.Data()) ;
753 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
754 TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), runNumber));
755 TString tmp(file[ifile]) ;
756 if (tmp.Contains(pattern)) {
757 merger.AddFile(tmp) ;
758 }
759 }
760 merger.Merge() ;
761 return kTRUE ;
762}
763
764//_____________________________________________________________________________
765Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
766{
767 // Merge the QA result from all the data chunks in a run
768 TString cmd ;
769 cmd = Form(".! ls %s*.root > tempo.txt", AliQA::GetQADataFileName()) ;
770 gROOT->ProcessLine(cmd.Data()) ;
771 ifstream in("tempo.txt") ;
772 const Int_t chunkMax = 100 ;
773 TString fileList[chunkMax] ;
774
775 Int_t index = 0 ;
776 while ( 1 ) {
777 TString file ;
778 in >> fileList[index] ;
779 if ( !in.good() )
780 break ;
781 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
782 index++ ;
783 }
784
785 if ( index == 0 ) {
786 AliError("No QA Result File found") ;
787 return kFALSE ;
788 }
789
790 TFileMerger merger ;
fc07289e 791 TString outFileName ;
792 if (runNumber != -1)
793 outFileName = Form("Merged.%s.Result.%d.root",AliQA::GetQADataFileName(),runNumber);
794 else
795 outFileName = Form("Merged.%s.Result.root",AliQA::GetQADataFileName());
2e331c8b 796 merger.OutputFile(outFileName.Data()) ;
797 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
798 TString file = fileList[ifile] ;
799 merger.AddFile(file) ;
800 }
801 merger.Merge() ;
802
803 return kTRUE ;
804}
805
806//_____________________________________________________________________________
807void AliQAManager::Reset(const Bool_t sameCycle)
808{
809 // Reset the default data members
810
811 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
812 if (IsSelected(AliQA::GetDetName(iDet))) {
813 AliQADataMaker * qadm = GetQADataMaker(iDet);
814 qadm->Reset();
815 }
816 }
817 if (fRawReaderDelete) {
818 delete fRawReader ;
819 fRawReader = NULL ;
820 }
821
822 fCycleSame = sameCycle ;
823 fESD = NULL ;
824 fESDTree = NULL ;
825 //fFirst = kTRUE ;
826 fNumberOfEvents = 999999 ;
827}
828
829//_____________________________________________________________________________
830AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
831{
832 // returns AliQAManager instance (singleton)
833
834 if (!fgQAInstance) {
835 fgQAInstance = new AliQAManager(mode) ;
836 if (!entryCache)
837 fgQAInstance->Init();
838 else
839 fgQAInstance->InitFromCache(entryCache,run);
840 }
841 return fgQAInstance;
842}
843
844//_____________________________________________________________________________
845TString AliQAManager::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
846{
847 //Runs all the QA data Maker for Raws only
848
849 fCycleSame = sameCycle ;
850 fRawReader = rawReader ;
851 fDetectors = detectors ;
852 fDetectorsW = detectors ;
853
854 AliCDBManager* man = AliCDBManager::Instance() ;
855
856 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
857 rawReader->NextEvent() ;
858 man->SetRun(fRawReader->GetRunNumber()) ;
859 rawReader->RewindEvents() ;
860 }
861
862 if (!fCycleSame)
863 if ( !InitQA(AliQA::kRAWS) )
864 return kFALSE ;
865 fRawReaderDelete = kFALSE ;
866
867 DoIt(AliQA::kRAWS) ;
868 return fDetectorsW ;
869}
870
871//_____________________________________________________________________________
872TString AliQAManager::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
873{
874 //Runs all the QA data Maker for Raws only
875
876 fCycleSame = sameCycle ;
877 fDetectors = detectors ;
878 fDetectorsW = detectors ;
879
880 AliCDBManager* man = AliCDBManager::Instance() ;
881 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
882 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
883 if ( ! rl ) {
884 AliFatal("galice.root file not found in current directory") ;
885 } else {
886 rl->CdGAFile() ;
887 rl->LoadgAlice() ;
888 if ( ! rl->GetAliRun() ) {
889 AliFatal("AliRun not found in galice.root") ;
890 } else {
891 rl->LoadHeader() ;
892 man->SetRun(rl->GetHeader()->GetRun());
893 }
894 }
895 }
896
897 if (!fCycleSame)
898 if ( !InitQA(AliQA::kRAWS, fileName) )
899 return kFALSE ;
900
901 DoIt(AliQA::kRAWS) ;
902 return fDetectorsW ;
903}
904
905//_____________________________________________________________________________
906TString AliQAManager::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
907{
908 // Runs all the QA data Maker for every detector
909
910 fCycleSame = sameCycle ;
911 fDetectors = detectors ;
912 fDetectorsW = detectors ;
913
914 AliCDBManager* man = AliCDBManager::Instance() ;
915 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
916 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
917 if ( ! rl ) {
918 AliFatal("galice.root file not found in current directory") ;
919 } else {
920 rl->CdGAFile() ;
921 rl->LoadgAlice() ;
922 if ( ! rl->GetAliRun() ) {
923 AliInfo("AliRun not found in galice.root") ;
924 } else {
925 rl->LoadHeader() ;
926 man->SetRun(rl->GetHeader()->GetRun()) ;
927 }
928 }
929 }
930
931
932 if ( taskIndex == AliQA::kNULLTASKINDEX) {
933 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
934 if ( fTasks.Contains(Form("%d", task)) ) {
935 if (!fCycleSame)
936 if ( !InitQA(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
937 return kFALSE ;
938 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
939 }
940 }
941 } else {
942 if (! fCycleSame )
943 if ( !InitQA(taskIndex, fileName) )
944 return kFALSE ;
945 DoIt(taskIndex) ;
946 }
947
948 return fDetectorsW ;
949
950}
951
952//_____________________________________________________________________________
953void AliQAManager::RunOneEvent(AliRawReader * rawReader)
954{
955 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
956 if ( ! rawReader )
957 return ;
958 AliCodeTimerAuto("") ;
959 if (fTasks.Contains(Form("%d", AliQA::kRAWS))){
960 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
961 if (!IsSelected(AliQA::GetDetName(iDet)))
962 continue;
963 AliQADataMaker *qadm = GetQADataMaker(iDet);
964 if (!qadm)
965 continue;
966 if ( qadm->IsCycleDone() ) {
967 qadm->EndOfCycle() ;
968 }
969 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
970 qadm->SetEventSpecie(fEventSpecie) ;
971 qadm->Exec(AliQA::kRAWS, rawReader) ;
972 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
973 }
974 }
975}
976
977//_____________________________________________________________________________
978void AliQAManager::RunOneEvent(AliESDEvent *& esd)
979{
980 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
981
982 AliCodeTimerAuto("") ;
983 if (fTasks.Contains(Form("%d", AliQA::kESDS))) {
984 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
985 if (!IsSelected(AliQA::GetDetName(iDet)))
986 continue;
987 AliQADataMaker *qadm = GetQADataMaker(iDet);
988 if (!qadm)
989 continue;
990 if ( qadm->IsCycleDone() ) {
991 qadm->EndOfCycle() ;
992 }
993 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
994 qadm->Exec(AliQA::kESDS, esd) ;
995 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
996 }
997 }
998}
999
1000//_____________________________________________________________________________
1001void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
1002{
1003 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
1004 AliCodeTimerAuto("") ;
1005 if (fTasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1006 if (IsSelected(AliQA::GetDetName(det))) {
1007 AliQADataMaker *qadm = GetQADataMaker(det);
1008 if (qadm) {
1009 if ( qadm->IsCycleDone() ) {
1010 qadm->EndOfCycle() ;
1011 }
1012 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
1013 qadm->Exec(AliQA::kRECPOINTS, tree) ;
1014 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
1015 }
1016 }
1017 }
1018}
1019
1020//_____________________________________________________________________________
1021Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const char * year, const char * detectors) const
1022{
1023 // take the locasl QA data merge into a single file and save in OCDB
1024 Bool_t rv = kTRUE ;
1025 TString tmp(AliQA::GetQARefStorage()) ;
1026 if ( tmp.IsNull() ) {
1027 AliError("No storage defined, use AliQA::SetQARefStorage") ;
1028 return kFALSE ;
1029 }
1030 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
1031 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
1032 return kFALSE ;
1033 }
1034 TString sdet(detectors) ;
1035 sdet.ToUpper() ;
1036 TFile * inputFile ;
1037 if ( sdet.Contains("ALL") ) {
1038 rv = Merge(runNumber) ;
1039 if ( ! rv )
1040 return kFALSE ;
1041 TString inputFileName(Form("Merged.%s.Data.%d.root", AliQA::GetQADataFileName(), runNumber)) ;
1042 inputFile = TFile::Open(inputFileName.Data()) ;
1043 rv = SaveIt2OCDB(runNumber, inputFile, year, es) ;
1044 } else {
1045 for (Int_t index = 0; index < AliQA::kNDET; index++) {
1046 if (sdet.Contains(AliQA::GetDetName(index))) {
1047 TString inputFileName(Form("%s.%s.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber)) ;
1048 inputFile = TFile::Open(inputFileName.Data()) ;
1049 rv *= SaveIt2OCDB(runNumber, inputFile, year, es) ;
1050 }
1051 }
1052 }
1053 return rv ;
1054}
1055
1056//_____________________________________________________________________________
1057Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year, AliRecoParam::EventSpecie_t es) const
1058{
1059 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
1060 Bool_t rv = kTRUE ;
1061 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
1062 if ( ! IsDefaultStorageSet() ) {
1063 TString tmp( AliQA::GetQARefStorage() ) ;
1064 if ( tmp.Contains(AliQA::GetLabLocalOCDB()) )
1065 Instance()->SetDefaultStorage(AliQA::GetQARefStorage()) ;
1066 else {
1067 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
1068 tmp1.Append(year) ;
1069 tmp1.Append("?user=alidaq") ;
1070 Instance()->SetDefaultStorage(tmp1.Data()) ;
1071 }
1072 }
1073 Instance()->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
1074 if(GetRun() < 0)
1075 Instance()->SetRun(runNumber);
1076
1077 AliCDBMetaData mdr ;
1078 mdr.SetResponsible("yves schutz");
1079
1080 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
1081 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
1082 if ( detDir ) {
1083 AliInfo(Form("Entering %s", detDir->GetName())) ;
1084 AliQA::SetQARefDataDirName(es) ;
1085 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ;
1086 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
1087 TList * listDetQAD = new TList() ;
1088 TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ;
1089 mdr.SetComment(Form("%s QA stuff", AliQA::GetDetName(detIndex)));
1090 listDetQAD->SetName(listName) ;
1091 TList * taskList = detDir->GetListOfKeys() ;
1092 TIter nextTask(taskList) ;
1093 TKey * taskKey ;
1094 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
1095 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
1096 TDirectory * esDir = taskDir->GetDirectory(AliRecoParam::GetEventSpecieName(es)) ;
1097 AliInfo(Form("Saving %s", esDir->GetName())) ;
1098 TObjArray * listTaskQAD = new TObjArray(100) ;
1099 listTaskQAD->SetName(Form("%s/%s", taskKey->GetName(), AliRecoParam::GetEventSpecieName(es))) ;
1100 listDetQAD->Add(listTaskQAD) ;
1101 TList * histList = esDir->GetListOfKeys() ;
1102 TIter nextHist(histList) ;
1103 TKey * histKey ;
1104 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
1105 TObject * odata = esDir->Get(histKey->GetName()) ;
1106 if ( !odata ) {
1107 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1108 } else {
1109 if ( AliQA::GetExpert() == histKey->GetName() ) {
1110 TDirectory * expertDir = esDir->GetDirectory(histKey->GetName()) ;
1111 TList * expertHistList = expertDir->GetListOfKeys() ;
1112 TIter nextExpertHist(expertHistList) ;
1113 TKey * expertHistKey ;
1114 while ( (expertHistKey = dynamic_cast<TKey*>(nextExpertHist())) ) {
1115 TObject * expertOdata = expertDir->Get(expertHistKey->GetName()) ;
1116 if ( !expertOdata ) {
1117 AliError(Form("%s in %s/%s/Expert returns a NULL pointer !!", expertHistKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1118 } else {
1119 AliInfo(Form("Adding %s", expertHistKey->GetName())) ;
1120 if ( expertOdata->IsA()->InheritsFrom("TH1") ) {
1121 AliInfo(Form("Adding %s", expertHistKey->GetName())) ;
1122 TH1 * hExpertdata = static_cast<TH1*>(expertOdata) ;
1123 listTaskQAD->Add(hExpertdata) ;
1124 }
1125 }
1126 }
1127 }
1128 AliInfo(Form("Adding %s", histKey->GetName())) ;
1129 if ( odata->IsA()->InheritsFrom("TH1") ) {
1130 AliInfo(Form("Adding %s", histKey->GetName())) ;
1131 TH1 * hdata = static_cast<TH1*>(odata) ;
1132 listTaskQAD->Add(hdata) ;
1133 }
1134 }
1135 }
1136 }
1137 Instance()->Put(listDetQAD, idr, &mdr) ;
1138 }
1139 }
1140 return rv ;
1141}
1142
1143//_____________________________________________________________________________
1144void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1145{
1146 // set the current event specie and inform AliQA that this event specie has been encountered
1147 fEventSpecie = es ;
1148 AliQA::Instance()->SetEventSpecie(es) ;
1149}
1150
1151//_____________________________________________________________________________
1152void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1153{
1154 // Set custom reconstruction parameters for a given detector
1155 // Single set of parameters for all the events
1156 GetQADataMaker(det)->SetRecoParam(par) ;
1157}
1158
1159