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>
35 #include <TGridCollection.h>
36 #include <TGridResult.h>
37 #include <TPluginManager.h>
42 #include "AliCDBManager.h"
43 #include "AliCDBEntry.h"
45 #include "AliCDBMetaData.h"
46 #include "AliCodeTimer.h"
47 #include "AliCorrQADataMakerRec.h"
48 #include "AliDetectorRecoParam.h"
49 #include "AliESDEvent.h"
50 #include "AliGeomManager.h"
51 #include "AliGlobalQADataMaker.h"
52 #include "AliHeader.h"
54 #include "AliModule.h"
56 #include "AliQADataMakerRec.h"
57 #include "AliQADataMakerSim.h"
58 #include "AliQAManager.h"
59 #include "AliRawReaderDate.h"
60 #include "AliRawReaderFile.h"
61 #include "AliRawReaderRoot.h"
63 #include "AliRunLoader.h"
64 #include "AliRunTag.h"
66 ClassImp(AliQAManager)
67 AliQAManager* AliQAManager::fgQAInstance = 0x0;
69 //_____________________________________________________________________________
70 AliQAManager::AliQAManager() :
82 fNumberOfEvents(999999),
86 fRawReaderDelete(kTRUE),
89 fEventSpecie(AliRecoParam::kDefault)
92 fMaxEvents = fNumberOfEvents ;
93 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
94 if (IsSelected(AliQA::GetDetName(iDet))) {
95 fLoader[iDet] = NULL ;
96 fQADataMaker[iDet] = NULL ;
97 fQACycles[iDet] = 999999 ;
98 fQAWriteExpert[iDet] = kTRUE ;
103 //_____________________________________________________________________________
104 AliQAManager::AliQAManager(const Char_t * mode, const Char_t* gAliceFilename) :
112 fGAliceFileName(gAliceFilename),
116 fNumberOfEvents(999999),
120 fRawReaderDelete(kTRUE),
123 fEventSpecie(AliRecoParam::kDefault)
126 fMaxEvents = fNumberOfEvents ;
127 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
128 if (IsSelected(AliQA::GetDetName(iDet))) {
129 fLoader[iDet] = NULL ;
130 fQADataMaker[iDet] = NULL ;
131 fQACycles[iDet] = 999999 ;
132 fQAWriteExpert[iDet] = kTRUE ;
137 //_____________________________________________________________________________
138 AliQAManager::AliQAManager(const AliQAManager & qas) :
140 fCurrentEvent(qas.fCurrentEvent),
142 fDetectors(qas.fDetectors),
143 fDetectorsW(qas.fDetectorsW),
146 fGAliceFileName(qas.fGAliceFileName),
147 fFirstEvent(qas.fFirstEvent),
148 fMaxEvents(qas.fMaxEvents),
150 fNumberOfEvents(qas.fNumberOfEvents),
152 fRunNumber(qas.fRunNumber),
154 fRawReaderDelete(kTRUE),
157 fEventSpecie(qas.fEventSpecie)
160 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
161 fLoader[iDet] = qas.fLoader[iDet] ;
162 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
163 fQACycles[iDet] = qas.fQACycles[iDet] ;
164 fQAWriteExpert[iDet] = qas.fQAWriteExpert[iDet] ;
168 //_____________________________________________________________________________
169 AliQAManager & AliQAManager::operator = (const AliQAManager & qas)
171 // assignment operator
172 this->~AliQAManager() ;
173 new(this) AliQAManager(qas) ;
177 //_____________________________________________________________________________
178 AliQAManager::~AliQAManager()
181 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
182 if (IsSelected(AliQA::GetDetName(iDet))) {
183 fLoader[iDet] = NULL;
184 if (fQADataMaker[iDet]) {
185 (fQADataMaker[iDet])->Finish() ;
186 delete fQADataMaker[iDet] ;
190 if (fRawReaderDelete) {
197 //_____________________________________________________________________________
198 Bool_t AliQAManager::DoIt(const AliQA::TASKINDEX_t taskIndex)
200 // Runs all the QA data Maker for every detector
203 // Fill QA data in event loop
204 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
207 if ( iEvent%10 == 0 )
208 AliInfo(Form("processing event %d", iEvent));
209 if ( taskIndex == AliQA::kRAWS ) {
210 if ( !fRawReader->NextEvent() )
212 } else if ( taskIndex == AliQA::kESDS ) {
213 if ( fESDTree->GetEntry(iEvent) == 0 )
216 if ( fRunLoader->GetEvent(iEvent) != 0 )
219 // loop over active loaders
220 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
221 if (IsSelected(AliQA::GetDetName(iDet))) {
222 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
223 if (!qadm) continue; // This detector doesn't have any QA (for example, HLT)
224 if ( qadm->IsCycleDone() ) {
225 qadm->EndOfCycle(taskIndex) ;
227 TTree * data = NULL ;
228 AliLoader* loader = GetLoader(qadm->GetUniqueID());
230 case AliQA::kNULLTASKINDEX :
233 qadm->Exec(taskIndex, fRawReader) ;
238 data = loader->TreeH() ;
240 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
244 qadm->Exec(taskIndex, data) ;
246 case AliQA::kSDIGITS :
248 loader->LoadSDigits() ;
249 data = loader->TreeS() ;
251 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
255 qadm->Exec(taskIndex, data) ;
257 case AliQA::kDIGITS :
259 loader->LoadDigits() ;
260 data = loader->TreeD() ;
262 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
266 qadm->Exec(taskIndex, data) ;
268 case AliQA::kRECPOINTS :
270 loader->LoadRecPoints() ;
271 data = loader->TreeR() ;
273 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
277 qadm->Exec(taskIndex, data) ;
279 case AliQA::kTRACKSEGMENTS :
281 case AliQA::kRECPARTICLES :
284 qadm->Exec(taskIndex, fESD) ;
286 case AliQA::kNTASKINDEX :
293 // Save QA data for all detectors
294 rv = Finish(taskIndex) ;
296 if ( taskIndex == AliQA::kRAWS )
297 fRawReader->RewindEvents() ;
302 //_____________________________________________________________________________
303 Bool_t AliQAManager::Finish(const AliQA::TASKINDEX_t taskIndex)
305 // write output to file for all detectors
306 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
307 if (IsSelected(AliQA::GetDetName(iDet))) {
308 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
310 qadm->EndOfCycle(taskIndex) ;
316 //_____________________________________________________________________________
317 TObjArray * AliQAManager::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const
319 // Retrieve the list of QA data for a given detector and a given task
320 TObjArray * rv = NULL ;
321 if ( !strlen(AliQA::GetQARefStorage()) ) {
322 AliError("No storage defined, use AliQA::SetQARefStorage") ;
325 if ( ! IsDefaultStorageSet() ) {
326 TString tmp(AliQA::GetQARefDefaultStorage()) ;
329 Instance()->SetDefaultStorage(tmp.Data()) ;
330 Instance()->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
332 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ;
333 AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ;
334 AliCDBEntry* entry = QAManager()->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
335 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
337 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
341 //_____________________________________________________________________________
342 AliLoader * AliQAManager::GetLoader(Int_t iDet)
344 // get the loader for a detector
346 if ( !fRunLoader || iDet == AliQA::kCORR)
349 TString detName = AliQA::GetDetName(iDet) ;
350 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
352 return fLoader[iDet] ;
354 // load the QA data maker object
355 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
356 TString loaderName = "Ali" + detName + "Loader" ;
358 AliLoader * loader = NULL ;
359 // first check if a plugin is defined for the quality assurance data maker
360 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
361 // if not, add a plugin for it
362 if (!pluginHandler) {
363 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
364 TString libs = gSystem->GetLibraries() ;
365 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
366 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
368 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
370 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
372 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
373 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
376 fLoader[iDet] = loader ;
380 //_____________________________________________________________________________
381 AliQA * AliQAManager::GetQA(UInt_t run, UInt_t evt)
383 // retrieves the QA object stored in a file named "Run{run}.Event{evt}_1.ESD.tag.root"
384 char * fileName = Form("Run%d.Event%d_1.ESD.tag.root", run, evt) ;
385 TFile * tagFile = TFile::Open(fileName) ;
387 AliError(Form("File %s not found", fileName)) ;
390 TTree * tagTree = dynamic_cast<TTree *>(tagFile->Get("T")) ;
392 AliError(Form("Tree T not found in %s", fileName)) ;
396 AliRunTag * tag = new AliRunTag ;
397 tagTree->SetBranchAddress("AliTAG", &tag) ;
398 tagTree->GetEntry(evt) ;
399 AliQA * qa = AliQA::Instance(tag->GetQALength(), tag->GetQA(), tag->GetESLength(), tag->GetEventSpecies()) ;
404 //_____________________________________________________________________________
405 AliQADataMaker * AliQAManager::GetQADataMaker(const Int_t iDet)
407 // get the quality assurance data maker for a detector
409 if (fQADataMaker[iDet]) {
410 fQADataMaker[iDet]->SetEventSpecie(fEventSpecie) ;
411 return fQADataMaker[iDet] ;
414 AliQADataMaker * qadm = NULL ;
416 if (iDet == AliQA::kGLOBAL) { //Global QA
417 qadm = new AliGlobalQADataMaker();
418 qadm->SetName(AliQA::GetDetName(iDet));
419 qadm->SetUniqueID(iDet);
420 fQADataMaker[iDet] = qadm;
421 qadm->SetEventSpecie(fEventSpecie) ;
425 if (iDet == AliQA::kCORR) { //the data maker for correlations among detectors
426 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
427 qadm->SetName(AliQA::GetDetName(iDet));
428 qadm->SetUniqueID(iDet);
429 fQADataMaker[iDet] = qadm;
430 qadm->SetEventSpecie(fEventSpecie) ;
434 // load the QA data maker object
435 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
436 TString detName = AliQA::GetDetName(iDet) ;
438 if (tmp.Contains("sim"))
439 tmp.ReplaceAll("s", "S") ;
440 else if (tmp.Contains("rec"))
441 tmp.ReplaceAll("r", "R") ;
443 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
445 // first check if a plugin is defined for the quality assurance data maker
446 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
447 // if not, add a plugin for it
448 if (!pluginHandler) {
449 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
450 TString libs = gSystem->GetLibraries() ;
451 if (libs.Contains("lib" + detName + fMode + ".so") || (gSystem->Load("lib" + detName + fMode + ".so") >= 0)) {
452 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
454 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
456 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
458 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
459 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
462 qadm->SetName(AliQA::GetDetName(iDet));
463 qadm->SetUniqueID(iDet);
464 fQADataMaker[iDet] = qadm ;
465 qadm->SetEventSpecie(fEventSpecie) ;
471 //_____________________________________________________________________________
472 void AliQAManager::EndOfCycle(TObjArray * detArray)
474 // End of cycle QADataMakers
476 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
477 if (IsSelected(AliQA::GetDetName(iDet))) {
478 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
481 // skip non active detectors
483 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
484 if (!det || !det->IsActive())
487 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
488 if ( fTasks.Contains(Form("%d", taskIndex)) )
489 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
496 //_____________________________________________________________________________
497 void AliQAManager::EndOfCycle(TString detectors)
499 // End of cycle QADataMakers
501 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
502 if (IsSelected(AliQA::GetDetName(iDet))) {
503 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
506 // skip non active detectors
507 if (!detectors.Contains(AliQA::GetDetName(iDet)))
509 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
510 if ( fTasks.Contains(Form("%d", taskIndex)) )
511 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
518 //_____________________________________________________________________________
519 void AliQAManager::Increment()
521 // Increments the cycle counter for all QA Data Makers
522 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
523 if (IsSelected(AliQA::GetDetName(iDet))) {
524 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
531 //_____________________________________________________________________________
532 Bool_t AliQAManager::InitQA(const AliQA::TASKINDEX_t taskIndex, const char * input )
534 // Initialize the event source and QA data makers
536 fTasks += Form("%d", taskIndex) ;
538 if (taskIndex == AliQA::kRAWS) {
540 fRawReader = AliRawReader::Create(input);
544 fRawReaderDelete = kTRUE ;
545 fRawReader->NextEvent() ;
546 fRunNumber = fRawReader->GetRunNumber() ;
548 fRawReader->RewindEvents();
549 fNumberOfEvents = 999999 ;
550 if ( fMaxEvents < 0 )
551 fMaxEvents = fNumberOfEvents ;
552 } else if (taskIndex == AliQA::kESDS) {
553 fTasks = AliQA::GetTaskName(AliQA::kESDS) ;
554 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
555 TFile * esdFile = TFile::Open("AliESDs.root") ;
556 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
558 AliError("esdTree not found") ;
561 fESD = new AliESDEvent() ;
562 fESD->ReadFromTree(fESDTree) ;
563 fESDTree->GetEntry(0) ;
564 fRunNumber = fESD->GetRunNumber() ;
565 fNumberOfEvents = fESDTree->GetEntries() ;
566 if ( fMaxEvents < 0 )
567 fMaxEvents = fNumberOfEvents ;
570 AliError("AliESDs.root not found") ;
574 if ( !InitRunLoader() ) {
575 AliWarning("No Run Loader not found") ;
577 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
578 if ( fMaxEvents < 0 )
579 fMaxEvents = fNumberOfEvents ;
584 TObjArray* detArray = NULL ;
585 if (fRunLoader) // check if RunLoader exists
586 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
587 detArray = fRunLoader->GetAliRun()->Detectors() ;
588 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
591 // Initialize all QA data makers for all detectors
592 fRunNumber = AliCDBManager::Instance()->GetRun() ;
593 if ( ! AliGeomManager::GetGeometry() )
594 AliGeomManager::LoadGeometry() ;
596 InitQADataMaker(fRunNumber, detArray) ; //, fCycleSame, kTRUE, detArray) ;
600 //_____________________________________________________________________________
601 void AliQAManager::InitQADataMaker(UInt_t run, TObjArray * detArray)
603 // Initializes The QADataMaker for all active detectors and for all active tasks
604 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
605 if (IsSelected(AliQA::GetDetName(iDet))) {
606 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
608 AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
609 fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ;
611 if (fQAWriteExpert[iDet])
612 qadm->SetWriteExpert() ;
613 AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ;
614 // skip non active detectors
616 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
617 if (!det || !det->IsActive())
620 if (fQAWriteExpert[iDet]) qadm->SetWriteExpert() ;
621 // Set default reco params
622 Bool_t sameCycle = kFALSE ;
623 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
624 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
625 qadm->Init(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), GetQACycles(qadm->GetUniqueID())) ;
626 qadm->StartOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), run, sameCycle) ;
636 //_____________________________________________________________________________
637 Bool_t AliQAManager::InitRunLoader()
639 // get or create the run loader
643 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
644 // load all base libraries to get the loader classes
645 TString libs = gSystem->GetLibraries() ;
646 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
647 if (!IsSelected(AliQA::GetDetName(iDet)))
649 TString detName = AliQA::GetDetName(iDet) ;
650 if (detName == "HLT")
652 if (libs.Contains("lib" + detName + "base.so"))
654 gSystem->Load("lib" + detName + "base.so");
656 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
658 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
661 fRunLoader->CdGAFile();
662 if (fRunLoader->LoadgAlice() == 0) {
663 gAlice = fRunLoader->GetAliRun();
667 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
671 } else { // galice.root does not exist
672 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
678 fRunLoader->LoadHeader();
679 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
684 //_____________________________________________________________________________
685 Bool_t AliQAManager::IsSelected(const char * det)
687 // check whether detName is contained in detectors
688 // if yes, it is removed from detectors
691 const TString detName(det) ;
692 // always activates Correlation
693 if ( detName.Contains(AliQA::GetDetName(AliQA::kCORR))) {
696 // check if all detectors are selected
697 if (fDetectors.Contains("ALL")) {
700 } else if ((fDetectors.CompareTo(detName) == 0) ||
701 fDetectors.BeginsWith(detName+" ") ||
702 fDetectors.EndsWith(" "+detName) ||
703 fDetectors.Contains(" "+detName+" ")) {
710 //_____________________________________________________________________________
711 Bool_t AliQAManager::Merge(const Int_t runNumber) const
713 // Merge data from all the cycles from all detectors in one single file per run
714 // Merge the QA results from all the data chunks in one run
715 Bool_t rv = MergeData(runNumber) ;
716 rv *= MergeResults(runNumber) ;
720 //______________________________________________________________________
721 Bool_t AliQAManager::MergeXML(const char * collectionFile, const char * subFile, const char * outFile)
723 // merges files listed in a xml collection
724 // usage Merge(collection, outputFile))
725 // collection: is a xml collection
729 if ( strstr(collectionFile, ".xml") == 0 ) {
730 AliError("Input collection file must be an \".xml\" file\n") ;
735 TGrid::Connect("alien://");
739 // Open the file collection
740 printf("*** Create Collection ***\n");
741 printf("*** Wk-Dir = |%s| \n",gSystem->WorkingDirectory());
742 printf("*** Coll = |%s| \n",collectionFile);
744 TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)",collectionFile));
745 TGridResult* result = collection->GetGridResult("", 0, 0);
751 TString tempo(collectionFile) ;
753 tempo.ReplaceAll(".xml", subFile) ;
755 tempo.ReplaceAll(".xml", "_Merged.root") ;
756 outFile = tempo.Data() ;
758 merger.OutputFile(outFile) ;
760 while ( (turl = result->GetKey(index, "turl")) ) {
763 file = Form("%s#%s", turl, subFile) ;
765 file = Form("%s", turl) ;
767 AliInfo(Form("%s\n", file)) ;
768 merger.AddFile(file) ;
775 AliInfo(Form("Files merged into %s\n", outFile)) ;
781 //_____________________________________________________________________________
782 Bool_t AliQAManager::MergeData(const Int_t runNumber) const
784 // Merge all the cycles from all detectors in one single file per run
787 cmd = Form(".! ls *%s*.%d.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
789 cmd = Form(".! ls *%s*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
790 gROOT->ProcessLine(cmd.Data()) ;
791 ifstream in("tempo.txt") ;
792 const Int_t runMax = 10 ;
793 TString file[AliQA::kNDET*runMax] ;
800 AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ;
805 AliError(Form("run number %d not found", runNumber)) ;
810 TString outFileName ;
812 outFileName = Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),runNumber);
814 outFileName = Form("Merged.%s.Data.root",AliQA::GetQADataFileName());
815 merger.OutputFile(outFileName.Data()) ;
816 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
817 TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), runNumber));
818 TString tmp(file[ifile]) ;
819 if (tmp.Contains(pattern)) {
820 merger.AddFile(tmp) ;
827 //_____________________________________________________________________________
828 Bool_t AliQAManager::MergeResults(const Int_t runNumber) const
830 // Merge the QA result from all the data chunks in a run
832 cmd = Form(".! ls %s*.root > tempo.txt", AliQA::GetQADataFileName()) ;
833 gROOT->ProcessLine(cmd.Data()) ;
834 ifstream in("tempo.txt") ;
835 const Int_t chunkMax = 100 ;
836 TString fileList[chunkMax] ;
841 in >> fileList[index] ;
844 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
849 AliError("No QA Result File found") ;
854 TString outFileName ;
856 outFileName = Form("Merged.%s.Result.%d.root",AliQA::GetQADataFileName(),runNumber);
858 outFileName = Form("Merged.%s.Result.root",AliQA::GetQADataFileName());
859 merger.OutputFile(outFileName.Data()) ;
860 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
861 TString file = fileList[ifile] ;
862 merger.AddFile(file) ;
869 //_____________________________________________________________________________
870 void AliQAManager::Reset(const Bool_t sameCycle)
872 // Reset the default data members
874 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
875 if (IsSelected(AliQA::GetDetName(iDet))) {
876 AliQADataMaker * qadm = GetQADataMaker(iDet);
880 if (fRawReaderDelete) {
885 fCycleSame = sameCycle ;
889 fNumberOfEvents = 999999 ;
892 //_____________________________________________________________________________
893 AliQAManager * AliQAManager::QAManager(const Char_t * mode, TMap *entryCache, Int_t run)
895 // returns AliQAManager instance (singleton)
898 fgQAInstance = new AliQAManager(mode) ;
900 fgQAInstance->Init();
902 fgQAInstance->InitFromCache(entryCache,run);
907 //_____________________________________________________________________________
908 TString AliQAManager::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
910 //Runs all the QA data Maker for Raws only
912 fCycleSame = sameCycle ;
913 fRawReader = rawReader ;
914 fDetectors = detectors ;
915 fDetectorsW = detectors ;
917 AliCDBManager* man = AliCDBManager::Instance() ;
919 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
920 rawReader->NextEvent() ;
921 man->SetRun(fRawReader->GetRunNumber()) ;
922 rawReader->RewindEvents() ;
926 if ( !InitQA(AliQA::kRAWS) )
928 fRawReaderDelete = kFALSE ;
934 //_____________________________________________________________________________
935 TString AliQAManager::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
937 //Runs all the QA data Maker for Raws only
939 fCycleSame = sameCycle ;
940 fDetectors = detectors ;
941 fDetectorsW = detectors ;
943 AliCDBManager* man = AliCDBManager::Instance() ;
944 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
945 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
947 AliFatal("galice.root file not found in current directory") ;
951 if ( ! rl->GetAliRun() ) {
952 AliFatal("AliRun not found in galice.root") ;
955 man->SetRun(rl->GetHeader()->GetRun());
961 if ( !InitQA(AliQA::kRAWS, fileName) )
968 //_____________________________________________________________________________
969 TString AliQAManager::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
971 // Runs all the QA data Maker for every detector
973 fCycleSame = sameCycle ;
974 fDetectors = detectors ;
975 fDetectorsW = detectors ;
977 AliCDBManager* man = AliCDBManager::Instance() ;
978 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
979 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
981 AliFatal("galice.root file not found in current directory") ;
985 if ( ! rl->GetAliRun() ) {
986 AliInfo("AliRun not found in galice.root") ;
989 man->SetRun(rl->GetHeader()->GetRun()) ;
995 if ( taskIndex == AliQA::kNULLTASKINDEX) {
996 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
997 if ( fTasks.Contains(Form("%d", task)) ) {
999 if ( !InitQA(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
1001 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
1006 if ( !InitQA(taskIndex, fileName) )
1011 return fDetectorsW ;
1015 //_____________________________________________________________________________
1016 void AliQAManager::RunOneEvent(AliRawReader * rawReader)
1018 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
1021 AliCodeTimerAuto("") ;
1022 if (fTasks.Contains(Form("%d", AliQA::kRAWS))){
1023 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1024 if (!IsSelected(AliQA::GetDetName(iDet)))
1026 AliQADataMaker *qadm = GetQADataMaker(iDet);
1029 if ( qadm->IsCycleDone() ) {
1030 qadm->EndOfCycle() ;
1032 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
1033 qadm->SetEventSpecie(fEventSpecie) ;
1034 qadm->Exec(AliQA::kRAWS, rawReader) ;
1035 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
1040 //_____________________________________________________________________________
1041 void AliQAManager::RunOneEvent(AliESDEvent *& esd)
1043 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
1045 AliCodeTimerAuto("") ;
1046 if (fTasks.Contains(Form("%d", AliQA::kESDS))) {
1047 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1048 if (!IsSelected(AliQA::GetDetName(iDet)))
1050 AliQADataMaker *qadm = GetQADataMaker(iDet);
1053 if ( qadm->IsCycleDone() ) {
1054 qadm->EndOfCycle() ;
1056 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
1057 qadm->Exec(AliQA::kESDS, esd) ;
1058 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
1063 //_____________________________________________________________________________
1064 void AliQAManager::RunOneEventInOneDetector(Int_t det, TTree * tree)
1066 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
1067 AliCodeTimerAuto("") ;
1068 if (fTasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
1069 if (IsSelected(AliQA::GetDetName(det))) {
1070 AliQADataMaker *qadm = GetQADataMaker(det);
1072 if ( qadm->IsCycleDone() ) {
1073 qadm->EndOfCycle() ;
1075 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
1076 qadm->Exec(AliQA::kRECPOINTS, tree) ;
1077 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
1083 //_____________________________________________________________________________
1084 Bool_t AliQAManager::Save2OCDB(const Int_t runNumber, AliRecoParam::EventSpecie_t es, const char * year, const char * detectors) const
1086 // take the locasl QA data merge into a single file and save in OCDB
1088 TString tmp(AliQA::GetQARefStorage()) ;
1089 if ( tmp.IsNull() ) {
1090 AliError("No storage defined, use AliQA::SetQARefStorage") ;
1093 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
1094 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
1097 TString sdet(detectors) ;
1100 if ( sdet.Contains("ALL") ) {
1101 rv = Merge(runNumber) ;
1104 TString inputFileName(Form("Merged.%s.Data.%d.root", AliQA::GetQADataFileName(), runNumber)) ;
1105 inputFile = TFile::Open(inputFileName.Data()) ;
1106 rv = SaveIt2OCDB(runNumber, inputFile, year, es) ;
1108 for (Int_t index = 0; index < AliQA::kNDET; index++) {
1109 if (sdet.Contains(AliQA::GetDetName(index))) {
1110 TString inputFileName(Form("%s.%s.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber)) ;
1111 inputFile = TFile::Open(inputFileName.Data()) ;
1112 rv *= SaveIt2OCDB(runNumber, inputFile, year, es) ;
1119 //_____________________________________________________________________________
1120 Bool_t AliQAManager::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year, AliRecoParam::EventSpecie_t es) const
1122 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
1124 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
1125 if ( ! IsDefaultStorageSet() ) {
1126 TString tmp( AliQA::GetQARefStorage() ) ;
1127 if ( tmp.Contains(AliQA::GetLabLocalOCDB()) )
1128 Instance()->SetDefaultStorage(AliQA::GetQARefStorage()) ;
1130 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
1132 tmp1.Append("?user=alidaq") ;
1133 Instance()->SetDefaultStorage(tmp1.Data()) ;
1136 Instance()->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
1138 Instance()->SetRun(runNumber);
1140 AliCDBMetaData mdr ;
1141 mdr.SetResponsible("yves schutz");
1143 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
1144 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
1146 AliInfo(Form("Entering %s", detDir->GetName())) ;
1147 AliQA::SetQARefDataDirName(es) ;
1148 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ;
1149 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
1150 TList * listDetQAD = new TList() ;
1151 TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ;
1152 mdr.SetComment(Form("%s QA stuff", AliQA::GetDetName(detIndex)));
1153 listDetQAD->SetName(listName) ;
1154 TList * taskList = detDir->GetListOfKeys() ;
1155 TIter nextTask(taskList) ;
1157 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
1158 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
1159 TDirectory * esDir = taskDir->GetDirectory(AliRecoParam::GetEventSpecieName(es)) ;
1160 AliInfo(Form("Saving %s", esDir->GetName())) ;
1161 TObjArray * listTaskQAD = new TObjArray(100) ;
1162 listTaskQAD->SetName(Form("%s/%s", taskKey->GetName(), AliRecoParam::GetEventSpecieName(es))) ;
1163 listDetQAD->Add(listTaskQAD) ;
1164 TList * histList = esDir->GetListOfKeys() ;
1165 TIter nextHist(histList) ;
1167 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
1168 TObject * odata = esDir->Get(histKey->GetName()) ;
1170 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1172 if ( AliQA::GetExpert() == histKey->GetName() ) {
1173 TDirectory * expertDir = esDir->GetDirectory(histKey->GetName()) ;
1174 TList * expertHistList = expertDir->GetListOfKeys() ;
1175 TIter nextExpertHist(expertHistList) ;
1176 TKey * expertHistKey ;
1177 while ( (expertHistKey = dynamic_cast<TKey*>(nextExpertHist())) ) {
1178 TObject * expertOdata = expertDir->Get(expertHistKey->GetName()) ;
1179 if ( !expertOdata ) {
1180 AliError(Form("%s in %s/%s/Expert returns a NULL pointer !!", expertHistKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
1182 AliInfo(Form("Adding %s", expertHistKey->GetName())) ;
1183 if ( expertOdata->IsA()->InheritsFrom("TH1") ) {
1184 AliInfo(Form("Adding %s", expertHistKey->GetName())) ;
1185 TH1 * hExpertdata = static_cast<TH1*>(expertOdata) ;
1186 listTaskQAD->Add(hExpertdata) ;
1191 AliInfo(Form("Adding %s", histKey->GetName())) ;
1192 if ( odata->IsA()->InheritsFrom("TH1") ) {
1193 AliInfo(Form("Adding %s", histKey->GetName())) ;
1194 TH1 * hdata = static_cast<TH1*>(odata) ;
1195 listTaskQAD->Add(hdata) ;
1200 Instance()->Put(listDetQAD, idr, &mdr) ;
1206 //_____________________________________________________________________________
1207 void AliQAManager::SetEventSpecie(AliRecoParam::EventSpecie_t es)
1209 // set the current event specie and inform AliQA that this event specie has been encountered
1211 AliQA::Instance()->SetEventSpecie(es) ;
1214 //_____________________________________________________________________________
1215 void AliQAManager::SetRecoParam(const Int_t det, const AliDetectorRecoParam *par)
1217 // Set custom reconstruction parameters for a given detector
1218 // Single set of parameters for all the events
1219 GetQADataMaker(det)->SetRecoParam(par) ;