]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
reading of run parameters from the logbook
authorjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Nov 2006 14:23:32 +0000 (14:23 +0000)
committerjgrosseo <jgrosseo@f7af4fe6-9843-0410-8265-dc069ae4e863>
Mon, 6 Nov 2006 14:23:32 +0000 (14:23 +0000)
online offline naming conversion

STEER/macros/CreateESDChain.C [new file with mode: 0644]

diff --git a/STEER/macros/CreateESDChain.C b/STEER/macros/CreateESDChain.C
new file mode 100644 (file)
index 0000000..7e886bd
--- /dev/null
@@ -0,0 +1,129 @@
+/* $Id$ */
+
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+// This helper macros creates a chain of ESD files for you. Source can be either a text
+// file with the file paths or a directory. In the latter case all ESD files in all subdirectories
+// are considered.
+//
+// Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
+
+TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", 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))
+  {
+    printf("%s not found.\n", aDataDir);
+    return 0;
+  }
+
+  TChain* chain = new TChain("esdTree");
+  TChain* chaingAlice = 0;
+
+  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;
+
+      if (offset > 0)
+      {
+        --offset;
+        continue;
+      }
+
+      if (count++ == aRuns)
+        break;
+
+      TString presentDirName(aDataDir);
+      presentDirName += "/";
+      presentDirName += presentDir->GetName();
+
+      chain->Add(presentDirName + "/AliESDs.root/esdTree");
+    }
+  }
+  else
+  {
+    // Open the input stream
+    ifstream in;
+    in.open(aDataDir);
+
+    Int_t count = 0;
+
+    // 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 (offset > 0)
+      {
+        --offset;
+        continue;
+      }
+
+      if (count++ == aRuns)
+        break;
+
+        // add esd file
+      chain->Add(esdfile);
+    }
+
+    in.close();
+  }
+
+  return chain;
+}
+
+void LookupWrite(TChain* chain, const char* target)
+{
+  // looks up the chain and writes the remaining files to the text file target
+
+  chain->Lookup();
+
+  TObjArray* list = chain->GetListOfFiles();
+  TIterator* iter = list->MakeIterator();
+  TObject* obj = 0;
+
+  ofstream outfile;
+  outfile.open(target);
+
+  while ((obj = iter->Next()))
+    outfile << obj->GetTitle() << endl;
+
+  outfile.close();
+
+  delete iter;
+}