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 ;
749 outFileName = Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),runNumber);
751 outFileName = Form("Merged.%s.Data.root",AliQA::GetQADataFileName());
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) ;
764 //_____________________________________________________________________________
765 Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
767 // Merge the QA result from all the data chunks in a run
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] ;
778 in >> fileList[index] ;
781 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
786 AliError("No QA Result File found") ;
791 TString outFileName ;
793 outFileName = Form("Merged.%s.Result.%d.root",AliQA::GetQADataFileName(),runNumber);
795 outFileName = Form("Merged.%s.Result.root",AliQA::GetQADataFileName());
796 merger.OutputFile(outFileName.Data()) ;
797 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
798 TString file = fileList[ifile] ;
799 merger.AddFile(file) ;
806 //_____________________________________________________________________________
807 void AliQAManager::Reset(const Bool_t sameCycle)
809 // Reset the default data members
811 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
812 if (IsSelected(AliQA::GetDetName(iDet))) {
813 AliQADataMaker * qadm = GetQADataMaker(iDet);
817 if (fRawReaderDelete) {
822 fCycleSame = sameCycle ;
826 fNumberOfEvents = 999999 ;
829 //_____________________________________________________________________________
830 AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
832 // returns AliQAManager instance (singleton)
835 fgQAInstance = new AliQAManager(mode) ;
837 fgQAInstance->Init();
839 fgQAInstance->InitFromCache(entryCache,run);
844 //_____________________________________________________________________________
845 TString AliQAManager::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
847 //Runs all the QA data Maker for Raws only
849 fCycleSame = sameCycle ;
850 fRawReader = rawReader ;
851 fDetectors = detectors ;
852 fDetectorsW = detectors ;
854 AliCDBManager* man = AliCDBManager::Instance() ;
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() ;
863 if ( !InitQA(AliQA::kRAWS) )
865 fRawReaderDelete = kFALSE ;
871 //_____________________________________________________________________________
872 TString AliQAManager::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
874 //Runs all the QA data Maker for Raws only
876 fCycleSame = sameCycle ;
877 fDetectors = detectors ;
878 fDetectorsW = detectors ;
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") ;
884 AliFatal("galice.root file not found in current directory") ;
888 if ( ! rl->GetAliRun() ) {
889 AliFatal("AliRun not found in galice.root") ;
892 man->SetRun(rl->GetHeader()->GetRun());
898 if ( !InitQA(AliQA::kRAWS, fileName) )
905 //_____________________________________________________________________________
906 TString AliQAManager::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
908 // Runs all the QA data Maker for every detector
910 fCycleSame = sameCycle ;
911 fDetectors = detectors ;
912 fDetectorsW = detectors ;
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") ;
918 AliFatal("galice.root file not found in current directory") ;
922 if ( ! rl->GetAliRun() ) {
923 AliInfo("AliRun not found in galice.root") ;
926 man->SetRun(rl->GetHeader()->GetRun()) ;
932 if ( taskIndex == AliQA::kNULLTASKINDEX) {
933 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
934 if ( fTasks.Contains(Form("%d", task)) ) {
936 if ( !InitQA(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
938 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
943 if ( !InitQA(taskIndex, fileName) )
952 //_____________________________________________________________________________
953 void AliQAManager::RunOneEvent(AliRawReader * rawReader)
955 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
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)))
963 AliQADataMaker *qadm = GetQADataMaker(iDet);
966 if ( qadm->IsCycleDone() ) {
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)));
977 //_____________________________________________________________________________
978 void AliQAManager::RunOneEvent(AliESDEvent *& esd)
980 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
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)))
987 AliQADataMaker *qadm = GetQADataMaker(iDet);
990 if ( qadm->IsCycleDone() ) {
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)));
1000 //_____________________________________________________________________________
1001 void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
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);
1009 if ( qadm->IsCycleDone() ) {
1010 qadm->EndOfCycle() ;
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)));
1020 //_____________________________________________________________________________
1021 Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const char * year, const char * detectors) const
1023 // take the locasl QA data merge into a single file and save in OCDB
1025 TString tmp(AliQA::GetQARefStorage()) ;
1026 if ( tmp.IsNull() ) {
1027 AliError("No storage defined, use AliQA::SetQARefStorage") ;
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())) ;
1034 TString sdet(detectors) ;
1037 if ( sdet.Contains("ALL") ) {
1038 rv = Merge(runNumber) ;
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) ;
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) ;
1056 //_____________________________________________________________________________
1057 Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year, AliRecoParam::EventSpecie_t es) const
1059 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
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()) ;
1067 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
1069 tmp1.Append("?user=alidaq") ;
1070 Instance()->SetDefaultStorage(tmp1.Data()) ;
1073 Instance()->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
1075 Instance()->SetRun(runNumber);
1077 AliCDBMetaData mdr ;
1078 mdr.SetResponsible("yves schutz");
1080 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
1081 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
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) ;
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) ;
1104 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
1105 TObject * odata = esDir->Get(histKey->GetName()) ;
1107 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
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())) ;
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) ;
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) ;
1137 Instance()->Put(listDetQAD, idr, &mdr) ;
1143 //_____________________________________________________________________________
1144 void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1146 // set the current event specie and inform AliQA that this event specie has been encountered
1148 AliQA::Instance()->SetEventSpecie(es) ;
1151 //_____________________________________________________________________________
1152 void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1154 // Set custom reconstruction parameters for a given detector
1155 // Single set of parameters for all the events
1156 GetQADataMaker(det)->SetRecoParam(par) ;