]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG0/CreateESDChain.C
Updates needed to be in synch with TDPMjet.
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
index d572649afc57709f6a41cc952f651c4b37376de8..bb9bf3bc3faf693f6d4c678e38d8d5d2516d8002 100644 (file)
@@ -1,43 +1,91 @@
-TChain* CreateESDChain(const char* aDataDir, Int_t aRuns = 20, Bool_t aAddHeader = kTRUE)
+/* $Id$ */
+
+// Helper macros for creating chains
+
+TChain* CreateESDChain(const char* aDataDir, Int_t aRuns = 20, Int_t offset = 0)
 {
+  // creates chain of files in a given directory or file containing a list.
+  // In case of directory the structure is expected as:
+  // <aDataDir>/<dir0>/AliESDs.root
+  // <aDataDir>/<dir1>/AliESDs.root
+  // ...
+
   if (!aDataDir)
     return 0;
 
+  Long_t id, size, flags, modtime;
+  if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
+  {
+    print("%s not found.\n", aDataDir);
+    return 0;
+  }
+
   TChain* chain = new TChain("esdTree");
   TChain* chaingAlice = 0;
 
-  if (aAddHeader != kFALSE)
-    chaingAlice = new TChain("TE");
+  if (flags & 2)
+  {
+    TString execDir(gSystem->pwd());
+    TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
+    TList* dirList            = baseDir->GetListOfFiles();
+    Int_t nDirs               = dirList->GetEntries();
+    gSystem->cd(execDir);
+
+    Int_t count = 0;
+
+    for (Int_t iDir=0; iDir<nDirs; ++iDir)
+    {
+      TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
+      if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
+        continue;
 
-  TString execDir(gSystem->pwd());
-  TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
-  TList* dirList            = baseDir->GetListOfFiles();
-  Int_t nDirs               = dirList->GetEntries();
-  gSystem->cd(execDir);
+      if (offset > 0)
+      {
+        --offset;
+        continue;
+      }
 
-  Int_t count = 0;
+      if (count++ == aRuns)
+        break;
 
-  for (Int_t iDir=0; iDir<nDirs; ++iDir)
+      TString presentDirName(aDataDir);
+      presentDirName += "/";
+      presentDirName += presentDir->GetName();
+
+      chain->Add(presentDirName + "/AliESDs.root/esdTree");
+    }
+  }
+  else
   {
-    TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
-    if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
-      continue;
+    // Open the input stream
+    ifstream in;
+    in.open(aDataDir);
 
-    if (count++ == aRuns)
-      break;
+    Int_t count = 0;
 
-    TString presentDirName(aDataDir);
-    presentDirName += "/";
-    presentDirName += presentDir->GetName();
+    // Read the input list of files and add them to the chain
+    TString esdfile;
+    while(in.good()) {
+      in >> esdfile;
+      if (!esdfile.Contains("root")) continue; // protection
 
-    chain->Add(presentDirName + "/AliESDs.root/esdTree");
+      if (offset > 0)
+      {
+        --offset;
+        continue;
+      }
 
-    if (aAddHeader != kFALSE)
-      chaingAlice->Add(presentDirName + "/galice.root/TE");
-  }
+      if (count++ == aRuns)
+        break;
+
+        // add esd file
+      chain->Add(esdfile);
+    }
 
-  if (aAddHeader != kFALSE)
-    chain->AddFriend(chaingAlice);
+    in.close();
+
+    chain->Lookup();
+  }
 
   return chain;
 }