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 ;
92 fQAWriteExpert[iDet] = kFALSE ;
97 //_____________________________________________________________________________
98 AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) :
100 fCurrentEvent(qas.fCurrentEvent),
102 fDetectors(qas.fDetectors),
103 fDetectorsW(qas.fDetectorsW),
106 fGAliceFileName(qas.fGAliceFileName),
107 fFirstEvent(qas.fFirstEvent),
108 fMaxEvents(qas.fMaxEvents),
110 fNumberOfEvents(qas.fNumberOfEvents),
112 fRunNumber(qas.fRunNumber),
114 fRawReaderDelete(kTRUE),
119 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
120 fLoader[iDet] = qas.fLoader[iDet] ;
121 fQADataMaker[iDet] = qas.fQADataMaker[iDet] ;
122 fQACycles[iDet] = qas.fQACycles[iDet] ;
123 fQAWriteExpert[iDet] = qas.fQAWriteExpert[iDet] ;
127 //_____________________________________________________________________________
128 AliQADataMakerSteer & AliQADataMakerSteer::operator = (const AliQADataMakerSteer & qas)
130 // assignment operator
131 this->~AliQADataMakerSteer() ;
132 new(this) AliQADataMakerSteer(qas) ;
136 //_____________________________________________________________________________
137 AliQADataMakerSteer::~AliQADataMakerSteer()
140 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
141 if (IsSelected(AliQA::GetDetName(iDet))) {
142 fLoader[iDet] = NULL;
143 if (fQADataMaker[iDet]) {
144 (fQADataMaker[iDet])->Finish() ;
145 delete fQADataMaker[iDet] ;
149 if (fRawReaderDelete) {
156 //_____________________________________________________________________________
157 Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX_t taskIndex)
159 // Runs all the QA data Maker for every detector
162 // Fill QA data in event loop
163 for (UInt_t iEvent = fFirstEvent ; iEvent < (UInt_t)fMaxEvents ; iEvent++) {
166 if ( iEvent%10 == 0 )
167 AliInfo(Form("processing event %d", iEvent));
168 if ( taskIndex == AliQA::kRAWS ) {
169 if ( !fRawReader->NextEvent() )
171 } else if ( taskIndex == AliQA::kESDS ) {
172 if ( fESDTree->GetEntry(iEvent) == 0 )
175 if ( fRunLoader->GetEvent(iEvent) != 0 )
178 // loop over active loaders
179 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
180 if (IsSelected(AliQA::GetDetName(iDet))) {
181 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
182 if (!qadm) continue; // This detector doesn't have any QA (for example, HLT)
183 if ( qadm->IsCycleDone() ) {
184 qadm->EndOfCycle(taskIndex) ;
186 TTree * data = NULL ;
187 AliLoader* loader = GetLoader(qadm->GetUniqueID());
189 case AliQA::kNULLTASKINDEX :
192 qadm->Exec(taskIndex, fRawReader) ;
197 data = loader->TreeH() ;
199 AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ;
203 qadm->Exec(taskIndex, data) ;
205 case AliQA::kSDIGITS :
207 loader->LoadSDigits() ;
208 data = loader->TreeS() ;
210 AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ;
214 qadm->Exec(taskIndex, data) ;
216 case AliQA::kDIGITS :
218 loader->LoadDigits() ;
219 data = loader->TreeD() ;
221 AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ;
225 qadm->Exec(taskIndex, data) ;
227 case AliQA::kRECPOINTS :
229 loader->LoadRecPoints() ;
230 data = loader->TreeR() ;
232 AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ;
236 qadm->Exec(taskIndex, data) ;
238 case AliQA::kTRACKSEGMENTS :
240 case AliQA::kRECPARTICLES :
243 qadm->Exec(taskIndex, fESD) ;
245 case AliQA::kNTASKINDEX :
252 // Save QA data for all detectors
253 rv = Finish(taskIndex) ;
255 if ( taskIndex == AliQA::kRAWS )
256 fRawReader->RewindEvents() ;
261 //_____________________________________________________________________________
262 Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX_t taskIndex)
264 // write output to file for all detectors
265 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
266 if (IsSelected(AliQA::GetDetName(iDet))) {
267 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
268 if (qadm) qadm->EndOfCycle(taskIndex) ;
274 //_____________________________________________________________________________
275 TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX_t det, AliQA::TASKINDEX_t task, const char * year) const
277 // Retrieve the list of QA data for a given detector and a given task
278 TObjArray * rv = NULL ;
279 if ( !strlen(AliQA::GetQARefStorage()) ) {
280 AliError("No storage defined, use AliQA::SetQARefStorage") ;
283 AliCDBManager* man = AliCDBManager::Instance() ;
284 if ( ! man->IsDefaultStorageSet() ) {
285 TString tmp(AliQA::GetQARefDefaultStorage()) ;
288 man->SetDefaultStorage(tmp.Data()) ;
289 man->SetSpecificStorage(Form("%s/*", AliQA::GetQAName()), AliQA::GetQARefStorage()) ;
291 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetQAName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName())) ;
292 AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir.Data(), AliQA::GetTaskName(task).Data())) ;
293 AliCDBEntry* entry = man->Get(detOCDBDir.Data(), 0) ; //FIXME 0 --> Run Number
294 TList * listDetQAD = dynamic_cast<TList *>(entry->GetObject()) ;
296 rv = dynamic_cast<TObjArray *>(listDetQAD->FindObject(AliQA::GetTaskName(task))) ;
300 //_____________________________________________________________________________
301 AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet)
303 // get the loader for a detector
305 if ( !fRunLoader || iDet == AliQA::kCORR)
308 TString detName = AliQA::GetDetName(iDet) ;
309 fLoader[iDet] = fRunLoader->GetLoader(detName + "Loader");
311 return fLoader[iDet] ;
313 // load the QA data maker object
314 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
315 TString loaderName = "Ali" + detName + "Loader" ;
317 AliLoader * loader = NULL ;
318 // first check if a plugin is defined for the quality assurance data maker
319 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
320 // if not, add a plugin for it
321 if (!pluginHandler) {
322 AliDebug(1, Form("defining plugin for %s", loaderName.Data())) ;
323 TString libs = gSystem->GetLibraries() ;
324 if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) {
325 pluginManager->AddHandler("AliQADataMaker", detName, loaderName, detName + "loader", loaderName + "()") ;
327 pluginManager->AddHandler("AliLoader", detName, loaderName, detName, loaderName + "()") ;
329 pluginHandler = pluginManager->FindHandler("AliLoader", detName) ;
331 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
332 loader = (AliLoader *) pluginHandler->ExecPlugin(0) ;
335 fLoader[iDet] = loader ;
339 //_____________________________________________________________________________
340 AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet)
342 // get the quality assurance data maker for a detector
344 if (fQADataMaker[iDet])
345 return fQADataMaker[iDet] ;
347 AliQADataMaker * qadm = NULL ;
349 if (iDet == AliQA::kGLOBAL) { //Global QA
350 qadm = new AliGlobalQADataMaker();
351 qadm->SetName(AliQA::GetDetName(iDet));
352 qadm->SetUniqueID(iDet);
353 fQADataMaker[iDet] = qadm;
357 if (iDet == AliQA::kCORR) { //the data maker for correlations among detectors
358 qadm = new AliCorrQADataMakerRec(fQADataMaker) ;
359 qadm->SetName(AliQA::GetDetName(iDet));
360 qadm->SetUniqueID(iDet);
361 fQADataMaker[iDet] = qadm;
365 // load the QA data maker object
366 TPluginManager* pluginManager = gROOT->GetPluginManager() ;
367 TString detName = AliQA::GetDetName(iDet) ;
369 if (tmp.Contains("sim"))
370 tmp.ReplaceAll("s", "S") ;
371 else if (tmp.Contains("rec"))
372 tmp.ReplaceAll("r", "R") ;
374 TString qadmName = "Ali" + detName + "QADataMaker" + tmp ;
376 // first check if a plugin is defined for the quality assurance data maker
377 TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
378 // if not, add a plugin for it
379 if (!pluginHandler) {
380 AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ;
381 TString libs = gSystem->GetLibraries() ;
382 if (libs.Contains("lib" + detName + fMode + ".so") || (gSystem->Load("lib" + detName + fMode + ".so") >= 0)) {
383 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ;
385 pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ;
387 pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ;
389 if (pluginHandler && (pluginHandler->LoadPlugin() == 0)) {
390 qadm = (AliQADataMaker *) pluginHandler->ExecPlugin(0) ;
393 qadm->SetName(AliQA::GetDetName(iDet));
394 qadm->SetUniqueID(iDet);
395 fQADataMaker[iDet] = qadm ;
401 //_____________________________________________________________________________
402 void AliQADataMakerSteer::EndOfCycle(TObjArray * detArray)
404 // End of cycle QADataMakers
406 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
407 if (IsSelected(AliQA::GetDetName(iDet))) {
408 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
411 // skip non active detectors
413 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
414 if (!det || !det->IsActive())
417 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
418 if ( fTasks.Contains(Form("%d", taskIndex)) )
419 qadm->EndOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex))) ;
426 //_____________________________________________________________________________
427 void AliQADataMakerSteer::Increment()
429 // Increments the cycle counter for all QA Data Makers
430 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
431 if (IsSelected(AliQA::GetDetName(iDet))) {
432 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
439 //_____________________________________________________________________________
440 Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX_t taskIndex, const char * input )
442 // Initialize the event source and QA data makers
444 //fTasks = AliQA::GetTaskName(taskIndex) ;
446 if (taskIndex == AliQA::kRAWS) {
448 fRawReader = AliRawReader::Create(input);
452 fRawReaderDelete = kTRUE ;
453 fRawReader->NextEvent() ;
454 fRunNumber = fRawReader->GetRunNumber() ;
455 AliCDBManager::Instance()->SetRun(fRunNumber) ;
456 fRawReader->RewindEvents();
457 fNumberOfEvents = 999999 ;
458 if ( fMaxEvents < 0 )
459 fMaxEvents = fNumberOfEvents ;
460 } else if (taskIndex == AliQA::kESDS) {
461 fTasks = AliQA::GetTaskName(AliQA::kESDS) ;
462 if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists
463 TFile * esdFile = TFile::Open("AliESDs.root") ;
464 fESDTree = dynamic_cast<TTree *> (esdFile->Get("esdTree")) ;
466 AliError("esdTree not found") ;
469 fESD = new AliESDEvent() ;
470 fESD->ReadFromTree(fESDTree) ;
471 fESDTree->GetEntry(0) ;
472 fRunNumber = fESD->GetRunNumber() ;
473 fNumberOfEvents = fESDTree->GetEntries() ;
474 if ( fMaxEvents < 0 )
475 fMaxEvents = fNumberOfEvents ;
478 AliError("AliESDs.root not found") ;
482 if ( !InitRunLoader() ) {
483 AliWarning("No Run Loader not found") ;
485 fNumberOfEvents = fRunLoader->GetNumberOfEvents() ;
486 if ( fMaxEvents < 0 )
487 fMaxEvents = fNumberOfEvents ;
492 TObjArray* detArray = NULL ;
493 if (fRunLoader) // check if RunLoader exists
494 if ( fRunLoader->GetAliRun() ) { // check if AliRun exists in gAlice.root
495 detArray = fRunLoader->GetAliRun()->Detectors() ;
496 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
499 // Initialize all QA data makers for all detectors
500 fRunNumber = AliCDBManager::Instance()->GetRun() ;
501 if ( ! AliGeomManager::GetGeometry() )
502 AliGeomManager::LoadGeometry() ;
504 InitQADataMaker(fRunNumber, fRecoParam, detArray) ; //, fCycleSame, kTRUE, detArray) ;
508 //_____________________________________________________________________________
509 void AliQADataMakerSteer::InitQADataMaker(UInt_t run, const AliRecoParam & par, TObjArray * detArray)
511 // Initializes The QADataMaker for all active detectors and for all active tasks
513 for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) {
514 if (IsSelected(AliQA::GetDetName(iDet))) {
515 AliQADataMaker * qadm = GetQADataMaker(iDet) ;
516 if (fQAWriteExpert[iDet])
517 qadm->SetWriteExpert() ;
519 AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ;
520 fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ;
522 AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ;
523 // skip non active detectors
525 AliModule* det = static_cast<AliModule*>(detArray->FindObject(AliQA::GetDetName(iDet))) ;
526 if (!det || !det->IsActive())
529 // Set default reco params
530 qadm->SetRecoParam(par.GetDetRecoParam(iDet));
531 Bool_t sameCycle = kFALSE ;
532 for (UInt_t taskIndex = 0; taskIndex < AliQA::kNTASKINDEX; taskIndex++) {
533 if ( fTasks.Contains(Form("%d", taskIndex)) ) {
534 qadm->StartOfCycle(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), run, sameCycle) ;
535 qadm->Init(AliQA::GetTaskIndex(AliQA::GetTaskName(taskIndex)), GetQACycles(qadm->GetUniqueID())) ;
545 //_____________________________________________________________________________
546 Bool_t AliQADataMakerSteer::InitRunLoader()
548 // get or create the run loader
552 if (!gSystem->AccessPathName(fGAliceFileName.Data())) { // galice.root exists
553 // load all base libraries to get the loader classes
554 TString libs = gSystem->GetLibraries() ;
555 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
556 if (!IsSelected(AliQA::GetDetName(iDet)))
558 TString detName = AliQA::GetDetName(iDet) ;
559 if (detName == "HLT")
561 if (libs.Contains("lib" + detName + "base.so"))
563 gSystem->Load("lib" + detName + "base.so");
565 fRunLoader = AliRunLoader::Open(fGAliceFileName.Data());
567 AliError(Form("no run loader found in file %s", fGAliceFileName.Data()));
570 fRunLoader->CdGAFile();
571 if (fRunLoader->LoadgAlice() == 0) {
572 gAlice = fRunLoader->GetAliRun();
576 AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data()));
580 } else { // galice.root does not exist
581 AliError(Form("the file %s does not exist", fGAliceFileName.Data()));
587 fRunLoader->LoadHeader();
588 fRunNumber = fRunLoader->GetHeader()->GetRun() ;
593 //_____________________________________________________________________________
594 Bool_t AliQADataMakerSteer::IsSelected(const char * det)
596 // check whether detName is contained in detectors
597 // if yes, it is removed from detectors
600 const TString detName(det) ;
601 // always activates Correlation
602 if ( detName.Contains(AliQA::GetDetName(AliQA::kCORR))) {
605 // check if all detectors are selected
606 if (fDetectors.Contains("ALL")) {
609 } else if ((fDetectors.CompareTo(detName) == 0) ||
610 fDetectors.BeginsWith(detName+" ") ||
611 fDetectors.EndsWith(" "+detName) ||
612 fDetectors.Contains(" "+detName+" ")) {
619 //_____________________________________________________________________________
620 Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const
622 // Merge data from all the cycles from all detectors in one single file per run
623 // Merge the QA results from all the data chunks in one run
624 Bool_t rv = MergeData(runNumber) ;
625 rv *= MergeResults(runNumber) ;
630 //_____________________________________________________________________________
631 Bool_t AliQADataMakerSteer::MergeData(const Int_t runNumber) const
633 // Merge all the cycles from all detectors in one single file per run
636 cmd = Form(".! ls *%s*.%d.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ;
638 cmd = Form(".! ls *%s*.*.root > tempo.txt", AliQA::GetQADataFileName()) ;
639 gROOT->ProcessLine(cmd.Data()) ;
640 ifstream in("tempo.txt") ;
641 const Int_t runMax = 10 ;
642 TString file[AliQA::kNDET*runMax] ;
649 AliInfo(Form("index = %d file = %s", index, (file[index]).Data())) ;
654 AliError(Form("run number %d not found", runNumber)) ;
659 TString outFileName(Form("Merged.%s.Data.%d.root",AliQA::GetQADataFileName(),runNumber));
660 merger.OutputFile(outFileName.Data()) ;
661 for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) {
662 TString pattern(Form("%s.%d.", AliQA::GetQADataFileName(), runNumber));
663 TString tmp(file[ifile]) ;
664 if (tmp.Contains(pattern)) {
665 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);
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)
843 AliCodeTimerAuto("") ;
844 if (fTasks.Contains(Form("%d", AliQA::kRAWS))){
845 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
846 if (!IsSelected(AliQA::GetDetName(iDet)))
848 AliQADataMaker *qadm = GetQADataMaker(iDet);
851 if ( qadm->IsCycleDone() ) {
854 AliCodeTimerStart(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
855 qadm->Exec(AliQA::kRAWS, rawReader) ;
856 AliCodeTimerStop(Form("running RAW quality assurance data maker for %s", AliQA::GetDetName(iDet)));
861 //_____________________________________________________________________________
862 void AliQADataMakerSteer::RunOneEvent(AliESDEvent *& esd)
864 //Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
866 AliCodeTimerAuto("") ;
867 if (fTasks.Contains(Form("%d", AliQA::kESDS))) {
868 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
869 if (!IsSelected(AliQA::GetDetName(iDet)))
871 AliQADataMaker *qadm = GetQADataMaker(iDet);
874 if ( qadm->IsCycleDone() ) {
877 AliCodeTimerStart(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
878 qadm->Exec(AliQA::kESDS, esd) ;
879 AliCodeTimerStop(Form("running ESD quality assurance data maker for %s", AliQA::GetDetName(iDet)));
884 //_____________________________________________________________________________
885 void AliQADataMakerSteer::RunOneEventInOneDetector(Int_t det, TTree * tree)
887 // Runs all the QA data Maker for ESDs only and on one event only (event loop done by calling method)
888 AliCodeTimerAuto("") ;
889 if (fTasks.Contains(Form("%d", AliQA::kRECPOINTS))) {
890 if (IsSelected(AliQA::GetDetName(det))) {
891 AliQADataMaker *qadm = GetQADataMaker(det);
893 if ( qadm->IsCycleDone() ) {
896 AliCodeTimerStart(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
897 qadm->Exec(AliQA::kRECPOINTS, tree) ;
898 AliCodeTimerStop(Form("running RecPoints quality assurance data maker for %s", AliQA::GetDetName(det)));
904 //_____________________________________________________________________________
905 Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const char * year, const char * detectors) const
907 // take the locasl QA data merge into a single file and save in OCDB
909 TString tmp(AliQA::GetQARefStorage()) ;
910 if ( tmp.IsNull() ) {
911 AliError("No storage defined, use AliQA::SetQARefStorage") ;
914 if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) {
915 AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ;
918 TString sdet(detectors) ;
921 if ( sdet.Contains("ALL") ) {
922 rv = Merge(runNumber) ;
925 TString inputFileName(Form("Merged.%s.Data.%d.root", AliQA::GetQADataFileName(), runNumber)) ;
926 inputFile = TFile::Open(inputFileName.Data()) ;
927 rv = SaveIt2OCDB(runNumber, inputFile, year) ;
929 for (Int_t index = 0; index < AliQA::kNDET; index++) {
930 if (sdet.Contains(AliQA::GetDetName(index))) {
931 TString inputFileName(Form("%s.%s.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber)) ;
932 inputFile = TFile::Open(inputFileName.Data()) ;
933 rv *= SaveIt2OCDB(runNumber, inputFile, year) ;
940 //_____________________________________________________________________________
941 Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile, const char * year) const
943 // reads the TH1 from file and adds it to appropriate list before saving to OCDB
945 AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ;
946 AliCDBManager* man = AliCDBManager::Instance() ;
947 if ( ! man->IsDefaultStorageSet() ) {
948 TString tmp( AliQA::GetQARefStorage() ) ;
949 if ( tmp.Contains(AliQA::GetLabLocalOCDB()) )
950 man->SetDefaultStorage(AliQA::GetQARefStorage()) ;
952 TString tmp1(AliQA::GetQARefDefaultStorage()) ;
954 tmp1.Append("?user=alidaq") ;
955 man->SetDefaultStorage(tmp1.Data()) ;
958 man->SetSpecificStorage("*", AliQA::GetQARefStorage()) ;
959 if(man->GetRun() < 0)
960 man->SetRun(runNumber);
963 mdr.SetResponsible("yves schutz");
965 for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) {
966 TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ;
968 AliInfo(Form("Entering %s", detDir->GetName())) ;
969 TString detOCDBDir(Form("%s/%s/%s", AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName(), AliQA::GetRefDataDirName())) ;
970 printf("SSSSSSSSSSSSSSSSSSSSS %s\n", detOCDBDir.Data()) ;
971 AliCDBId idr(detOCDBDir.Data(), runNumber, AliCDBRunRange::Infinity()) ;
972 TList * listDetQAD = new TList() ;
973 TString listName(Form("%s QA data Reference", AliQA::GetDetName(detIndex))) ;
974 mdr.SetComment("HMPID QA stuff");
975 listDetQAD->SetName(listName) ;
976 TList * taskList = detDir->GetListOfKeys() ;
977 TIter nextTask(taskList) ;
979 while ( (taskKey = dynamic_cast<TKey*>(nextTask())) ) {
980 TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ;
981 AliInfo(Form("Saving %s", taskDir->GetName())) ;
982 TObjArray * listTaskQAD = new TObjArray(100) ;
983 listTaskQAD->SetName(taskKey->GetName()) ;
984 listDetQAD->Add(listTaskQAD) ;
985 TList * histList = taskDir->GetListOfKeys() ;
986 TIter nextHist(histList) ;
988 while ( (histKey = dynamic_cast<TKey*>(nextHist())) ) {
989 TObject * odata = taskDir->Get(histKey->GetName()) ;
991 AliError(Form("%s in %s/%s returns a NULL pointer !!", histKey->GetName(), detDir->GetName(), taskDir->GetName())) ;
993 AliInfo(Form("Adding %s", histKey->GetName())) ;
994 if ( odata->IsA()->InheritsFrom("TH1") ) {
995 AliInfo(Form("Adding %s", histKey->GetName())) ;
996 TH1 * hdata = static_cast<TH1*>(odata) ;
997 listTaskQAD->Add(hdata) ;
1002 man->Put(listDetQAD, idr, &mdr) ;
1008 //_____________________________________________________________________________
1009 void AliQADataMakerSteer::SetRecoParam(const char* detector, AliDetectorRecoParam *par)
1011 // Set custom reconstruction parameters for a given detector
1012 // Single set of parameters for all the events
1013 for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) {
1014 if(!strcmp(detector, AliQA::GetDetName(iDet))) {
1015 par->SetAsDefault();
1016 fRecoParam.AddDetRecoParam(iDet,par);