]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliQAManager.cxx
From Cesar: make selection and two-selection working with the new
[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 ;
130 }
131 }
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 ;
723 if (runNumber == -1)
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 ;
747 TString outFileName(Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),runNumber));
748 merger.OutputFile(outFileName.Data()) ;
749 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
750 TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), runNumber));
751 TString tmp(file[ifile]) ;
752 if (tmp.Contains(pattern)) {
753 merger.AddFile(tmp) ;
754 }
755 }
756 merger.Merge() ;
757 return kTRUE ;
758}
759
760//_____________________________________________________________________________
761Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
762{
763 // Merge the QA result from all the data chunks in a run
764 TString cmd ;
765 cmd = Form(".! ls %s*.root > tempo.txt", AliQA::GetQADataFileName()) ;
766 gROOT->ProcessLine(cmd.Data()) ;
767 ifstream in("tempo.txt") ;
768 const Int_t chunkMax = 100 ;
769 TString fileList[chunkMax] ;
770
771 Int_t index = 0 ;
772 while ( 1 ) {
773 TString file ;
774 in >> fileList[index] ;
775 if ( !in.good() )
776 break ;
777 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
778 index++ ;
779 }
780
781 if ( index == 0 ) {
782 AliError("No QA Result File found") ;
783 return kFALSE ;
784 }
785
786 TFileMerger merger ;
787 TString outFileName(Form("Merged.%s.Result.%d.root", AliQA::GetQADataFileName(), runNumber));
788 merger.OutputFile(outFileName.Data()) ;
789 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
790 TString file = fileList[ifile] ;
791 merger.AddFile(file) ;
792 }
793 merger.Merge() ;
794
795 return kTRUE ;
796}
797
798//_____________________________________________________________________________
799void AliQAManager::Reset(const Bool_t sameCycle)
800{
801 // Reset the default data members
802
803 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
804 if (IsSelected(AliQA::GetDetName(iDet))) {
805 AliQADataMaker * qadm = GetQADataMaker(iDet);
806 qadm->Reset();
807 }
808 }
809 if (fRawReaderDelete) {
810 delete fRawReader ;
811 fRawReader = NULL ;
812 }
813
814 fCycleSame = sameCycle ;
815 fESD = NULL ;
816 fESDTree = NULL ;
817 //fFirst = kTRUE ;
818 fNumberOfEvents = 999999 ;
819}
820
821//_____________________________________________________________________________
822AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
823{
824 // returns AliQAManager instance (singleton)
825
826 if (!fgQAInstance) {
827 fgQAInstance = new AliQAManager(mode) ;
828 if (!entryCache)
829 fgQAInstance->Init();
830 else
831 fgQAInstance->InitFromCache(entryCache,run);
832 }
833 return fgQAInstance;
834}
835
836//_____________________________________________________________________________
837TString AliQAManager::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
838{
839 //Runs all the QA data Maker for Raws only
840
841 fCycleSame = sameCycle ;
842 fRawReader = rawReader ;
843 fDetectors = detectors ;
844 fDetectorsW = detectors ;
845
846 AliCDBManager* man = AliCDBManager::Instance() ;
847
848 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
849 rawReader->NextEvent() ;
850 man->SetRun(fRawReader->GetRunNumber()) ;
851 rawReader->RewindEvents() ;
852 }
853
854 if (!fCycleSame)
855 if ( !InitQA(AliQA::kRAWS) )
856 return kFALSE ;
857 fRawReaderDelete = kFALSE ;
858
859 DoIt(AliQA::kRAWS) ;
860 return fDetectorsW ;
861}
862
863//_____________________________________________________________________________
864TString AliQAManager::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
865{
866 //Runs all the QA data Maker for Raws only
867
868 fCycleSame = sameCycle ;
869 fDetectors = detectors ;
870 fDetectorsW = detectors ;
871
872 AliCDBManager* man = AliCDBManager::Instance() ;
873 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
874 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
875 if ( ! rl ) {
876 AliFatal("galice.root file not found in current directory") ;
877 } else {
878 rl->CdGAFile() ;
879 rl->LoadgAlice() ;
880 if ( ! rl->GetAliRun() ) {
881 AliFatal("AliRun not found in galice.root") ;
882 } else {
883 rl->LoadHeader() ;
884 man->SetRun(rl->GetHeader()->GetRun());
885 }
886 }
887 }
888
889 if (!fCycleSame)
890 if ( !InitQA(AliQA::kRAWS, fileName) )
891 return kFALSE ;
892
893 DoIt(AliQA::kRAWS) ;
894 return fDetectorsW ;
895}
896
897//_____________________________________________________________________________
898TString AliQAManager::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
899{
900 // Runs all the QA data Maker for every detector
901
902 fCycleSame = sameCycle ;
903 fDetectors = detectors ;
904 fDetectorsW = detectors ;
905
906 AliCDBManager* man = AliCDBManager::Instance() ;
907 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
908 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
909 if ( ! rl ) {
910 AliFatal("galice.root file not found in current directory") ;
911 } else {
912 rl->CdGAFile() ;
913 rl->LoadgAlice() ;
914 if ( ! rl->GetAliRun() ) {
915 AliInfo("AliRun not found in galice.root") ;
916 } else {
917 rl->LoadHeader() ;
918 man->SetRun(rl->GetHeader()->GetRun()) ;
919 }
920 }
921 }
922
923
924 if ( taskIndex == AliQA::kNULLTASKINDEX) {
925 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
926 if ( fTasks.Contains(Form("%d", task)) ) {
927 if (!fCycleSame)
928 if ( !InitQA(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
929 return kFALSE ;
930 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
931 }
932 }
933 } else {
934 if (! fCycleSame )
935 if ( !InitQA(taskIndex, fileName) )
936 return kFALSE ;
937 DoIt(taskIndex) ;
938 }
939
940 return fDetectorsW ;
941
942}
943
944//_____________________________________________________________________________
945void AliQAManager::RunOneEvent(AliRawReader * rawReader)
946{
947 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
948 if ( ! rawReader )
949 return ;
950 AliCodeTimerAuto("") ;
951 if (fTasks.Contains(Form("%d", AliQA::kRAWS))){
952 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
953 if (!IsSelected(AliQA::GetDetName(iDet)))
954 continue;
955 AliQADataMaker *qadm = GetQADataMaker(iDet);
956 if (!qadm)
957 continue;
958 if ( qadm->IsCycleDone() ) {
959 qadm->EndOfCycle() ;
960 }
961 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
962 qadm->SetEventSpecie(fEventSpecie) ;
963 qadm->Exec(AliQA::kRAWS, rawReader) ;
964 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
965 }
966 }
967}
968
969//_____________________________________________________________________________
970void AliQAManager::RunOneEvent(AliESDEvent *& esd)
971{
972 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
973
974 AliCodeTimerAuto("") ;
975 if (fTasks.Contains(Form("%d", AliQA::kESDS))) {
976 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
977 if (!IsSelected(AliQA::GetDetName(iDet)))
978 continue;
979 AliQADataMaker *qadm = GetQADataMaker(iDet);
980 if (!qadm)
981 continue;
982 if ( qadm->IsCycleDone() ) {
983 qadm->EndOfCycle() ;
984 }
985 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
986 qadm->Exec(AliQA::kESDS, esd) ;
987 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
988 }
989 }
990}
991
992//_____________________________________________________________________________
993void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
994{
995 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
996 AliCodeTimerAuto("") ;
997 if (fTasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
998 if (IsSelected(AliQA::GetDetName(det))) {
999 AliQADataMaker *qadm = GetQADataMaker(det);
1000 if (qadm) {
1001 if ( qadm->IsCycleDone() ) {
1002 qadm->EndOfCycle() ;
1003 }
1004 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
1005 qadm->Exec(AliQA::kRECPOINTS, tree) ;
1006 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
1007 }
1008 }
1009 }
1010}
1011
1012//_____________________________________________________________________________
1013Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const char * year, const char * detectors) const
1014{
1015 // take the locasl QA data merge into a single file and save in OCDB
1016 Bool_t rv = kTRUE ;
1017 TString tmp(AliQA::GetQARefStorage()) ;
1018 if ( tmp.IsNull() ) {
1019 AliError("No storage defined, use AliQA::SetQARefStorage") ;
1020 return kFALSE ;
1021 }
1022 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
1023 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
1024 return kFALSE ;
1025 }
1026 TString sdet(detectors) ;
1027 sdet.ToUpper() ;
1028 TFile * inputFile ;
1029 if ( sdet.Contains("ALL") ) {
1030 rv = Merge(runNumber) ;
1031 if ( ! rv )
1032 return kFALSE ;
1033 TString inputFileName(Form("Merged.%s.Data.%d.root", AliQA::GetQADataFileName(), runNumber)) ;
1034 inputFile = TFile::Open(inputFileName.Data()) ;
1035 rv = SaveIt2OCDB(runNumber, inputFile, year, es) ;
1036 } else {
1037 for (Int_t index = 0; index < AliQA::kNDET; index++) {
1038 if (sdet.Contains(AliQA::GetDetName(index))) {
1039 TString inputFileName(Form("%s.%s.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber)) ;
1040 inputFile = TFile::Open(inputFileName.Data()) ;
1041 rv *= SaveIt2OCDB(runNumber, inputFile, year, es) ;
1042 }
1043 }
1044 }
1045 return rv ;
1046}
1047
1048//_____________________________________________________________________________
1049Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year, AliRecoParam::EventSpecie_t es) const
1050{
1051 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
1052 Bool_t rv = kTRUE ;
1053 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
1054 if ( ! IsDefaultStorageSet() ) {
1055 TString tmp( AliQA::GetQARefStorage() ) ;
1056 if ( tmp.Contains(AliQA::GetLabLocalOCDB()) )
1057 Instance()->SetDefaultStorage(AliQA::GetQARefStorage()) ;
1058 else {
1059 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
1060 tmp1.Append(year) ;
1061 tmp1.Append("?user=alidaq") ;
1062 Instance()->SetDefaultStorage(tmp1.Data()) ;
1063 }
1064 }
1065 Instance()->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
1066 if(GetRun() < 0)
1067 Instance()->SetRun(runNumber);
1068
1069 AliCDBMetaData mdr ;
1070 mdr.SetResponsible("yves schutz");
1071
1072 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
1073 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
1074 if ( detDir ) {
1075 AliInfo(Form("Entering %s", detDir->GetName())) ;
1076 AliQA::SetQARefDataDirName(es) ;
1077 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ;
1078 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
1079 TList * listDetQAD = new TList() ;
1080 TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ;
1081 mdr.SetComment(Form("%s QA stuff", AliQA::GetDetName(detIndex)));
1082 listDetQAD->SetName(listName) ;
1083 TList * taskList = detDir->GetListOfKeys() ;
1084 TIter nextTask(taskList) ;
1085 TKey * taskKey ;
1086 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
1087 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
1088 TDirectory * esDir = taskDir->GetDirectory(AliRecoParam::GetEventSpecieName(es)) ;
1089 AliInfo(Form("Saving %s", esDir->GetName())) ;
1090 TObjArray * listTaskQAD = new TObjArray(100) ;
1091 listTaskQAD->SetName(Form("%s/%s", taskKey->GetName(), AliRecoParam::GetEventSpecieName(es))) ;
1092 listDetQAD->Add(listTaskQAD) ;
1093 TList * histList = esDir->GetListOfKeys() ;
1094 TIter nextHist(histList) ;
1095 TKey * histKey ;
1096 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
1097 TObject * odata = esDir->Get(histKey->GetName()) ;
1098 if ( !odata ) {
1099 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1100 } else {
1101 if ( AliQA::GetExpert() == histKey->GetName() ) {
1102 TDirectory * expertDir = esDir->GetDirectory(histKey->GetName()) ;
1103 TList * expertHistList = expertDir->GetListOfKeys() ;
1104 TIter nextExpertHist(expertHistList) ;
1105 TKey * expertHistKey ;
1106 while ( (expertHistKey = dynamic_cast<TKey*>(nextExpertHist())) ) {
1107 TObject * expertOdata = expertDir->Get(expertHistKey->GetName()) ;
1108 if ( !expertOdata ) {
1109 AliError(Form("%s in %s/%s/Expert returns a NULL pointer !!", expertHistKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1110 } else {
1111 AliInfo(Form("Adding %s", expertHistKey->GetName())) ;
1112 if ( expertOdata->IsA()->InheritsFrom("TH1") ) {
1113 AliInfo(Form("Adding %s", expertHistKey->GetName())) ;
1114 TH1 * hExpertdata = static_cast<TH1*>(expertOdata) ;
1115 listTaskQAD->Add(hExpertdata) ;
1116 }
1117 }
1118 }
1119 }
1120 AliInfo(Form("Adding %s", histKey->GetName())) ;
1121 if ( odata->IsA()->InheritsFrom("TH1") ) {
1122 AliInfo(Form("Adding %s", histKey->GetName())) ;
1123 TH1 * hdata = static_cast<TH1*>(odata) ;
1124 listTaskQAD->Add(hdata) ;
1125 }
1126 }
1127 }
1128 }
1129 Instance()->Put(listDetQAD, idr, &mdr) ;
1130 }
1131 }
1132 return rv ;
1133}
1134
1135//_____________________________________________________________________________
1136void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1137{
1138 // set the current event specie and inform AliQA that this event specie has been encountered
1139 fEventSpecie = es ;
1140 AliQA::Instance()->SetEventSpecie(es) ;
1141}
1142
1143//_____________________________________________________________________________
1144void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1145{
1146 // Set custom reconstruction parameters for a given detector
1147 // Single set of parameters for all the events
1148 GetQADataMaker(det)->SetRecoParam(par) ;
1149}
1150
1151