]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
addin Read ESD macro
authorschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 17 Aug 2005 09:45:37 +0000 (09:45 +0000)
committerschutz <schutz@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 17 Aug 2005 09:45:37 +0000 (09:45 +0000)
PHOS/macros/AliReadESD.C [new file with mode: 0644]
PHOS/macros/AliReadESD.h [new file with mode: 0644]

diff --git a/PHOS/macros/AliReadESD.C b/PHOS/macros/AliReadESD.C
new file mode 100644 (file)
index 0000000..86e783f
--- /dev/null
@@ -0,0 +1,60 @@
+#include "AliReadESD.h"
+
+//======================================================================================
+TChain * AliReadESDfromdisk(const UInt_t eventsToRead, 
+                                  const TString dirName, 
+                                  const TString esdTreeName, 
+                                  const char *  pattern) 
+{
+  // Reads ESDs from Disk
+ TChain *  rv = 0; 
+
+  AliInfo( Form("\nReading files in %s \nESD tree name is %s \nReading %d events", 
+               dirName.Data(), esdTreeName.Data(), eventsToRead) ) ;
+  
+  // create a TChain of all the files 
+  TChain * cESDTree = new TChain(esdTreeName) ; 
+
+  // read from the directory file until the require number of events are collected
+  void * from = gSystem->OpenDirectory(dirName) ;
+  if (!from) {
+    AliError( Form("Directory %s does not exist") ) ;
+    rv = 0 ;
+  }
+  else{ // reading file names from directory
+    const char * file ; 
+    // search all subdirectories witch matching pattern
+    while( (file = gSystem->GetDirEntry(from))  && 
+          (cESDTree->GetEntries() < eventsToRead)) { 
+      if ( strstr(file, pattern) != 0 ) { 
+       AliInfo( Form("Adding %s\n", file) );
+       cESDTree->Add(file) ;
+      }
+    } // while file
+  
+    AliInfo( Form(" %d events read", cESDTree->GetEntriesFast()) ) ;
+    rv = cESDTree ; 
+    
+  } // reading file names from directory
+  return rv ; 
+}
+
+//======================================================================================
+TChain * AliReadESD(const UInt_t eventsToRead,
+                 const TString dirName, 
+                 const TString esdTreeName, 
+                 const char *  pattern)  
+{
+  // Read AliESDs files and return a Chain of events
+  if ( dirName == "" ) {
+    AliError("Give the name of the DIR where to find files") ; 
+    return 0 ; 
+  }
+  if ( esdTreeName == "" ) 
+    return AliReadESDfromdisk(eventsToRead, dirName) ;
+  else if ( strcmp(pattern, "") == 0 )
+    return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName) ;
+  else 
+    return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName, pattern) ;       
+}
diff --git a/PHOS/macros/AliReadESD.h b/PHOS/macros/AliReadESD.h
new file mode 100644 (file)
index 0000000..fee26d3
--- /dev/null
@@ -0,0 +1,31 @@
+#if !defined(__CINT__) || defined(__MAKECINT__)
+
+// Root include files
+#include <Riostream.h>
+#include <TString.h>
+#include <TChain.h>
+#include <TSystem.h>
+
+// AliROOT include files
+#include <AliLog.h>
+
+#else
+#endif
+
+// Define global parameters 
+const TString kgESDTreeName     = "esdTree" ; 
+const UInt_t  kgeventsToRead    = 1 ;
+const char *  kgPattern         = "Evt" ;
+
+TChain * AliReadESDfromdisk(const UInt_t eventsToRead, 
+                              const TString dirName, 
+                              const TString esdTreeName = kgESDTreeName, 
+                              const char *  pattern     = kgPattern) ; 
+TChain * AliReadESD(const UInt_t eventsToRead = kgeventsToRead,
+                    TString fileName  = "", 
+                    const TString esdTreeName = kgESDTreeName, 
+                    const char *  pattern     = kgPattern ) ;  
+
+// Needed for AliLog (return the macro name)
+char * ClassName() { return "macro" ; } 
+