]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/CreateESDChain.C
Cell numbering fixed for V0A
[u/mrichter/AliRoot.git] / PWG0 / CreateESDChain.C
1 /* $Id$ */
2
3 // Helper macros for creating chains
4
5 TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0)
6 {
7   // creates chain of files in a given directory or file containing a list.
8   // In case of directory the structure is expected as:
9   // <aDataDir>/<dir0>/AliESDs.root
10   // <aDataDir>/<dir1>/AliESDs.root
11   // ...
12
13   if (!aDataDir)
14     return 0;
15
16   Long_t id, size, flags, modtime;
17   if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
18   {
19     printf("%s not found.\n", aDataDir);
20     return 0;
21   }
22
23   TChain* chain = new TChain("esdTree");
24   TChain* chaingAlice = 0;
25
26   if (flags & 2)
27   {
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);
33
34     Int_t count = 0;
35
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;
41
42       if (offset > 0)
43       {
44         --offset;
45         continue;
46       }
47
48       if (count++ == aRuns)
49         break;
50
51       TString presentDirName(aDataDir);
52       presentDirName += "/";
53       presentDirName += presentDir->GetName();
54
55       chain->Add(presentDirName + "/AliESDs.root/esdTree");
56     }
57   }
58   else
59   {
60     // Open the input stream
61     ifstream in;
62     in.open(aDataDir);
63
64     Int_t count = 0;
65
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
71
72       if (offset > 0)
73       {
74         --offset;
75         continue;
76       }
77
78       if (count++ == aRuns)
79         break;
80
81         // add esd file
82       chain->Add(esdfile);
83     }
84
85     in.close();
86   }
87
88   return chain;
89 }
90
91 void 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 }