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