From 105631b5f6243361be7e25c45ac1060666837904 Mon Sep 17 00:00:00 2001 From: agheata Date: Wed, 6 Jul 2011 09:10:38 +0000 Subject: [PATCH] Added static method in the plugin to load the analysis manager from file --- ANALYSIS/AliAnalysisAlien.cxx | 54 ++++++++++++++++++----------------- ANALYSIS/AliAnalysisAlien.h | 2 ++ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/ANALYSIS/AliAnalysisAlien.cxx b/ANALYSIS/AliAnalysisAlien.cxx index 2956bd57f71..796bd7c5410 100644 --- a/ANALYSIS/AliAnalysisAlien.cxx +++ b/ANALYSIS/AliAnalysisAlien.cxx @@ -24,6 +24,7 @@ #include "Riostream.h" #include "TEnv.h" +#include "TKey.h" #include "TBits.h" #include "TError.h" #include "TROOT.h" @@ -2115,6 +2116,27 @@ Bool_t AliAnalysisAlien::CheckMergedFiles(const char *filename, const char *alie return kTRUE; } +//______________________________________________________________________________ +AliAnalysisManager *AliAnalysisAlien::LoadAnalysisManager(const char *fname) +{ +// Loat the analysis manager from a file. + TFile *file = TFile::Open(fname); + if (!file) { + ::Error("LoadAnalysisManager", "Cannot open file %s", fname); + return 0; + } + TIter nextkey(file->GetListOfKeys()); + AliAnalysisManager *mgr = 0; + TKey *key; + while ((key=(TKey*)nextkey())) { + if (!strcmp(key->GetClassName(), "AliAnalysisManager")) + mgr = (AliAnalysisManager*)file->Get(key->GetName()); + } + if (!mgr) + ::Error("LoadAnalysisManager", "No analysis manager found in file %s", fname); + return mgr; +} + //______________________________________________________________________________ Int_t AliAnalysisAlien::SubmitSingleJob(const char *query) { @@ -3402,19 +3424,9 @@ void AliAnalysisAlien::WriteAnalysisMacro() out << "// read the analysis manager from file" << endl; TString analysisFile = fExecutable; analysisFile.ReplaceAll(".sh", ".root"); - out << " TFile *file = TFile::Open(\"" << analysisFile << "\");" << endl; - out << " if (!file) return;" << endl; - out << " TIter nextkey(file->GetListOfKeys());" << endl; - out << " AliAnalysisManager *mgr = 0;" << endl; - out << " TKey *key;" << endl; - out << " while ((key=(TKey*)nextkey())) {" << endl; - out << " if (!strcmp(key->GetClassName(), \"AliAnalysisManager\"))" << endl; - out << " mgr = (AliAnalysisManager*)file->Get(key->GetName());" << endl; - out << " };" << endl; - out << " if (!mgr) {" << endl; - out << " ::Error(\"" << func.Data() << "\", \"No analysis manager found in file " << analysisFile <<"\");" << endl; - out << " return;" << endl; - out << " }" << endl << endl; + out << " AliAnalysisManager *mgr = AliAnalysisAlien::LoadAnalysisManager(\"" + << analysisFile << "\");" << endl; + out << " if (!mgr) return;" << endl; out << " mgr->PrintStatus();" << endl; if (AliAnalysisManager::GetAnalysisManager()) { if (AliAnalysisManager::GetAnalysisManager()->GetDebugLevel()>3) { @@ -3807,19 +3819,9 @@ void AliAnalysisAlien::WriteMergingMacro() TString analysisFile = fExecutable; analysisFile.ReplaceAll(".sh", ".root"); out << " if (!outputDir.Contains(\"Stage\")) return;" << endl; - out << " TFile *file = TFile::Open(\"" << analysisFile << "\");" << endl; - out << " if (!file) return;" << endl; - out << " TIter nextkey(file->GetListOfKeys());" << endl; - out << " AliAnalysisManager *mgr = 0;" << endl; - out << " TKey *key;" << endl; - out << " while ((key=(TKey*)nextkey())) {" << endl; - out << " if (!strcmp(key->GetClassName(), \"AliAnalysisManager\"))" << endl; - out << " mgr = (AliAnalysisManager*)file->Get(key->GetName());" << endl; - out << " };" << endl; - out << " if (!mgr) {" << endl; - out << " ::Error(\"" << func.Data() << "\", \"No analysis manager found in file" << analysisFile <<"\");" << endl; - out << " return;" << endl; - out << " }" << endl << endl; + out << " AliAnalysisManager *mgr = AliAnalysisAlien::LoadAnalysisManager(\"" + << analysisFile << "\");" << endl; + out << " if (!mgr) return;" << endl; out << " mgr->SetRunFromPath(mgr->GetRunFromAlienPath(dir));" << endl; out << " mgr->SetSkipTerminate(kFALSE);" << endl; out << " mgr->PrintStatus();" << endl; diff --git a/ANALYSIS/AliAnalysisAlien.h b/ANALYSIS/AliAnalysisAlien.h index 1f78521f071..4f4c2dafa0c 100644 --- a/ANALYSIS/AliAnalysisAlien.h +++ b/ANALYSIS/AliAnalysisAlien.h @@ -26,6 +26,7 @@ #include #endif +class AliAnalysisManager; class TGridJDL; class AliAnalysisAlien : public AliAnalysisGrid { @@ -105,6 +106,7 @@ public: static const char *GetJobStatus(Int_t jobidstart, Int_t lastid, Int_t &nrunning, Int_t &nwaiting, Int_t &nerror, Int_t &ndone); const char *GetListOfFiles(const char *type); Bool_t CheckMergedFiles(const char *filename, const char *aliendir, Int_t nperchunk, const char *jdl=""); + static AliAnalysisManager *LoadAnalysisManager(const char *fname); static Bool_t MergeOutput(const char *output, const char *basedir, Int_t nmaxmerge, Int_t stage=0); virtual Bool_t MergeOutputs(); virtual void Print(Option_t *option="") const; -- 2.43.0