]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Also search sub-directories for ESD files
authorcholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 5 Jan 2011 11:35:38 +0000 (11:35 +0000)
committercholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 5 Jan 2011 11:35:38 +0000 (11:35 +0000)
PWG2/FORWARD/analysis2/scripts/MakeESDChain.C

index 39de328e8dec0e17774058226cb9c0f786cdfa52..a2da6964653ac40561e00a219597b8b78295130f 100644 (file)
@@ -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<TSystemFile*>(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<TSystemDirectory*>(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;
 }