]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG0/CreateESDChain.C
updating makefile to include evgen headers to compile systematics selector
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
index 2f60dfe8a9575a6f4d8446f19dd01e61453a872f..b9009f7b5eef8622736b0a649e8d3627c8c8d3d1 100644 (file)
@@ -2,9 +2,10 @@
 
 // Helper macros for creating chains
 
-TChain* CreateESDChainFromDir(const char* aDataDir, Int_t aRuns = 20, Int_t offset = 0)
+TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0)
 {
-  // creates chain of files in a given directory. The structure is expected as:
+  // 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
   // ...
@@ -12,74 +13,98 @@ TChain* CreateESDChainFromDir(const char* aDataDir, Int_t aRuns = 20, Int_t offs
   if (!aDataDir)
     return 0;
 
+  Long_t id, size, flags, modtime;
+  if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
+  {
+    printf("%s not found.\n", aDataDir);
+    return 0;
+  }
+
   TChain* chain = new TChain("esdTree");
   TChain* chaingAlice = 0;
 
-  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)
+  if (flags & 2)
   {
-    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);
+
+    Int_t count = 0;
 
-    if (offset > 0)
+    for (Int_t iDir=0; iDir<nDirs; ++iDir)
     {
-      --offset;
-      continue;
-    }
+      TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
+      if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
+        continue;
+
+      if (offset > 0)
+      {
+        --offset;
+        continue;
+      }
 
-    if (count++ == aRuns)
-      break;
+      if (count++ == aRuns)
+        break;
 
-    TString presentDirName(aDataDir);
-    presentDirName += "/";
-    presentDirName += presentDir->GetName();
+      TString presentDirName(aDataDir);
+      presentDirName += "/";
+      presentDirName += presentDir->GetName();
 
-    chain->Add(presentDirName + "/AliESDs.root/esdTree");
+      chain->Add(presentDirName + "/AliESDs.root/esdTree");
+    }
   }
+  else
+  {
+    // Open the input stream
+    ifstream in;
+    in.open(aDataDir);
 
-  return chain;
-}
+    Int_t count = 0;
 
-TChain* CreateESDChainFromList(const char* listFile, Int_t aRuns = 20)
-{
-  // Creates a chain from a file which contains a list of ESD files
+    // 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
 
-  if (!listFile)
-    return 0;
+      if (offset > 0)
+      {
+        --offset;
+        continue;
+      }
 
-  TChain* chain = new TChain("esdTree");
-  TChain* chaingAlice = 0;
+      if (count++ == aRuns)
+        break;
+
+        // add esd file
+      chain->Add(esdfile);
+    }
+
+    in.close();
+  }
 
-  // Open the input stream
-  ifstream in;
-  in.open(listFile);
+  return chain;
+}
 
-  Int_t count = 0;
+void LookupWrite(TChain* chain, const char* target)
+{
+  // looks up the chain and writes the remaining files to the text file target
 
-  // 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->Lookup();
 
-    if (count++ == aRuns)
-      break;
+  TObjArray* list = chain->GetListOfFiles();
+  TIterator* iter = list->MakeIterator();
+  TObject* obj = 0;
 
-      // add esd file
-    chain->Add(esdfile);
-  }
+  ofstream outfile;
+  outfile.open(target);
 
-  in.close();
+  while ((obj = iter->Next()))
+    outfile << obj->GetTitle() << "#AliESDs.root" << endl;
 
-  chain->Lookup();
+  outfile.close();
 
-  return chain;
+  delete iter;
 }