]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PHOS/macros/AliReadESD.C
addin Read ESD macro
[u/mrichter/AliRoot.git] / PHOS / macros / AliReadESD.C
1 #include "AliReadESD.h"
2
3 //======================================================================================
4 TChain * AliReadESDfromdisk(const UInt_t eventsToRead, 
5                                    const TString dirName, 
6                                    const TString esdTreeName, 
7                                    const char *  pattern) 
8 {
9   // Reads ESDs from Disk
10  TChain *  rv = 0; 
11
12   AliInfo( Form("\nReading files in %s \nESD tree name is %s \nReading %d events", 
13                 dirName.Data(), esdTreeName.Data(), eventsToRead) ) ;
14   
15   // create a TChain of all the files 
16   TChain * cESDTree = new TChain(esdTreeName) ; 
17
18   // read from the directory file until the require number of events are collected
19   void * from = gSystem->OpenDirectory(dirName) ;
20   if (!from) {
21     AliError( Form("Directory %s does not exist") ) ;
22     rv = 0 ;
23   }
24   else{ // reading file names from directory
25     const char * file ; 
26     // search all subdirectories witch matching pattern
27     while( (file = gSystem->GetDirEntry(from))  && 
28            (cESDTree->GetEntries() < eventsToRead)) { 
29       if ( strstr(file, pattern) != 0 ) { 
30         AliInfo( Form("Adding %s\n", file) );
31         cESDTree->Add(file) ;
32       }
33     } // while file
34   
35     AliInfo( Form(" %d events read", cESDTree->GetEntriesFast()) ) ;
36     rv = cESDTree ; 
37     
38   } // reading file names from directory
39   return rv ; 
40 }
41
42 //======================================================================================
43 TChain * AliReadESD(const UInt_t eventsToRead,
44                   const TString dirName, 
45                   const TString esdTreeName, 
46                   const char *  pattern)  
47 {
48   // Read AliESDs files and return a Chain of events
49  
50   if ( dirName == "" ) {
51     AliError("Give the name of the DIR where to find files") ; 
52     return 0 ; 
53   }
54   if ( esdTreeName == "" ) 
55     return AliReadESDfromdisk(eventsToRead, dirName) ;
56   else if ( strcmp(pattern, "") == 0 )
57     return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName) ;
58   else 
59     return AliReadESDfromdisk(eventsToRead, dirName, esdTreeName, pattern) ;        
60 }