]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/CreateESDChain.C
o) adding log tags to all files
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
1 /* $Id$ */
2
3 // Helper macros for creating chains
4
5 TChain* CreateESDChainFromDir(const char* aDataDir, Int_t aRuns = 20, Int_t offset = 0, Bool_t aAddHeader = kTRUE)
6 {
7   // creates chain of files in a given directory. The structure is expected as:
8   // <aDataDir>/<dir0>/AliESDs.root
9   // <aDataDir>/<dir0>/galice.root (when <aAddHeader> flag is set)
10   // <aDataDir>/<dir1>/AliESDs.root
11   // <aDataDir>/<dir1>/galice.root (when <aAddHeader> flag is set)
12   // ...
13
14   if (!aDataDir)
15     return 0;
16
17   TChain* chain = new TChain("esdTree");
18   TChain* chaingAlice = 0;
19
20   if (aAddHeader != kFALSE)
21     chaingAlice = new TChain("TE");
22
23   TString execDir(gSystem->pwd());
24   TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
25   TList* dirList            = baseDir->GetListOfFiles();
26   Int_t nDirs               = dirList->GetEntries();
27   gSystem->cd(execDir);
28
29   Int_t count = 0;
30
31   for (Int_t iDir=0; iDir<nDirs; ++iDir)
32   {
33     TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
34     if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
35       continue;
36
37     if (offset > 0)
38     {
39       --offset;
40       continue;
41     }
42
43     if (count++ == aRuns)
44       break;
45
46     TString presentDirName(aDataDir);
47     presentDirName += "/";
48     presentDirName += presentDir->GetName();
49
50     chain->Add(presentDirName + "/AliESDs.root/esdTree");
51
52     if (aAddHeader != kFALSE)
53       chaingAlice->Add(presentDirName + "/galice.root/TE");
54   }
55
56   if (aAddHeader != kFALSE)
57     chain->AddFriend(chaingAlice);
58
59   return chain;
60 }
61
62 TChain* CreateESDChainFromList(const char* listFile, Int_t aRuns = 20, Bool_t aAddHeader = kTRUE)
63 {
64   // Creates a chain from a file which contains a list of ESD files
65   // if <aAddHeader> is set, the filename of the galice.root file is created by replacing
66   // AliESDs to galice in the esd file name
67
68   if (!listFile)
69     return 0;
70
71   TChain* chain = new TChain("esdTree");
72   TChain* chaingAlice = 0;
73
74   if (aAddHeader != kFALSE)
75     chaingAlice = new TChain("TE");
76
77   // Open the input stream
78   ifstream in;
79   in.open(listFile);
80
81   Int_t count = 0;
82
83   // Read the input list of files and add them to the chain
84   TString esdfile;
85   while(in.good()) {
86     in >> esdfile;
87     if (!esdfile.Contains("root")) continue; // protection
88
89     if (count++ == aRuns)
90       break;
91
92       // add esd file
93     chain->Add(esdfile);
94
95       // add header
96     if (aAddHeader != kFALSE)
97     {
98       esdfile.ReplaceAll("AliESDs", "galice");
99       chaingAlice->Add(esdfile + "/TE");
100     }
101   }
102
103   in.close();
104
105   chain->Lookup();
106
107   if (aAddHeader != kFALSE)
108   {
109     chaingAlice->Lookup();
110     chain->AddFriend(chaingAlice);
111   }
112
113   return chain;
114 }