X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;ds=sidebyside;f=STEER%2FAliQADataMakerSteer.cxx;h=b32c43526b9b7bc6822b5b5bedfe4076634faae1;hb=a6f6970e109ee97cb8d9edff3b8203c0f36c4d34;hp=70485b33822e5e10cff9789bb25d970af96c1bee;hpb=ad265f3e088f46305e88f2e1b965ee281f7bb9c4;p=u%2Fmrichter%2FAliRoot.git diff --git a/STEER/AliQADataMakerSteer.cxx b/STEER/AliQADataMakerSteer.cxx index 70485b33822..b32c43526b9 100644 --- a/STEER/AliQADataMakerSteer.cxx +++ b/STEER/AliQADataMakerSteer.cxx @@ -15,18 +15,28 @@ /* $Id$ */ +#include #include +#include #include #include #include #include +#include "AliCDBManager.h" +#include "AliCDBEntry.h" +#include "AliCDBId.h" +#include "AliCDBMetaData.h" #include "AliESDEvent.h" +#include "AliHeader.h" #include "AliLog.h" #include "AliModule.h" #include "AliQA.h" -#include "AliQADataMaker.h" +#include "AliQADataMakerRec.h" +#include "AliQADataMakerSim.h" #include "AliQADataMakerSteer.h" +#include "AliRawReaderDate.h" +#include "AliRawReaderFile.h" #include "AliRawReaderRoot.h" #include "AliRun.h" #include "AliRunLoader.h" @@ -37,20 +47,25 @@ ClassImp(AliQADataMakerSteer) AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char * name, const char * title) : TNamed(name, title), fCycleSame(kFALSE), + fDetectors("ALL"), + fDetectorsW("ALL"), fESD(NULL), fESDTree(NULL), fFirst(kTRUE), fGAliceFileName(gAliceFilename), fRunNumber(0), - fNumberOfEvents(0), + fNumberOfEvents(999999), fRawReader(NULL), + fRawReaderDelete(kTRUE), fRunLoader(NULL) { // default ctor for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { - fLoader[iDet] = NULL ; - fQADataMaker[iDet] = NULL ; - fQACycles[iDet] = 999999 ; + if (IsSelected(AliQA::GetDetName(iDet))) { + fLoader[iDet] = NULL ; + fQADataMaker[iDet] = NULL ; + fQACycles[iDet] = 999999 ; + } } } @@ -58,6 +73,8 @@ AliQADataMakerSteer::AliQADataMakerSteer(const char* gAliceFilename, const char AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) : TNamed(qas), fCycleSame(kFALSE), + fDetectors(qas.fDetectors), + fDetectorsW(qas.fDetectorsW), fESD(NULL), fESDTree(NULL), fFirst(qas.fFirst), @@ -65,6 +82,7 @@ AliQADataMakerSteer::AliQADataMakerSteer(const AliQADataMakerSteer & qas) : fRunNumber(qas.fRunNumber), fNumberOfEvents(qas.fNumberOfEvents), fRawReader(NULL), + fRawReaderDelete(kTRUE), fRunLoader(NULL) { // cpy ctor @@ -89,17 +107,164 @@ AliQADataMakerSteer::~AliQADataMakerSteer() { // dtor for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { - fLoader[iDet] = NULL; - if (fQADataMaker[iDet]) { - (fQADataMaker[iDet])->Finish() ; - delete fQADataMaker[iDet] ; - fQADataMaker[iDet] = NULL ; - } + if (IsSelected(AliQA::GetDetName(iDet))) { + fLoader[iDet] = NULL; + if (fQADataMaker[iDet]) { + (fQADataMaker[iDet])->Finish() ; + delete fQADataMaker[iDet] ; + fQADataMaker[iDet] = NULL ; + } + } + } + + if (fRawReaderDelete) { + fRunLoader = NULL ; + delete fRawReader ; + fRawReader = NULL ; } +} + +//_____________________________________________________________________________ +Bool_t AliQADataMakerSteer::DoIt(const AliQA::TASKINDEX taskIndex, const char * mode) +{ + // Runs all the QA data Maker for every detector + + Bool_t rv = kFALSE ; + // Fill QA data in event loop + for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) { + // Get the event + if ( iEvent%10 == 0 ) + AliInfo(Form("processing event %d", iEvent)); + if ( taskIndex == AliQA::kRAWS ) { + if ( !fRawReader->NextEvent() ) + break ; + } else if ( taskIndex == AliQA::kESDS ) { + if ( fESDTree->GetEntry(iEvent) == 0 ) + break ; + } else { + if ( fRunLoader->GetEvent(iEvent) != 0 ) + break ; + } + // loop over detectors + TObjArray* detArray = NULL ; + if (fRunLoader) // check if RunLoader exists + if ( fRunLoader->GetAliRun() ) // check if AliRun exists in gAlice.root + detArray = fRunLoader->GetAliRun()->Detectors() ; + for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) { + if (detArray) { + AliModule* det = static_cast(detArray->FindObject(AliQA::GetDetName(iDet))) ; + if (!det || !det->IsActive()) + continue ; + } + if (!IsSelected(AliQA::GetDetName(iDet))) + continue ; + AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ; + if (!qadm) { + rv = kFALSE ; + } else { + if ( qadm->IsCycleDone() ) { + qadm->EndOfCycle(AliQA::kRAWS) ; + qadm->StartOfCycle(AliQA::kRAWS) ; + } + TTree * data ; + switch (taskIndex) { + case AliQA::kRAWS : + qadm->Exec(taskIndex, fRawReader) ; + break ; + case AliQA::kHITS : + GetLoader(iDet)->LoadHits() ; + data = GetLoader(iDet)->TreeH() ; + if ( ! data ) { + AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ; + } else { + qadm->Exec(taskIndex, data) ; + } + break ; + case AliQA::kSDIGITS : + GetLoader(iDet)->LoadSDigits() ; + data = GetLoader(iDet)->TreeS() ; + if ( ! data ) { + AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ; + } else { + qadm->Exec(taskIndex, data) ; + } + break; + case AliQA::kDIGITS : + GetLoader(iDet)->LoadDigits() ; + data = GetLoader(iDet)->TreeD() ; + if ( ! data ) { + AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ; + } else { + qadm->Exec(taskIndex, data) ; + } + break; + case AliQA::kRECPOINTS : + GetLoader(iDet)->LoadRecPoints() ; + data = GetLoader(iDet)->TreeR() ; + if (!data) { + AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ; + } else { + qadm->Exec(taskIndex, data) ; + } + break; + case AliQA::kTRACKSEGMENTS : + break; + case AliQA::kRECPARTICLES : + break; + case AliQA::kESDS : + qadm->Exec(taskIndex, fESD) ; + break; + case AliQA::kNTASKINDEX : + break; + } //task switch + //qadm->Increment() ; + } //data maker exist + } // detector loop + } // event loop +// // Save QA data for all detectors + rv = Finish(taskIndex, mode) ; + + return rv ; +} + +//_____________________________________________________________________________ +Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex, const char * mode) +{ + // write output to file for all detectors + for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { + if (IsSelected(AliQA::GetDetName(iDet))) { + AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ; + if (qadm) { + qadm->EndOfCycle(taskIndex) ; + } + } + } + return kTRUE ; +} - fRunLoader = NULL ; - delete fRawReader ; - fRawReader = NULL ; +//_____________________________________________________________________________ +TObjArray * AliQADataMakerSteer::GetFromOCDB(AliQA::DETECTORINDEX det, AliQA::TASKINDEX task) const +{ + // Retrieve the list of QA data for a given detector and a given task + TObjArray * rv = NULL ; + TString tmp(AliQA::GetQARefStorage()) ; + if ( tmp.IsNull() ) { + AliError("No storage defined, use AliQA::SetQARefStorage") ; + return NULL ; + } + AliCDBManager* man = AliCDBManager::Instance() ; + if ( ! man->IsDefaultStorageSet() ) { + man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ; + man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ; + } + char detOCDBDir[10] ; + sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName((Int_t)det), AliQA::GetRefOCDBDirName()) ; + AliInfo(Form("Retrieving reference data from %s/%s for %s", AliQA::GetQARefStorage(), detOCDBDir, AliQA::GetTaskName(task).Data())) ; + AliCDBEntry* entry = man->Get(detOCDBDir, 0) ; //FIXME 0 --> Run Number + TList * listDetQAD = dynamic_cast(entry->GetObject()) ; + if ( listDetQAD ) + rv = dynamic_cast(listDetQAD->FindObject(AliQA::GetTaskName(task))) ; + return rv ; } //_____________________________________________________________________________ @@ -139,7 +304,7 @@ AliLoader * AliQADataMakerSteer::GetLoader(Int_t iDet) } //_____________________________________________________________________________ -AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet) +AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(const Int_t iDet, const char * mode ) { // get the quality assurance data maker for a detector @@ -152,7 +317,12 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet) // load the QA data maker object TPluginManager* pluginManager = gROOT->GetPluginManager() ; TString detName = AliQA::GetDetName(iDet) ; - TString qadmName = "Ali" + detName + "QADataMaker" ; + TString tmp(mode) ; + if (tmp.Contains("sim")) + tmp.ReplaceAll("s", "S") ; + else if (tmp.Contains("rec")) + tmp.ReplaceAll("r", "R") ; + TString qadmName = "Ali" + detName + "QADataMaker" + tmp ; // first check if a plugin is defined for the quality assurance data maker TPluginHandler* pluginHandler = pluginManager->FindHandler("AliQADataMaker", detName) ; @@ -160,7 +330,7 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet) if (!pluginHandler) { AliDebug(1, Form("defining plugin for %s", qadmName.Data())) ; TString libs = gSystem->GetLibraries() ; - if (libs.Contains("lib" + detName + "base.so") || (gSystem->Load("lib" + detName + "base.so") >= 0)) { + if (libs.Contains("lib" + detName + mode + ".so") || (gSystem->Load("lib" + detName + mode + ".so") >= 0)) { pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName + "qadm", qadmName + "()") ; } else { pluginManager->AddHandler("AliQADataMaker", detName, qadmName, detName, qadmName + "()") ; @@ -177,51 +347,68 @@ AliQADataMaker * AliQADataMakerSteer::GetQADataMaker(Int_t iDet) } //_____________________________________________________________________________ -Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * fileName ) +Bool_t AliQADataMakerSteer::Init(const AliQA::TASKINDEX taskIndex, const char * mode, const char * input ) { // Initialize the event source and QA data makers - if (taskIndex == AliQA::kRAWS) { - fRawReader = new AliRawReaderRoot(fileName) ; + if (taskIndex == AliQA::kRAWS) { + if (!fRawReader) { + TString fileName(input); + if (fileName.EndsWith("/")) { + fRawReader = new AliRawReaderFile(fileName); + } else if (fileName.EndsWith(".root")) { + fRawReader = new AliRawReaderRoot(fileName); + } else if (!fileName.IsNull()) { + fRawReader = new AliRawReaderDate(fileName); + fRawReader->SelectEvents(7); + } + } if ( ! fRawReader ) return kFALSE ; + fRawReaderDelete = kTRUE ; fRawReader->NextEvent() ; fRunNumber = fRawReader->GetRunNumber() ; + AliCDBManager::Instance()->SetRun(fRunNumber) ; fRawReader->RewindEvents(); fNumberOfEvents = 999999 ; } else if (taskIndex == AliQA::kESDS) { if (!gSystem->AccessPathName("AliESDs.root")) { // AliESDs.root exists TFile * esdFile = TFile::Open("AliESDs.root") ; fESDTree = dynamic_cast (esdFile->Get("esdTree")) ; - fESD = new AliESDEvent() ; - fESD->ReadFromTree(fESDTree) ; - fESDTree->GetEntry(0) ; - fRunNumber = fESD->GetRunNumber() ; - fNumberOfEvents = fESDTree->GetEntries() ; + if ( !fESDTree ) { + AliError("esdTree not found") ; + return kFALSE ; + } else { + fESD = new AliESDEvent() ; + fESD->ReadFromTree(fESDTree) ; + fESDTree->GetEntry(0) ; + fRunNumber = fESD->GetRunNumber() ; + fNumberOfEvents = fESDTree->GetEntries() ; + } } else { AliError("AliESDs.root not found") ; return kFALSE ; } } else { - if ( !InitRunLoader() ) { - AliError("Problems in getting the Run Loader") ; - return kFALSE ; + if ( !InitRunLoader() ) { + AliWarning("No Run Loader not found") ; } else { - if (fRunLoader->GetAliRun()) - fRunNumber = fRunLoader->GetAliRun()->GetRunNumber() ; fNumberOfEvents = fRunLoader->GetNumberOfEvents() ; } } - - // Initialize all QA data makers for all detectors + // Initialize all QA data makers for all detectors for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { - AliQADataMaker * qadm = GetQADataMaker(iDet) ; - if (!qadm) { - AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; - } else { - AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; - qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ; - qadm->StartOfCycle(taskIndex, fCycleSame) ; + + if (IsSelected(AliQA::GetDetName(iDet))) { + AliQADataMaker * qadm = GetQADataMaker(iDet, mode) ; + if (!qadm) { + AliError(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; + fDetectorsW.ReplaceAll(AliQA::GetDetName(iDet), "") ; + } else { + AliDebug(1, Form("Data Maker found for %s", qadm->GetName())) ; + qadm->Init(taskIndex, fRunNumber, GetQACycles(iDet)) ; + qadm->StartOfCycle(taskIndex, fCycleSame) ; + } } } fFirst = kFALSE ; @@ -241,6 +428,8 @@ Bool_t AliQADataMakerSteer::InitRunLoader() // load all base libraries to get the loader classes TString libs = gSystem->GetLibraries() ; for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { + if (!IsSelected(AliQA::GetDetName(iDet))) + continue ; TString detName = AliQA::GetDetName(iDet) ; if (detName == "HLT") continue; @@ -257,6 +446,7 @@ Bool_t AliQADataMakerSteer::InitRunLoader() if (fRunLoader->LoadgAlice() == 0) { gAlice = fRunLoader->GetAliRun(); } + if (!gAlice) { AliError(Form("no gAlice object found in file %s", fGAliceFileName.Data())); return kFALSE; @@ -271,137 +461,311 @@ Bool_t AliQADataMakerSteer::InitRunLoader() } //_____________________________________________________________________________ -Bool_t AliQADataMakerSteer::Finish(const AliQA::TASKINDEX taskIndex) +Bool_t AliQADataMakerSteer::IsSelected(const char * det) { - // write output to file for all detectors - for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { - AliQADataMaker * qadm = GetQADataMaker(iDet) ; - if (qadm) { - qadm->EndOfCycle(taskIndex) ; - } + // check whether detName is contained in detectors + // if yes, it is removed from detectors + + const TString detName(det) ; + // check if all detectors are selected + if ((fDetectors.CompareTo("ALL") == 0) || + fDetectors.BeginsWith("ALL ") || + fDetectors.EndsWith(" ALL") || + fDetectors.Contains(" ALL ")) { + fDetectors = "ALL"; + return kTRUE; } - return kTRUE ; + + // search for the given detector + Bool_t rv = kFALSE; + //AliInfo(Form("SSSSSSSSSSSSS fd = %s det = %s ", fDetectors.Data(), det)) ; + if ((fDetectors.CompareTo(detName) == 0) || + fDetectors.BeginsWith(detName+" ") || + fDetectors.EndsWith(" "+detName) || + fDetectors.Contains(" "+detName+" ")) { + // fDetectors.ReplaceAll(detName, ""); + rv = kTRUE; + } + + // clean up the detectors string + // while (fDetectors.Contains(" ")) + // fDetectors.ReplaceAll(" ", " "); + // while (fDetectors.BeginsWith(" ")) + // fDetectors.Remove(0, 1); + // while (fDetectors.EndsWith(" ")) + // fDetectors.Remove(fDetectors.Length()-1, 1); + + return rv ; } //_____________________________________________________________________________ -Bool_t AliQADataMakerSteer::Merge() +Bool_t AliQADataMakerSteer::Merge(const Int_t runNumber) const { - // Merge - + // Merge all the cycles from all detectors in one single file per run + char cmd[80] ; + if ( runNumber == -1 ) + sprintf(cmd, ".! ls *%s*.*.*.root > tempo.txt", AliQA::GetQADataFileName()) ; + else + sprintf(cmd, ".! ls *%s*.%d.*.root > tempo.txt", AliQA::GetQADataFileName(), runNumber) ; + gROOT->ProcessLine(cmd) ; + ifstream in("tempo.txt") ; + const Int_t runMax = 10 ; + TString file[AliQA::kNDET*runMax] ; + Int_t run[AliQA::kNDET*runMax] ; + + Int_t index = 0 ; + while ( 1 ) { + in >> file[index] ; + if ( !in.good() ) + break ; + index++ ; + } + + if ( index == 0 ) { + AliError(Form("run number %d not found", runNumber)) ; + return kFALSE ; + } + + Int_t runIndex = 0 ; + Int_t runIndexMax = 0 ; + char stmp[10] ; + sprintf(stmp, ".%s.", AliQA::GetQADataFileName()) ; + for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) { + TString tmp(file[ifile]) ; + tmp.ReplaceAll(".root", "") ; + TString det = tmp(0, tmp.Index(".")) ; + tmp.Remove(0, tmp.Index(stmp)+4) ; + TString ttmp = tmp(0, tmp.Index(".")) ; + Int_t newRun = ttmp.Atoi() ; + for (Int_t irun = 0; irun <= runIndexMax; irun++) { + if (newRun == run[irun]) + break ; + run[runIndex] = newRun ; + runIndex++ ; + } + runIndexMax = runIndex ; + ttmp = tmp(tmp.Index(".")+1, tmp.Length()) ; + Int_t cycle = ttmp.Atoi() ; + AliDebug(1, Form("%s : det = %s run = %d cycle = %d \n", file[ifile].Data(), det.Data(), newRun, cycle)) ; + } + for (Int_t irun = 0 ; irun < runIndexMax ; irun++) { + TFileMerger merger ; + char outFileName[20] ; + sprintf(outFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), run[irun]) ; + merger.OutputFile(outFileName) ; + for (Int_t ifile = 0 ; ifile < index-1 ; ifile++) { + char pattern[100] ; + sprintf(pattern, "%s.%d.", AliQA::GetQADataFileName(), run[irun]) ; + TString tmp(file[ifile]) ; + if (tmp.Contains(pattern)) { + merger.AddFile(tmp) ; + } + } + merger.Merge() ; + } + + return kTRUE ; } //_____________________________________________________________________________ -void AliQADataMakerSteer::Reset() +void AliQADataMakerSteer::Reset(const Bool_t sameCycle) { // Reset the default data members for (UInt_t iDet = 0; iDet < fgkNDetectors; iDet++) { - fLoader[iDet] = NULL; - if (fQADataMaker[iDet]) { - (fQADataMaker[iDet])->Reset() ; -// delete fQADataMaker[iDet] ; -// fQADataMaker[iDet] = NULL ; + if (IsSelected(AliQA::GetDetName(iDet))) { + fLoader[iDet] = NULL; + if (fQADataMaker[iDet]) { + (fQADataMaker[iDet])->Reset(sameCycle) ; + //delete fQADataMaker[iDet] ; + //fQADataMaker[iDet] = NULL ; + } } } - delete fRawReader ; - fRawReader = NULL ; + if (fRawReaderDelete) { + delete fRawReader ; + fRawReader = NULL ; + } - fCycleSame = kFALSE ; + fCycleSame = sameCycle ; fESD = NULL ; fESDTree = NULL ; fFirst = kTRUE ; - fNumberOfEvents = 0 ; + fNumberOfEvents = 999999 ; +} + +//_____________________________________________________________________________ +Bool_t AliQADataMakerSteer::Run(const char * detectors, AliRawReader * rawReader) +{ + //Runs all the QA data Maker for Raws only + fRawReader = rawReader ; + fRawReaderDelete = kFALSE ; + fCycleSame = kTRUE ; + fDetectors = detectors ; + + // Initialize all QA data makers for all detectors + for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { + if (IsSelected(AliQA::GetDetName(iDet))) { + AliQADataMaker * qadm = GetQADataMaker(iDet, "rec") ; + if (!qadm) { + AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; + } else { + AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; + qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ; + qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ; + } + } + } + fFirst = kFALSE ; + + return DoIt(AliQA::kRAWS, "rec") ; +} + +//_____________________________________________________________________________ +TString AliQADataMakerSteer::Run(const char * detectors, const char * fileName) +{ + //Runs all the QA data Maker for Raws only + //fCycleSame = kTRUE ; + fDetectors = detectors ; + fDetectorsW = detectors ; + + + if ( !Init(AliQA::kRAWS, "rec", fileName) ) + return kFALSE ; + + // Initialize all QA data makers for all detectors + //for (UInt_t iDet = 0; iDet < fgkNDetectors ; iDet++) { +// if (IsSelected(AliQA::GetDetName(iDet))) { +// AliQADataMaker * qadm = GetQADataMaker(iDet, "rec") ; +// if (!qadm) { +// AliWarning(Form("AliQADataMaker not found for %s", AliQA::GetDetName(iDet))) ; +// } else { +// AliInfo(Form("Data Maker found for %s", qadm->GetName())) ; +// qadm->Init(AliQA::kRAWS, fRunNumber, GetQACycles(iDet)) ; +// qadm->StartOfCycle(AliQA::kRAWS, fCycleSame) ; +// } +// } +// } + fFirst = kFALSE ; + DoIt(AliQA::kRAWS, "rec") ; + return fDetectorsW ; } //_____________________________________________________________________________ -Bool_t AliQADataMakerSteer::Run(const AliQA::TASKINDEX taskIndex, const char * fileName ) +Bool_t AliQADataMakerSteer::Run(const char * detectors, const AliQA::TASKINDEX taskIndex, const char * fileName ) { // Runs all the QA data Maker for every detector - Bool_t rv = kFALSE ; + + Bool_t rv = kFALSE ; + fDetectors = detectors ; + + char * mode ; + if ( (taskIndex == AliQA::kHITS) || (taskIndex == AliQA::kSDIGITS) || (taskIndex == AliQA::kDIGITS) ) + mode = "sim" ; + else if ( (taskIndex == AliQA::kRAWS) || (taskIndex == AliQA::kRECPOINTS) || (taskIndex == AliQA::kESDS) ) + mode = "rec" ; + else { + AliError(Form("%s not implemented", AliQA::GetTaskName(taskIndex).Data())) ; + return rv ; + } + + if ( !Init(taskIndex, mode, fileName) ) + return kFALSE ; + + rv = DoIt(taskIndex, mode) ; - if ( !Init(taskIndex, fileName) ) + return rv ; + +} + +//_____________________________________________________________________________ +Bool_t AliQADataMakerSteer::Save2OCDB(const Int_t runNumber, const Int_t cycleNumber, const char * detectors) const +{ + // take the locasl QA data merge into a single file and save in OCDB + Bool_t rv = kTRUE ; + TString tmp(AliQA::GetQARefStorage()) ; + if ( tmp.IsNull() ) { + AliError("No storage defined, use AliQA::SetQARefStorage") ; return kFALSE ; - - // Fill QA data in event loop - for (UInt_t iEvent = 0 ; iEvent < fNumberOfEvents ; iEvent++) { - // Get the event - AliInfo(Form("processing event %d", iEvent)); - if ( taskIndex == AliQA::kRAWS ) { - if ( !fRawReader->NextEvent() ) - break ; - } else if ( taskIndex == AliQA::kESDS ) { - fESDTree->GetEntry(iEvent) ; - } else { - fRunLoader->GetEvent(iEvent); + } + if ( !(tmp.Contains(AliQA::GetLabLocalOCDB()) || tmp.Contains(AliQA::GetLabAliEnOCDB())) ) { + AliError(Form("%s is a wrong storage, use %s or %s", AliQA::GetQARefStorage(), AliQA::GetLabLocalOCDB().Data(), AliQA::GetLabAliEnOCDB().Data())) ; + return kFALSE ; + } + TString sdet(detectors) ; + sdet.ToUpper() ; + TFile * inputFile ; + if ( sdet.Contains("ALL") ) { + rv = Merge(runNumber) ; + if ( ! rv ) + return kFALSE ; + char inputFileName[20] ; + sprintf(inputFileName, "Merged.%s.%d.root", AliQA::GetQADataFileName(), runNumber) ; + inputFile = TFile::Open(inputFileName) ; + rv = SaveIt2OCDB(runNumber, inputFile) ; + } else { + for (Int_t index = 0; index < AliQA::kNDET; index++) { + if (sdet.Contains(AliQA::GetDetName(index))) { + char inputFileName[20] ; + sprintf(inputFileName, "%s.%s.%d.%d.root", AliQA::GetDetName(index), AliQA::GetQADataFileName(), runNumber, cycleNumber) ; + inputFile = TFile::Open(inputFileName) ; + rv *= SaveIt2OCDB(runNumber, inputFile) ; + } } - // loop over detectors - TObjArray* detArray = fRunLoader->GetAliRun()->Detectors() ; - for (UInt_t iDet = 0 ; iDet < fgkNDetectors ; iDet++) { - AliModule* det = static_cast(detArray->FindObject(AliQA::GetDetName(iDet))) ; - if (!det || !det->IsActive()) - continue; - AliQADataMaker * qadm = GetQADataMaker(iDet) ; - if (!qadm) { - rv = kFALSE ; - } else { - if ( qadm->IsCycleDone() ) { - qadm->EndOfCycle(AliQA::kRAWS) ; - qadm->StartOfCycle(AliQA::kRAWS) ; - } - TTree * data ; - switch (taskIndex) { - case AliQA::kRAWS : - qadm->Exec(taskIndex, fRawReader) ; - break ; - case AliQA::kHITS : - GetLoader(iDet)->LoadHits() ; - data = GetLoader(iDet)->TreeH() ; - if ( ! data ) { - AliWarning(Form(" Hit Tree not found for %s", AliQA::GetDetName(iDet))) ; - } else { - qadm->Exec(taskIndex, data) ; - } - break ; - case AliQA::kSDIGITS : - GetLoader(iDet)->LoadSDigits() ; - data = GetLoader(iDet)->TreeS() ; - if ( ! data ) { - AliWarning(Form(" SDigit Tree not found for %s", AliQA::GetDetName(iDet))) ; - } else { - qadm->Exec(taskIndex, data) ; - } - break; - case AliQA::kDIGITS : - GetLoader(iDet)->LoadDigits() ; - data = GetLoader(iDet)->TreeD() ; - if ( ! data ) { - AliWarning(Form(" Digit Tree not found for %s", AliQA::GetDetName(iDet))) ; - } else { - qadm->Exec(taskIndex, data) ; - } - break; - case AliQA::kRECPOINTS : - GetLoader(iDet)->LoadRecPoints() ; - data = GetLoader(iDet)->TreeR() ; - if (!data) { - AliWarning(Form("RecPoints not found for %s", AliQA::GetDetName(iDet))) ; - } else { - qadm->Exec(taskIndex, data) ; - } - break; - case AliQA::kTRACKSEGMENTS : - break; - case AliQA::kRECPARTICLES : - break; - case AliQA::kESDS : - qadm->Exec(taskIndex, fESD) ; - break; - } //task switch - qadm->Increment() ; - } //data maker exist - } // detector loop - } // event loop - // Save QA data for all detectors - rv = Finish(taskIndex) ; + } return rv ; } + +//_____________________________________________________________________________ +Bool_t AliQADataMakerSteer::SaveIt2OCDB(const Int_t runNumber, TFile * inputFile) const +{ + // reads the TH1 from file and adds it to appropriate list before saving to OCDB + Bool_t rv = kTRUE ; + AliInfo(Form("Saving TH1s in %s to %s", inputFile->GetName(), AliQA::GetQARefStorage())) ; + AliCDBManager* man = AliCDBManager::Instance() ; + if ( ! man->IsDefaultStorageSet() ) { + man->SetDefaultStorage(AliQA::GetQARefDefaultStorage()) ; + man->SetSpecificStorage(Form("%s/*", AliQA::GetQAOCDBDirName()), AliQA::GetQARefStorage()) ; + } + if(man->GetRun() < 0) + man->SetRun(runNumber); + + for ( Int_t detIndex = 0 ; detIndex < AliQA::kNDET ; detIndex++) { + TDirectory * detDir = inputFile->GetDirectory(AliQA::GetDetName(detIndex)) ; + if ( detDir ) { + AliInfo(Form("Entering %s", detDir->GetName())) ; + char detOCDBDir[20] ; + sprintf(detOCDBDir, "%s/%s/%s", AliQA::GetQAOCDBDirName(), AliQA::GetDetName(detIndex), AliQA::GetRefOCDBDirName()) ; + AliCDBId idr(detOCDBDir, runNumber, 999999999) ; + TList * listDetQAD = new TList() ; + char listName[20] ; + sprintf(listName, "%s QA data Reference", AliQA::GetDetName(detIndex)) ; + listDetQAD->SetName(listName) ; + TList * taskList = detDir->GetListOfKeys() ; + TIter nextTask(taskList) ; + TKey * taskKey ; + while ( (taskKey = dynamic_cast(nextTask())) ) { + TDirectory * taskDir = detDir->GetDirectory(taskKey->GetName()) ; + AliInfo(Form("Saving %s", taskDir->GetName())) ; + TObjArray * listTaskQAD = new TObjArray(100) ; + listTaskQAD->SetName(taskKey->GetName()) ; + listDetQAD->Add(listTaskQAD) ; + TList * histList = taskDir->GetListOfKeys() ; + TIter nextHist(histList) ; + TKey * histKey ; + while ( (histKey = dynamic_cast(nextHist())) ) { + TObject * odata = taskDir->Get(histKey->GetName()) ; + if ( odata->IsA()->InheritsFrom("TH1") ) { + AliInfo(Form("Adding %s", histKey->GetName())) ; + TH1 * hdata = static_cast(odata) ; + listTaskQAD->Add(hdata) ; + } + } + } + AliCDBMetaData mdr ; + man->Put(listDetQAD, idr, &mdr) ; + } + } + return rv ; +} +