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 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // class for running the QA makers //
21 // AliQADataMakerSteer 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 "AliQADataMakerSteer.h"
56 #include "AliRawReaderDate.h"
57 #include "AliRawReaderFile.h"
58 #include "AliRawReaderRoot.h"
60 #include "AliRunLoader.h"
62 ClassImp(AliQADataMakerSteer)
64 //_____________________________________________________________________________
65 AliQADataMakerSteer::AliQADataMakerSteer(char * mode, const char* gAliceFilename, const char * name, const char * title) :
73 fGAliceFileName(gAliceFilename),
77 fNumberOfEvents(999999),
81 fRawReaderDelete(kTRUE),
86 fMaxEvents = fNumberOfEvents ;
87 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
88 if (IsSelected(AliQA::GetDetName(iDet))) {
89 fLoader[iDet] = NULL ;
90 fQADataMaker[iDet] = NULL ;
91 fQACycles[iDet] = 999999 ;
96 //_____________________________________________________________________________
97 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
99 fCurrentEvent(qas.fCurrentEvent),
101 fDetectors(qas.fDetectors),
102 fDetectorsW(qas.fDetectorsW),
105 fGAliceFileName(qas.fGAliceFileName),
106 fFirstEvent(qas.fFirstEvent),
107 fMaxEvents(qas.fMaxEvents),
109 fNumberOfEvents(qas.fNumberOfEvents),
111 fRunNumber(qas.fRunNumber),
113 fRawReaderDelete(kTRUE),
118 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
119 fLoader[iDet] = qas.fLoader[iDet] ;
120 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
121 fQACycles[iDet] = qas.fQACycles[iDet] ;
125 //_____________________________________________________________________________
126 AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
128 // assignment operator
129 this->~AliQADataMakerSteer() ;
130 new(this) AliQADataMakerSteer(qas) ;
134 //_____________________________________________________________________________
135 AliQADataMakerSteer::~AliQADataMakerSteer()
138 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
139 if (IsSelected(AliQA::GetDetName(iDet))) {
140 fLoader[iDet] = NULL;
141 if (fQADataMaker[iDet]) {
142 (fQADataMaker[iDet])->Finish() ;
143 delete fQADataMaker[iDet] ;
147 if (fRawReaderDelete) {
154 //_____________________________________________________________________________
155 Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX_t taskIndex)
157 // Runs all the QA data Maker for every detector
160 // Fill QA data in event loop
161 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
164 if ( iEvent%10 == 0 )
165 AliInfo(Form("processing event %d", iEvent));
166 if ( taskIndex == AliQA::kRAWS ) {
167 if ( !fRawReader->NextEvent() )
169 } else if ( taskIndex == AliQA::kESDS ) {
170 if ( fESDTree->GetEntry(iEvent) == 0 )
173 if ( fRunLoader->GetEvent(iEvent) != 0 )
176 // loop over active loaders
177 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
178 if (IsSelected(AliQA::GetDetName(iDet))) {
179 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
180 if ( qadm->IsCycleDone() ) {
181 qadm->EndOfCycle(AliQA::kRAWS) ;
182 qadm->StartOfCycle(AliQA::kRAWS) ;
185 AliLoader* loader = GetLoader(qadm->GetUniqueID());
187 case AliQA::kNULLTASKINDEX :
190 qadm->Exec(taskIndex, fRawReader) ;
194 data = loader->TreeH() ;
196 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
198 qadm->Exec(taskIndex, data) ;
201 case AliQA::kSDIGITS :
202 loader->LoadSDigits() ;
203 data = loader->TreeS() ;
205 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
207 qadm->Exec(taskIndex, data) ;
210 case AliQA::kDIGITS :
211 loader->LoadDigits() ;
212 data = loader->TreeD() ;
214 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
216 qadm->Exec(taskIndex, data) ;
219 case AliQA::kRECPOINTS :
220 loader->LoadRecPoints() ;
221 data = loader->TreeR() ;
223 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
225 qadm->Exec(taskIndex, data) ;
228 case AliQA::kTRACKSEGMENTS :
230 case AliQA::kRECPARTICLES :
233 qadm->Exec(taskIndex, fESD) ;
235 case AliQA::kNTASKINDEX :
241 // Save QA data for all detectors
242 rv = Finish(taskIndex) ;
244 if ( taskIndex == AliQA::kRAWS )
245 fRawReader->RewindEvents() ;
250 //_____________________________________________________________________________
251 Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX_t taskIndex)
253 // write output to file for all detectors
254 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
255 if (IsSelected(AliQA::GetDetName(iDet))) {
256 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
257 qadm->EndOfCycle(taskIndex) ;
263 //_____________________________________________________________________________
264 TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const
266 // Retrieve the list of QA data for a given detector and a given task
267 TObjArray * rv = NULL ;
268 if ( !strlen(AliQA::GetQARefStorage()) ) {
269 AliError("No storage defined, use AliQA::SetQARefStorage") ;
272 AliCDBManager* man = AliCDBManager::Instance() ;
273 if ( ! man->IsDefaultStorageSet() ) {
274 TString tmp(AliQA::GetQARefDefaultStorage()) ;
277 man->SetDefaultStorage(tmp.Data()) ;
278 man->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
280 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ;
281 AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ;
282 AliCDBEntry* entry = man->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
283 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
285 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
289 //_____________________________________________________________________________
290 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
292 // get the loader for a detector
297 TString detName = AliQA::GetDetName(iDet) ;
298 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
300 return fLoader[iDet] ;
302 // load the QA data maker object
303 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
304 TString loaderName = "Ali" + detName + "Loader" ;
306 AliLoader * loader = NULL ;
307 // first check if a plugin is defined for the quality assurance data maker
308 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
309 // if not, add a plugin for it
310 if (!pluginHandler) {
311 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
312 TString libs = gSystem->GetLibraries() ;
313 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
314 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
316 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
318 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
320 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
321 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
324 fLoader[iDet] = loader ;
328 //_____________________________________________________________________________
329 AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet)
331 // get the quality assurance data maker for a detector
333 if (fQADataMaker[iDet])
334 return fQADataMaker[iDet] ;
336 AliQADataMaker * qadm = NULL ;
338 if (iDet == AliQA::kGLOBAL) { //Global QA
339 qadm = new AliGlobalQADataMaker();
340 qadm->SetName(AliQA::GetDetName(iDet));
341 qadm->SetUniqueID(iDet);
342 fQADataMaker[iDet] = qadm;
346 if (iDet == AliQA::kCORR) { //the data maker for correlations among detectors
347 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
348 qadm->SetName(AliQA::GetDetName(iDet));
349 qadm->SetUniqueID(iDet);
350 fQADataMaker[iDet] = qadm;
354 // load the QA data maker object
355 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
356 TString detName = AliQA::GetDetName(iDet) ;
358 if (tmp.Contains("sim"))
359 tmp.ReplaceAll("s", "S") ;
360 else if (tmp.Contains("rec"))
361 tmp.ReplaceAll("r", "R") ;
363 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
365 // first check if a plugin is defined for the quality assurance data maker
366 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
367 // if not, add a plugin for it
368 if (!pluginHandler) {
369 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
370 TString libs = gSystem->GetLibraries() ;
371 if (libs.Contains("lib" + detName + fMode + ".so") || (gSystem->Load("lib" + detName + fMode + ".so") >= 0)) {
372 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
374 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
376 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
378 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
379 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
382 qadm->SetName(AliQA::GetDetName(iDet));
383 qadm->SetUniqueID(iDet);
384 fQADataMaker[iDet] = qadm ;
390 //_____________________________________________________________________________
391 void AliQADataMakerSteer::EndOfCycle(TObjArray * detArray)
393 // End of cycle QADataMakers
395 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
396 if (IsSelected(AliQA::GetDetName(iDet))) {
397 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
400 // skip non active detectors
402 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
403 if (!det || !det->IsActive())
406 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
407 if ( fTasks.Contains(Form("%d", taskIndex)) )
408 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
415 //_____________________________________________________________________________
416 Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX_t taskIndex, const char * input )
418 // Initialize the event source and QA data makers
420 //fTasks = AliQA::GetTaskName(taskIndex) ;
422 if (taskIndex == AliQA::kRAWS) {
424 fRawReader = AliRawReader::Create(input);
428 fRawReaderDelete = kTRUE ;
429 fRawReader->NextEvent() ;
430 fRunNumber = fRawReader->GetRunNumber() ;
431 AliCDBManager::Instance()->SetRun(fRunNumber) ;
432 fRawReader->RewindEvents();
433 fNumberOfEvents = 999999 ;
434 if ( fMaxEvents < 0 )
435 fMaxEvents = fNumberOfEvents ;
436 } else if (taskIndex == AliQA::kESDS) {
437 fTasks = AliQA::GetTaskName(AliQA::kESDS) ;
438 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
439 TFile * esdFile = TFile::Open("AliESDs.root") ;
440 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
442 AliError("esdTree not found") ;
445 fESD = new AliESDEvent() ;
446 fESD->ReadFromTree(fESDTree) ;
447 fESDTree->GetEntry(0) ;
448 fRunNumber = fESD->GetRunNumber() ;
449 fNumberOfEvents = fESDTree->GetEntries() ;
450 if ( fMaxEvents < 0 )
451 fMaxEvents = fNumberOfEvents ;
454 AliError("AliESDs.root not found") ;
458 if ( !InitRunLoader() ) {
459 AliWarning("No Run Loader not found") ;
461 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
462 if ( fMaxEvents < 0 )
463 fMaxEvents = fNumberOfEvents ;
468 TObjArray* detArray = NULL ;
469 if (fRunLoader) // check if RunLoader exists
470 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
471 detArray = fRunLoader->GetAliRun()->Detectors() ;
472 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
475 // Initialize all QA data makers for all detectors
476 fRunNumber = AliCDBManager::Instance()->GetRun() ;
477 if ( ! AliGeomManager::GetGeometry() )
478 AliGeomManager::LoadGeometry() ;
480 InitQADataMaker(fRunNumber, fRecoParam, fCycleSame, kTRUE, detArray) ;
484 //_____________________________________________________________________________
485 void AliQADataMakerSteer::InitQADataMaker(UInt_t run, const AliRecoParam & par, Bool_t sameCycle, Bool_t startOption, TObjArray * detArray)
487 // Initializes The QADataMaker for all active detectors and for all active tasks
489 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
490 if (IsSelected(AliQA::GetDetName(iDet))) {
491 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
493 AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
494 fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ;
496 AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ;
497 // skip non active detectors
499 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
500 if (!det || !det->IsActive())
503 // Set default reco params
504 qadm->SetRecoParam(par.GetDetRecoParam(iDet));
505 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
506 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
507 qadm->Init(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), run, GetQACycles(qadm->GetUniqueID())) ;
509 qadm->StartOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), sameCycle) ;
520 //_____________________________________________________________________________
521 Bool_t AliQADataMakerSteer::InitRunLoader()
523 // get or create the run loader
527 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
528 // load all base libraries to get the loader classes
529 TString libs = gSystem->GetLibraries() ;
530 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
531 if (!IsSelected(AliQA::GetDetName(iDet)))
533 TString detName = AliQA::GetDetName(iDet) ;
534 if (detName == "HLT")
536 if (libs.Contains("lib" + detName + "base.so"))
538 gSystem->Load("lib" + detName + "base.so");
540 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
542 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
545 fRunLoader->CdGAFile();
546 if (fRunLoader->LoadgAlice() == 0) {
547 gAlice = fRunLoader->GetAliRun();
551 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
555 } else { // galice.root does not exist
556 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
562 fRunLoader->LoadHeader();
563 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
568 //_____________________________________________________________________________
569 Bool_t AliQADataMakerSteer::IsSelected(const char * det)
571 // check whether detName is contained in detectors
572 // if yes, it is removed from detectors
575 const TString detName(det) ;
576 // always activates Correlation
577 if ( detName.Contains(AliQA::GetDetName(AliQA::kCORR))) {
580 // check if all detectors are selected
581 if (fDetectors.Contains("ALL")) {
584 } else if ((fDetectors.CompareTo(detName) == 0) ||
585 fDetectors.BeginsWith(detName+" ") ||
586 fDetectors.EndsWith(" "+detName) ||
587 fDetectors.Contains(" "+detName+" ")) {
594 //_____________________________________________________________________________
595 Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
597 // Merge data from all the cycles from all detectors in one single file per run
598 // Merge the QA results from all the data chunks in one run
599 Bool_t rv = MergeData(runNumber) ;
600 rv *= MergeResults(runNumber) ;
605 //_____________________________________________________________________________
606 Bool_t AliQADataMakerSteer::MergeData(const Int_t runNumber) const
608 // Merge all the cycles from all detectors in one single file per run
611 cmd = Form(".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
613 cmd = Form(".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
614 gROOT->ProcessLine(cmd.Data()) ;
615 ifstream in("tempo.txt") ;
616 const Int_t runMax = 10 ;
617 TString file[AliQA::kNDET*runMax] ;
618 Int_t run[AliQA::kNDET*runMax] = {-1} ;
625 AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ;
630 AliError(Form("run number %d not found", runNumber)) ;
635 Int_t runIndexMax = 0 ;
636 TString stmp(Form(".%s.", AliQA::GetQADataFileName())) ;
637 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
638 TString tmp(file[ifile]) ;
639 tmp.ReplaceAll(".root", "") ;
640 TString det = tmp(0, tmp.Index(".")) ;
641 tmp.Remove(0, tmp.Index(stmp)+4) ;
642 TString ttmp = tmp(0, tmp.Index(".")) ;
643 Int_t newRun = ttmp.Atoi() ;
644 for (Int_t irun = 0; irun <= runIndexMax; irun++) {
645 if (newRun == run[irun])
647 run[runIndex] = newRun ;
650 runIndexMax = runIndex ;
651 ttmp = tmp(tmp.Index(".")+1, tmp.Length()) ;
652 Int_t cycle = ttmp.Atoi() ;
653 AliDebug(1, Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ;
655 for (Int_t irun = 0 ; irun < runIndexMax ; irun++) {
657 TString outFileName(Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),run[irun]));
658 merger.OutputFile(outFileName.Data()) ;
659 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
660 TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), run[irun])) ;
661 TString tmp(file[ifile]) ;
662 if (tmp.Contains(pattern)) {
663 merger.AddFile(tmp) ;
672 //_____________________________________________________________________________
673 Bool_t AliQADataMakerSteer::MergeResults(const Int_t runNumber) const
675 // Merge the QA result from all the data chunks in a run
677 cmd = Form(".! ls %s*.root > tempo.txt", AliQA::GetQADataFileName()) ;
678 gROOT->ProcessLine(cmd.Data()) ;
679 ifstream in("tempo.txt") ;
680 const Int_t chunkMax = 100 ;
681 TString fileList[chunkMax] ;
686 in >> fileList[index] ;
689 AliInfo(Form("index = %d file = %s", index, (fileList[index].Data()))) ;
694 AliError("No QA Result File found") ;
699 TString outFileName(Form("Merged.%s.Result.%d.root", AliQA::GetQADataFileName(), runNumber));
700 merger.OutputFile(outFileName.Data()) ;
701 for (Int_t ifile = 0 ; ifile < index ; ifile++) {
702 TString file = fileList[ifile] ;
703 merger.AddFile(file) ;
710 //_____________________________________________________________________________
711 void AliQADataMakerSteer::Reset(const Bool_t sameCycle)
713 // Reset the default data members
715 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
716 if (IsSelected(AliQA::GetDetName(iDet))) {
717 AliQADataMaker * qadm = GetQADataMaker(iDet);
718 qadm->Reset(sameCycle);
721 if (fRawReaderDelete) {
726 fCycleSame = sameCycle ;
730 fNumberOfEvents = 999999 ;
733 //_____________________________________________________________________________
734 TString AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader, const Bool_t sameCycle)
736 //Runs all the QA data Maker for Raws only
738 fCycleSame = sameCycle ;
739 fRawReader = rawReader ;
740 fDetectors = detectors ;
741 fDetectorsW = detectors ;
743 AliCDBManager* man = AliCDBManager::Instance() ;
745 if ( man->GetRun() == -1 ) {// check if run number not set previously and set it from raw data
746 rawReader->NextEvent() ;
747 man->SetRun(fRawReader->GetRunNumber()) ;
748 rawReader->RewindEvents() ;
751 if ( !Init(AliQA::kRAWS) )
753 fRawReaderDelete = kFALSE ;
759 //_____________________________________________________________________________
760 TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName, const Bool_t sameCycle)
762 //Runs all the QA data Maker for Raws only
764 fCycleSame = sameCycle ;
765 fDetectors = detectors ;
766 fDetectorsW = detectors ;
768 AliCDBManager* man = AliCDBManager::Instance() ;
769 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
770 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
772 AliFatal("galice.root file not found in current directory") ;
776 if ( ! rl->GetAliRun() ) {
777 AliFatal("AliRun not found in galice.root") ;
780 man->SetRun(rl->GetHeader()->GetRun());
785 if ( !Init(AliQA::kRAWS, fileName) )
792 //_____________________________________________________________________________
793 TString AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX_t taskIndex, Bool_t const sameCycle, const char * fileName )
795 // Runs all the QA data Maker for every detector
797 fCycleSame = sameCycle ;
798 fDetectors = detectors ;
799 fDetectorsW = detectors ;
801 AliCDBManager* man = AliCDBManager::Instance() ;
802 if ( man->GetRun() == -1 ) { // check if run number not set previously and set it from AliRun
803 AliRunLoader * rl = AliRunLoader::Open("galice.root") ;
805 AliFatal("galice.root file not found in current directory") ;
809 if ( ! rl->GetAliRun() ) {
810 AliInfo("AliRun not found in galice.root") ;
813 man->SetRun(rl->GetHeader()->GetRun()) ;
819 if ( taskIndex == AliQA::kNULLTASKINDEX) {
820 for (UInt_t task = 0; task < AliQA::kNTASKINDEX; task++) {
821 if ( fTasks.Contains(Form("%d", task)) ) {
822 if ( !Init(AliQA::GetTaskIndex(AliQA::GetTaskName(task)), fileName) )
824 DoIt(AliQA::GetTaskIndex(AliQA::GetTaskName(task))) ;
828 if ( !Init(taskIndex, fileName) )
837 //_____________________________________________________________________________
838 void AliQADataMakerSteer::RunOneEvent(AliRawReader * rawReader)
840 //Runs all the QA data Maker for Raws only and on one event only (event loop done by calling method)
842 AliCodeTimerAuto("") ;
843 if (fTasks.Contains(Form("%d", AliQA::kRAWS))){
844 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
845 if (!IsSelected(AliQA::GetDetName(iDet)))
847 AliQADataMaker *qadm = GetQADataMaker(iDet);
850 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
851 qadm->Exec(AliQA::kRAWS, rawReader) ;
852 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
857 //_____________________________________________________________________________
858 void AliQADataMakerSteer::RunOneEvent(AliESDEvent *& esd)
860 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
862 AliCodeTimerAuto("") ;
863 if (fTasks.Contains(Form("%d", AliQA::kESDS))) {
864 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
865 if (!IsSelected(AliQA::GetDetName(iDet)))
867 AliQADataMaker *qadm = GetQADataMaker(iDet);
870 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
871 qadm->Exec(AliQA::kESDS, esd) ;
872 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
877 //_____________________________________________________________________________
878 void AliQADataMakerSteer::RunOneEventInOneDetector(Int_t det, TTree * tree)
880 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
881 AliCodeTimerAuto("") ;
882 if (fTasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
883 if (!IsSelected(AliQA::GetDetName(det))) {
884 AliQADataMaker *qadm = GetQADataMaker(det);
886 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
887 qadm->Exec(AliQA::kRECPOINTS, tree) ;
888 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
894 //_____________________________________________________________________________
895 Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const char * year, const Int_t cycleNumber, const char * detectors) const
897 // take the locasl QA data merge into a single file and save in OCDB
899 TString tmp(AliQA::GetQARefStorage()) ;
900 if ( tmp.IsNull() ) {
901 AliError("No storage defined, use AliQA::SetQARefStorage") ;
904 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
905 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
908 TString sdet(detectors) ;
911 if ( sdet.Contains("ALL") ) {
912 rv = Merge(runNumber) ;
915 TString inputFileName(Form("Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber)) ;
916 inputFile = TFile::Open(inputFileName.Data()) ;
917 rv = SaveIt2OCDB(runNumber, inputFile, year) ;
919 for (Int_t index = 0; index < AliQA::kNDET; index++) {
920 if (sdet.Contains(AliQA::GetDetName(index))) {
921 TString inputFileName(Form("%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber)) ;
922 inputFile = TFile::Open(inputFileName.Data()) ;
923 rv *= SaveIt2OCDB(runNumber, inputFile, year) ;
930 //_____________________________________________________________________________
931 Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year) const
933 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
935 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
936 AliCDBManager* man = AliCDBManager::Instance() ;
937 if ( ! man->IsDefaultStorageSet() ) {
938 TString tmp( AliQA::GetQARefStorage() ) ;
939 if ( tmp.Contains(AliQA::GetLabLocalOCDB()) )
940 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
942 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
944 tmp1.Append("?user=alidaq") ;
945 man->SetDefaultStorage(tmp1.Data()) ;
948 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
949 if(man->GetRun() < 0)
950 man->SetRun(runNumber);
953 mdr.SetResponsible("yves schutz");
955 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
956 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
958 AliInfo(Form("Entering %s", detDir->GetName())) ;
959 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ;
960 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
961 TList * listDetQAD = new TList() ;
962 TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ;
963 mdr.SetComment("HMPID QA stuff");
964 listDetQAD->SetName(listName) ;
965 TList * taskList = detDir->GetListOfKeys() ;
966 TIter nextTask(taskList) ;
968 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
969 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
970 AliInfo(Form("Saving %s", taskDir->GetName())) ;
971 TObjArray * listTaskQAD = new TObjArray(100) ;
972 listTaskQAD->SetName(taskKey->GetName()) ;
973 listDetQAD->Add(listTaskQAD) ;
974 TList * histList = taskDir->GetListOfKeys() ;
975 TIter nextHist(histList) ;
977 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
978 TObject * odata = taskDir->Get(histKey->GetName()) ;
980 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
982 AliInfo(Form("Adding %s", histKey->GetName())) ;
983 if ( odata->IsA()->InheritsFrom("TH1") ) {
984 AliInfo(Form("Adding %s", histKey->GetName())) ;
985 TH1 * hdata = static_cast<TH1*>(odata) ;
986 listTaskQAD->Add(hdata) ;
991 man->Put(listDetQAD, idr, &mdr) ;
997 //_____________________________________________________________________________
998 void AliQADataMakerSteer::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
1000 // Set custom reconstruction parameters for a given detector
1001 // Single set of parameters for all the events
1002 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1003 if(!strcmp(detector, AliQA::GetDetName(iDet))) {
1004 par->SetAsDefault();
1005 fRecoParam.AddDetRecoParam(iDet,par);