From 5d0ddfc10fce63d4c4a147bd811aa725a179b840 Mon Sep 17 00:00:00 2001 From: cholm Date: Wed, 5 Jan 2011 11:35:38 +0000 Subject: [PATCH] Also search sub-directories for ESD files --- PWG2/FORWARD/analysis2/scripts/MakeESDChain.C | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/PWG2/FORWARD/analysis2/scripts/MakeESDChain.C b/PWG2/FORWARD/analysis2/scripts/MakeESDChain.C index 39de328e8de..a2da6964653 100644 --- a/PWG2/FORWARD/analysis2/scripts/MakeESDChain.C +++ b/PWG2/FORWARD/analysis2/scripts/MakeESDChain.C @@ -1,14 +1,14 @@ -TChain* -MakeESDChain(const char* esddir) +void +ScanDirectory(TSystemDirectory* dir, TChain* chain, bool recursive) { - // --- Our data chain ---------------------------------------------- - TChain* chain = new TChain("esdTree"); - - // --- Get list of ESDs -------------------------------------------- - // Open source directory, and make sure we go back to were we were + // gROOT->IndentLevel(); + // Printf("Scanning %s ...", dir->GetName()); + // gROOT->IncreaseDirLevel(); + + + // Get list of files, and go back to old working directory TString oldDir(gSystem->WorkingDirectory()); - TSystemDirectory d(esddir, esddir); - TList* files = d.GetListOfFiles(); + TList* files = dir->GetListOfFiles(); gSystem->ChangeDirectory(oldDir); // Sort list of files and check if we should add it @@ -16,13 +16,49 @@ MakeESDChain(const char* esddir) TIter next(files); TSystemFile* file = 0; while ((file = static_cast(next()))) { - if (file->IsDirectory()) continue; TString name(file->GetName()); + + // Ignore special links + if (name == "." || name == "..") continue; + + // Check if this is a directory + if (file->IsDirectory()) { + if (recursive) + ScanDirectory(static_cast(file),chain,recursive); + continue; + } + + // If this is not a root file, ignore if (!name.EndsWith(".root")) continue; + + // If this file does not contain AliESDs, ignore if (!name.Contains("AliESDs")) continue; + + // Get the path TString esd(Form("%s/%s", file->GetTitle(), name.Data())); - Info("RunManager", "Adding %s to chain", esd.Data()); + + // Print and add + // gROOT->IndentLevel(); + // Printf("adding %s", esd.Data()); chain->Add(esd); - } + + } + // gROOT->DecreaseDirLevel(); +} + +TChain* +MakeESDChain(const char* esddir, bool recursive=false) +{ + // --- Our data chain ---------------------------------------------- + TChain* chain = new TChain("esdTree"); + + // --- Get list of ESDs -------------------------------------------- + // Open source directory, and make sure we go back to were we were + TString oldDir(gSystem->WorkingDirectory()); + TSystemDirectory d(esddir, esddir); + ScanDirectory(&d, chain, recursive); + + // chain->GetListOfFiles()->ls(); + return chain; } -- 2.43.0