coding conventions (Alberto)
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
CommitLineData
dc740de4 1/* $Id$ */
2
3// Helper macros for creating chains
4
e6a87095 5TChain* CreateESDChainFromDir(const char* aDataDir, Int_t aRuns = 20, Int_t offset = 0)
539b6cb4 6{
dc740de4 7 // creates chain of files in a given directory. The structure is expected as:
8 // <aDataDir>/<dir0>/AliESDs.root
dc740de4 9 // <aDataDir>/<dir1>/AliESDs.root
dc740de4 10 // ...
11
539b6cb4 12 if (!aDataDir)
13 return 0;
14
15 TChain* chain = new TChain("esdTree");
16 TChain* chaingAlice = 0;
17
539b6cb4 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
49dc84d9 24 Int_t count = 0;
25
539b6cb4 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
dc740de4 32 if (offset > 0)
33 {
34 --offset;
35 continue;
36 }
37
49dc84d9 38 if (count++ == aRuns)
39 break;
40
539b6cb4 41 TString presentDirName(aDataDir);
42 presentDirName += "/";
43 presentDirName += presentDir->GetName();
44
45 chain->Add(presentDirName + "/AliESDs.root/esdTree");
539b6cb4 46 }
47
539b6cb4 48 return chain;
49}
37dbb69e 50
e6a87095 51TChain* CreateESDChainFromList(const char* listFile, Int_t aRuns = 20)
37dbb69e 52{
dc740de4 53 // Creates a chain from a file which contains a list of ESD files
dc740de4 54
37dbb69e 55 if (!listFile)
56 return 0;
57
58 TChain* chain = new TChain("esdTree");
59 TChain* chaingAlice = 0;
60
37dbb69e 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 (count++ == aRuns)
74 break;
75
76 // add esd file
77 chain->Add(esdfile);
37dbb69e 78 }
79
80 in.close();
81
82 chain->Lookup();
83
37dbb69e 84 return chain;
85}