From c07b9ce264350c023142dc7cf8f110d65c1d4cbd Mon Sep 17 00:00:00 2001 From: agheata Date: Thu, 30 Apr 2009 13:49:23 +0000 Subject: [PATCH] Added support for retrieving and merging dAOD's. The producer task has to call AliAnalysisManager::RegisterExtraFile(filename) in their Init() --- ANALYSIS/AliAnalysisAlien.cxx | 5 ++ ANALYSIS/AliAnalysisManager.cxx | 86 ++++++++++++++++++++++----------- ANALYSIS/AliAnalysisManager.h | 6 ++- 3 files changed, 68 insertions(+), 29 deletions(-) diff --git a/ANALYSIS/AliAnalysisAlien.cxx b/ANALYSIS/AliAnalysisAlien.cxx index 3d09307ed2e..4b6c03af800 100644 --- a/ANALYSIS/AliAnalysisAlien.cxx +++ b/ANALYSIS/AliAnalysisAlien.cxx @@ -960,6 +960,11 @@ void AliAnalysisAlien::StartAnalysis(Long64_t /*nentries*/, Long64_t /*firstEntr if (fOutputFiles.Length()) fOutputFiles += " "; fOutputFiles += filename; } + // Add extra files registered to the analysis manager + if (mgr->GetExtraFiles().Length()) { + if (fOutputFiles.Length()) fOutputFiles += " "; + fOutputFiles += mgr->GetExtraFiles(); + } } // if (!fCloseSE.Length()) fCloseSE = gSystem->Getenv("alien_CLOSE_SE"); if (TestBit(AliAnalysisGrid::kOffline)) { diff --git a/ANALYSIS/AliAnalysisManager.cxx b/ANALYSIS/AliAnalysisManager.cxx index c4f6d16508c..5b829372272 100644 --- a/ANALYSIS/AliAnalysisManager.cxx +++ b/ANALYSIS/AliAnalysisManager.cxx @@ -73,7 +73,8 @@ AliAnalysisManager::AliAnalysisManager(const char *name, const char *title) fCommonInput(NULL), fCommonOutput(NULL), fSelector(NULL), - fGridHandler(NULL) + fGridHandler(NULL), + fExtraFiles("") { // Default constructor. fgAnalysisManager = this; @@ -109,7 +110,8 @@ AliAnalysisManager::AliAnalysisManager(const AliAnalysisManager& other) fCommonInput(NULL), fCommonOutput(NULL), fSelector(NULL), - fGridHandler(NULL) + fGridHandler(NULL), + fExtraFiles() { // Copy constructor. fTasks = new TObjArray(*other.fTasks); @@ -147,6 +149,7 @@ AliAnalysisManager& AliAnalysisManager::operator=(const AliAnalysisManager& othe fCommonOutput = NULL; fSelector = NULL; fGridHandler = NULL; + fExtraFiles = other.fExtraFiles; fgAnalysisManager = this; } return *this; @@ -582,33 +585,15 @@ void AliAnalysisManager::ImportWrappers(TList *source) // Copy merged file from PROOF scratch space. // In case of grid the files are already in the current directory. if (!inGrid) { - char full_path[512]; - char ch_url[512]; - TObject *pof = source->FindObject(filename); - if (!pof || !pof->InheritsFrom("TProofOutputFile")) { - Error("ImportWrappers", "TProofOutputFile object not found in output list for container %s", cont->GetName()); - continue; - } - gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", ((TProofOutputFile*)0x%lx)->GetOutputFileName();)", full_path, pof)); - gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", gProof->GetUrl();)", ch_url)); - TString clientUrl(ch_url); - TString full_path_str(full_path); - if (clientUrl.Contains("localhost")){ - TObjArray* array = full_path_str.Tokenize ( "//" ); - TObjString *strobj = ( TObjString *)array->At(1); - TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" ); - TObjString *strobjPort = ( TObjString *) arrayPort->At(1); - full_path_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT"); - full_path_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data())); - if (fDebug > 1) Info("ImportWrappers","Using tunnel from %s to %s",full_path_str.Data(),filename); - } - if (fDebug > 1) - printf(" Copying file %s from PROOF scratch space\n", full_path_str.Data()); - Bool_t gotit = TFile::Cp(full_path_str.Data(), filename); - if (!gotit) { - Error("ImportWrappers", "Could not get file %s from proof scratch space", cont->GetFileName()); - continue; + if (isManagedByHandler && fExtraFiles.Length()) { + // Copy extra registered dAOD files. + TObjArray *arr = fExtraFiles.Tokenize(" "); + TObjString *os; + TIter nextfilename(arr); + while ((os=(TObjString*)nextfilename())) GetFileFromWrapper(os->GetString(), source); + delete arr; } + if (!GetFileFromWrapper(filename, source)) continue; } // Normally we should connect data from the copied file to the // corresponding output container, but it is not obvious how to do this @@ -1304,3 +1289,48 @@ void AliAnalysisManager::SetOutputEventHandler(AliVEventHandler* handler) fCommonOutput->SetSpecialOutput(); Warning("SetOutputEventHandler", " An automatic output container for the output tree was created.\nPlease use: mgr->GetCommonOutputContainer() to access it."); } + +//______________________________________________________________________________ +void AliAnalysisManager::RegisterExtraFile(const char *fname) +{ +// This method is used externally to register output files which are not +// connected to any output container, so that the manager can properly register, +// retrieve or merge them when running in distributed mode. The file names are +// separated by blancs. The method has to be called in MyAnalysisTask::LocalInit(). + if (fExtraFiles.Length()) fExtraFiles += " "; + fExtraFiles += fname; +} + +//______________________________________________________________________________ +Bool_t AliAnalysisManager::GetFileFromWrapper(const char *filename, TList *source) +{ +// Copy a file from the location specified ina the wrapper with the same name from the source list. + char full_path[512]; + char ch_url[512]; + TObject *pof = source->FindObject(filename); + if (!pof || !pof->InheritsFrom("TProofOutputFile")) { + Error("GetFileFromWrapper", "TProofOutputFile object not found in output list for file %s", filename); + return kFALSE; + } + gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", ((TProofOutputFile*)0x%lx)->GetOutputFileName();)", full_path, pof)); + gROOT->ProcessLine(Form("sprintf((char*)0x%lx, \"%%s\", gProof->GetUrl();)", ch_url)); + TString clientUrl(ch_url); + TString full_path_str(full_path); + if (clientUrl.Contains("localhost")){ + TObjArray* array = full_path_str.Tokenize ( "//" ); + TObjString *strobj = ( TObjString *)array->At(1); + TObjArray* arrayPort = strobj->GetString().Tokenize ( ":" ); + TObjString *strobjPort = ( TObjString *) arrayPort->At(1); + full_path_str.ReplaceAll(strobj->GetString().Data(),"localhost:PORT"); + full_path_str.ReplaceAll(":PORT",Form(":%s",strobjPort->GetString().Data())); + if (fDebug > 1) Info("GetFileFromWrapper","Using tunnel from %s to %s",full_path_str.Data(),filename); + delete arrayPort; + delete array; + } + if (fDebug > 1) + Info("GetFileFromWrapper","Copying file %s from PROOF scratch space", full_path_str.Data()); + Bool_t gotit = TFile::Cp(full_path_str.Data(), filename); + if (!gotit) + Error("GetFileFromWrapper", "Could not get file %s from proof scratch space", filename); + return gotit; +} diff --git a/ANALYSIS/AliAnalysisManager.h b/ANALYSIS/AliAnalysisManager.h index e7c92f5dc59..32e3d050adb 100644 --- a/ANALYSIS/AliAnalysisManager.h +++ b/ANALYSIS/AliAnalysisManager.h @@ -57,7 +57,7 @@ enum EAliAnalysisFlags { AliAnalysisManager(const AliAnalysisManager& other); AliAnalysisManager& operator=(const AliAnalysisManager& other); - // Management + // Management methods called by the framework void StartAnalysis(const char *type="local", TTree *tree=0, Long64_t nentries=1234567890, Long64_t firstentry=0); void StartAnalysis(const char *type, const char *dataset, Long64_t nentries=1234567890, Long64_t firstentry=0); @@ -87,6 +87,7 @@ enum EAliAnalysisFlags { GetAnalysisType() const {return fMode;} Bool_t IsUsingDataSet() const {return TObject::TestBit(kUseDataSet);} + void RegisterExtraFile(const char *fname); void SetAnalysisType(EAliAnalysisExecMode mode) {fMode = mode;} void SetCurrentEntry(Long64_t entry) {fCurrentEntry = entry;} void SetDebugLevel(UInt_t level) {fDebug = level;} @@ -107,6 +108,8 @@ enum EAliAnalysisFlags { AliAnalysisDataContainer *GetCommonOutputContainer() {return fCommonOutput;} AliAnalysisGrid* GetGridHandler() {return fGridHandler;} AliVEventPool* GetEventPool() {return fEventPool;} + Bool_t GetFileFromWrapper(const char *filename, TList *source); + TString GetExtraFiles() const {return fExtraFiles;} // Container handling AliAnalysisDataContainer *CreateContainer(const char *name, TClass *datatype, @@ -160,6 +163,7 @@ private: AliAnalysisDataContainer *fCommonOutput; // Common output container AliAnalysisSelector *fSelector; //! Current selector AliAnalysisGrid *fGridHandler; //! Grid handler plugin + TString fExtraFiles; //! List of extra files to be merged static AliAnalysisManager *fgAnalysisManager; //! static pointer to object instance ClassDef(AliAnalysisManager,4) // Analysis manager class -- 2.43.0