1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 /* $Id: AliQAManager.cxx 30894 2009-02-05 13:46:48Z schutz $ */
17 ///////////////////////////////////////////////////////////////////////////////
19 // class for running the QA makers //
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); //
29 ///////////////////////////////////////////////////////////////////////////////
33 #include <TFileMerger.h>
34 #include <TPluginManager.h>
39 #include "AliCDBManager.h"
40 #include "AliCDBEntry.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"
51 #include "AliModule.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"
60 #include "AliRunLoader.h"
61 #include "AliRunTag.h"
63 ClassImp(AliQAManager)
64 AliQAManager* AliQAManager::fgQAInstance = 0x0;
66 //_____________________________________________________________________________
67 AliQAManager::AliQAManager() :
79 fNumberOfEvents(999999),
83 fRawReaderDelete(kTRUE),
86 fEventSpecie(AliRecoParam::kDefault)
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 ;
100 //_____________________________________________________________________________
101 AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
109 fGAliceFileName(gAliceFilename),
113 fNumberOfEvents(999999),
117 fRawReaderDelete(kTRUE),
120 fEventSpecie(AliRecoParam::kDefault)
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 ;
134 //_____________________________________________________________________________
135 AliQAManager::AliQAManager(const AliQAManager & qas) :
137 fCurrentEvent(qas.fCurrentEvent),
139 fDetectors(qas.fDetectors),
140 fDetectorsW(qas.fDetectorsW),
143 fGAliceFileName(qas.fGAliceFileName),
144 fFirstEvent(qas.fFirstEvent),
145 fMaxEvents(qas.fMaxEvents),
147 fNumberOfEvents(qas.fNumberOfEvents),
149 fRunNumber(qas.fRunNumber),
151 fRawReaderDelete(kTRUE),
154 fEventSpecie(qas.fEventSpecie)
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] ;
165 //_____________________________________________________________________________
166 AliQAManager & AliQAManager::operator = (const AliQAManager & qas)
168 // assignment operator
169 this->~AliQAManager() ;
170 new(this) AliQAManager(qas) ;
174 //_____________________________________________________________________________
175 AliQAManager::~AliQAManager()
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] ;
187 if (fRawReaderDelete) {
194 //_____________________________________________________________________________
195 Bool_t AliQAManager::DoIt(const AliQA::TASKINDEX_t taskIndex)
197 // Runs all the QA data Maker for every detector
200 // Fill QA data in event loop
201 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
204 if ( iEvent%10 == 0 )
205 AliInfo(Form("processing event %d", iEvent));
206 if ( taskIndex == AliQA::kRAWS ) {
207 if ( !fRawReader->NextEvent() )
209 } else if ( taskIndex == AliQA::kESDS ) {
210 if ( fESDTree->GetEntry(iEvent) == 0 )
213 if ( fRunLoader->GetEvent(iEvent) != 0 )
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) ;
224 TTree * data = NULL ;
225 AliLoader* loader = GetLoader(qadm->GetUniqueID());
227 case AliQA::kNULLTASKINDEX :
230 qadm->Exec(taskIndex, fRawReader) ;
235 data = loader->TreeH() ;
237 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
241 qadm->Exec(taskIndex, data) ;
243 case AliQA::kSDIGITS :
245 loader->LoadSDigits() ;
246 data = loader->TreeS() ;
248 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
252 qadm->Exec(taskIndex, data) ;
254 case AliQA::kDIGITS :
256 loader->LoadDigits() ;
257 data = loader->TreeD() ;
259 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
263 qadm->Exec(taskIndex, data) ;
265 case AliQA::kRECPOINTS :
267 loader->LoadRecPoints() ;
268 data = loader->TreeR() ;
270 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
274 qadm->Exec(taskIndex, data) ;
276 case AliQA::kTRACKSEGMENTS :
278 case AliQA::kRECPARTICLES :
281 qadm->Exec(taskIndex, fESD) ;
283 case AliQA::kNTASKINDEX :
290 // Save QA data for all detectors
291 rv = Finish(taskIndex) ;
293 if ( taskIndex == AliQA::kRAWS )
294 fRawReader->RewindEvents() ;
299 //_____________________________________________________________________________
300 Bool_t AliQAManager::Finish(const AliQA::TASKINDEX_t taskIndex)
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) ;
307 qadm->EndOfCycle(taskIndex) ;
313 //_____________________________________________________________________________
314 TObjArray * AliQAManager::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const
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") ;
322 if ( ! IsDefaultStorageSet() ) {
323 TString tmp(AliQA::GetQARefDefaultStorage()) ;
326 Instance()->SetDefaultStorage(tmp.Data()) ;
327 Instance()->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
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()) ;
334 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
338 //_____________________________________________________________________________
339 AliLoader * AliQAManager::GetLoader(Int_t iDet)
341 // get the loader for a detector
343 if ( !fRunLoader || iDet == AliQA::kCORR)
346 TString detName = AliQA::GetDetName(iDet) ;
347 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
349 return fLoader[iDet] ;
351 // load the QA data maker object
352 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
353 TString loaderName = "Ali" + detName + "Loader" ;
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 + "()") ;
365 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
367 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
369 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
370 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
373 fLoader[iDet] = loader ;
377 //_____________________________________________________________________________
378 AliQA * AliQAManager::GetQA(UInt_t run, UInt_t evt)
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) ;
384 AliError(Form("File %s not found", fileName)) ;
387 TTree * tagTree = dynamic_cast<TTree *>(tagFile->Get("T")) ;
389 AliError(Form("Tree T not found in %s", fileName)) ;
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()) ;
401 //_____________________________________________________________________________
402 AliQADataMaker * AliQAManager::GetQADataMaker(const Int_t iDet)
404 // get the quality assurance data maker for a detector
406 if (fQADataMaker[iDet]) {
407 fQADataMaker[iDet]->SetEventSpecie(fEventSpecie) ;
408 return fQADataMaker[iDet] ;
411 AliQADataMaker * qadm = NULL ;
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) ;
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) ;
431 // load the QA data maker object
432 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
433 TString detName = AliQA::GetDetName(iDet) ;
435 if (tmp.Contains("sim"))
436 tmp.ReplaceAll("s", "S") ;
437 else if (tmp.Contains("rec"))
438 tmp.ReplaceAll("r", "R") ;
440 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
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 + "()") ;
451 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
453 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
455 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
456 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
459 qadm->SetName(AliQA::GetDetName(iDet));
460 qadm->SetUniqueID(iDet);
461 fQADataMaker[iDet] = qadm ;
462 qadm->SetEventSpecie(fEventSpecie) ;
468 //_____________________________________________________________________________
469 void AliQAManager::EndOfCycle(TObjArray * detArray)
471 // End of cycle QADataMakers
473 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
474 if (IsSelected(AliQA::GetDetName(iDet))) {
475 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
478 // skip non active detectors
480 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
481 if (!det || !det->IsActive())
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))) ;
493 //_____________________________________________________________________________
494 void AliQAManager::EndOfCycle(TString detectors)
496 // End of cycle QADataMakers
498 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
499 if (IsSelected(AliQA::GetDetName(iDet))) {
500 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
503 // skip non active detectors
504 if (!detectors.Contains(AliQA::GetDetName(iDet)))
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))) ;
515 //_____________________________________________________________________________
516 void AliQAManager::Increment()
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) ;
528 //_____________________________________________________________________________
529 Bool_t AliQAManager::InitQA(const AliQA::TASKINDEX_t taskIndex, const char * input )
531 // Initialize the event source and QA data makers
533 fTasks += Form("%d", taskIndex) ;
535 if (taskIndex == AliQA::kRAWS) {
537 fRawReader = AliRawReader::Create(input);
541 fRawReaderDelete = kTRUE ;
542 fRawReader->NextEvent() ;
543 fRunNumber = fRawReader->GetRunNumber() ;
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")) ;
555 AliError("esdTree not found") ;
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 ;
567 AliError("AliESDs.root not found") ;
571 if ( !InitRunLoader() ) {
572 AliWarning("No Run Loader not found") ;
574 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
575 if ( fMaxEvents < 0 )
576 fMaxEvents = fNumberOfEvents ;
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() ;
588 // Initialize all QA data makers for all detectors
589 fRunNumber = AliCDBManager::Instance()->GetRun() ;
590 if ( ! AliGeomManager::GetGeometry() )
591 AliGeomManager::LoadGeometry() ;
593 InitQADataMaker(fRunNumber, detArray) ; //, fCycleSame, kTRUE, detArray) ;
597 //_____________________________________________________________________________
598 void AliQAManager::InitQADataMaker(UInt_t run, TObjArray * detArray)
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) ;
605 AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
606 fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ;
608 if (fQAWriteExpert[iDet])
609 qadm->SetWriteExpert() ;
610 AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ;
611 // skip non active detectors
613 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
614 if (!det || !det->IsActive())
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) ;
633 //_____________________________________________________________________________
634 Bool_t AliQAManager::InitRunLoader()
636 // get or create the run loader
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)))
646 TString detName = AliQA::GetDetName(iDet) ;
647 if (detName == "HLT")
649 if (libs.Contains("lib" + detName + "base.so"))
651 gSystem->Load("lib" + detName + "base.so");
653 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
655 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
658 fRunLoader->CdGAFile();
659 if (fRunLoader->LoadgAlice() == 0) {
660 gAlice = fRunLoader->GetAliRun();
664 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
668 } else { // galice.root does not exist
669 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
675 fRunLoader->LoadHeader();
676 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
681 //_____________________________________________________________________________
682 Bool_t AliQAManager::IsSelected(const char * det)
684 // check whether detName is contained in detectors
685 // if yes, it is removed from detectors
688 const TString detName(det) ;
689 // always activates Correlation
690 if ( detName.Contains(AliQA::GetDetName(AliQA::kCORR))) {
693 // check if all detectors are selected
694 if (fDetectors.Contains("ALL")) {
697 } else if ((fDetectors.CompareTo(detName) == 0) ||
698 fDetectors.BeginsWith(detName+" ") ||
699 fDetectors.EndsWith(" "+detName) ||
700 fDetectors.Contains(" "+detName+" ")) {
707 //_____________________________________________________________________________
708 Bool_t AliQAManager::Merge(const Int_t runNumber) const
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) ;
718 //_____________________________________________________________________________
719 Bool_t AliQAManager::MergeData(const Int_t runNumber) const
721 // Merge all the cycles from all detectors in one single file per run
724 cmd = Form(".! ls *%s*.%d.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
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] ;
737 AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ;
742 AliError(Form("run number %d not found", runNumber)) ;
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) ;
760 //_____________________________________________________________________________
761 Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
763 // Merge the QA result from all the data chunks in a run
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] ;
774 in >> fileList[index] ;
777 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
782 AliError("No QA Result File found") ;
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) ;
798 //_____________________________________________________________________________
799 void AliQAManager::Reset(const Bool_t sameCycle)
801 // Reset the default data members
803 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
804 if (IsSelected(AliQA::GetDetName(iDet))) {
805 AliQADataMaker * qadm = GetQADataMaker(iDet);
809 if (fRawReaderDelete) {
814 fCycleSame = sameCycle ;
818 fNumberOfEvents = 999999 ;
821 //_____________________________________________________________________________
822 AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
824 // returns AliQAManager instance (singleton)
827 fgQAInstance = new AliQAManager(mode) ;
829 fgQAInstance->Init();
831 fgQAInstance->InitFromCache(entryCache,run);
836 //_____________________________________________________________________________
837 TString AliQAManager::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
839 //Runs all the QA data Maker for Raws only
841 fCycleSame = sameCycle ;
842 fRawReader = rawReader ;
843 fDetectors = detectors ;
844 fDetectorsW = detectors ;
846 AliCDBManager* man = AliCDBManager::Instance() ;
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() ;
855 if ( !InitQA(AliQA::kRAWS) )
857 fRawReaderDelete = kFALSE ;
863 //_____________________________________________________________________________
864 TString AliQAManager::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
866 //Runs all the QA data Maker for Raws only
868 fCycleSame = sameCycle ;
869 fDetectors = detectors ;
870 fDetectorsW = detectors ;
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") ;
876 AliFatal("galice.root file not found in current directory") ;
880 if ( ! rl->GetAliRun() ) {
881 AliFatal("AliRun not found in galice.root") ;
884 man->SetRun(rl->GetHeader()->GetRun());
890 if ( !InitQA(AliQA::kRAWS, fileName) )
897 //_____________________________________________________________________________
898 TString AliQAManager::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
900 // Runs all the QA data Maker for every detector
902 fCycleSame = sameCycle ;
903 fDetectors = detectors ;
904 fDetectorsW = detectors ;
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") ;
910 AliFatal("galice.root file not found in current directory") ;
914 if ( ! rl->GetAliRun() ) {
915 AliInfo("AliRun not found in galice.root") ;
918 man->SetRun(rl->GetHeader()->GetRun()) ;
924 if ( taskIndex == AliQA::kNULLTASKINDEX) {
925 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
926 if ( fTasks.Contains(Form("%d", task)) ) {
928 if ( !InitQA(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
930 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
935 if ( !InitQA(taskIndex, fileName) )
944 //_____________________________________________________________________________
945 void AliQAManager::RunOneEvent(AliRawReader * rawReader)
947 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
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)))
955 AliQADataMaker *qadm = GetQADataMaker(iDet);
958 if ( qadm->IsCycleDone() ) {
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)));
969 //_____________________________________________________________________________
970 void AliQAManager::RunOneEvent(AliESDEvent *& esd)
972 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
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)))
979 AliQADataMaker *qadm = GetQADataMaker(iDet);
982 if ( qadm->IsCycleDone() ) {
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)));
992 //_____________________________________________________________________________
993 void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
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);
1001 if ( qadm->IsCycleDone() ) {
1002 qadm->EndOfCycle() ;
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)));
1012 //_____________________________________________________________________________
1013 Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const char * year, const char * detectors) const
1015 // take the locasl QA data merge into a single file and save in OCDB
1017 TString tmp(AliQA::GetQARefStorage()) ;
1018 if ( tmp.IsNull() ) {
1019 AliError("No storage defined, use AliQA::SetQARefStorage") ;
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())) ;
1026 TString sdet(detectors) ;
1029 if ( sdet.Contains("ALL") ) {
1030 rv = Merge(runNumber) ;
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) ;
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) ;
1048 //_____________________________________________________________________________
1049 Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year, AliRecoParam::EventSpecie_t es) const
1051 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
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()) ;
1059 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
1061 tmp1.Append("?user=alidaq") ;
1062 Instance()->SetDefaultStorage(tmp1.Data()) ;
1065 Instance()->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
1067 Instance()->SetRun(runNumber);
1069 AliCDBMetaData mdr ;
1070 mdr.SetResponsible("yves schutz");
1072 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
1073 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
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) ;
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) ;
1096 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
1097 TObject * odata = esDir->Get(histKey->GetName()) ;
1099 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
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())) ;
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) ;
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) ;
1129 Instance()->Put(listDetQAD, idr, &mdr) ;
1135 //_____________________________________________________________________________
1136 void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1138 // set the current event specie and inform AliQA that this event specie has been encountered
1140 AliQA::Instance()->SetEventSpecie(es) ;
1143 //_____________________________________________________________________________
1144 void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1146 // Set custom reconstruction parameters for a given detector
1147 // Single set of parameters for all the events
1148 GetQADataMaker(det)->SetRecoParam(par) ;