]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG0/CreateESDChain.C
Added Reset function
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
CommitLineData
dc740de4 1/* $Id$ */
2
3// Helper macros for creating chains
4
ea1224c5 5TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0)
539b6cb4 6{
0ab29cfa 7 // creates chain of files in a given directory or file containing a list.
8 // In case of directory the structure is expected as:
dc740de4 9 // <aDataDir>/<dir0>/AliESDs.root
dc740de4 10 // <aDataDir>/<dir1>/AliESDs.root
dc740de4 11 // ...
12
539b6cb4 13 if (!aDataDir)
14 return 0;
15
0ab29cfa 16 Long_t id, size, flags, modtime;
17 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
18 {
bdfe2916 19 printf("%s not found.\n", aDataDir);
0ab29cfa 20 return 0;
21 }
22
539b6cb4 23 TChain* chain = new TChain("esdTree");
24 TChain* chaingAlice = 0;
25
0ab29cfa 26 if (flags & 2)
539b6cb4 27 {
0ab29cfa 28 TString execDir(gSystem->pwd());
29 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
30 TList* dirList = baseDir->GetListOfFiles();
31 Int_t nDirs = dirList->GetEntries();
32 gSystem->cd(execDir);
539b6cb4 33
0ab29cfa 34 Int_t count = 0;
dc740de4 35
0ab29cfa 36 for (Int_t iDir=0; iDir<nDirs; ++iDir)
37 {
38 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
39 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
40 continue;
49dc84d9 41
0ab29cfa 42 if (offset > 0)
43 {
44 --offset;
45 continue;
46 }
539b6cb4 47
0ab29cfa 48 if (count++ == aRuns)
49 break;
539b6cb4 50
0ab29cfa 51 TString presentDirName(aDataDir);
52 presentDirName += "/";
53 presentDirName += presentDir->GetName();
37dbb69e 54
0ab29cfa 55 chain->Add(presentDirName + "/AliESDs.root/esdTree");
56 }
57 }
58 else
59 {
60 // Open the input stream
61 ifstream in;
62 in.open(aDataDir);
dc740de4 63
0ab29cfa 64 Int_t count = 0;
37dbb69e 65
0ab29cfa 66 // Read the input list of files and add them to the chain
67 TString esdfile;
68 while(in.good()) {
69 in >> esdfile;
70 if (!esdfile.Contains("root")) continue; // protection
37dbb69e 71
0ab29cfa 72 if (offset > 0)
73 {
74 --offset;
75 continue;
76 }
37dbb69e 77
0ab29cfa 78 if (count++ == aRuns)
79 break;
37dbb69e 80
0ab29cfa 81 // add esd file
82 chain->Add(esdfile);
16e24ca3 83 }
84
0ab29cfa 85 in.close();
37dbb69e 86 }
87
37dbb69e 88 return chain;
89}
7f8cf861 90
91void LookupWrite(TChain* chain, const char* target)
92{
93 // looks up the chain and writes the remaining files to the text file target
94
95 chain->Lookup();
96
97 TObjArray* list = chain->GetListOfFiles();
98 TIterator* iter = list->MakeIterator();
99 TObject* obj = 0;
100
101 ofstream outfile;
102 outfile.open(target);
103
104 while ((obj = iter->Next()))
105 outfile << obj->GetTitle() << "#AliESDs.root" << endl;
106
107 outfile.close();
108
109 delete iter;
110}