3 // This helper macros creates a chain of ESD files for you.
4 // Source can be either a text file with the file paths or
5 // a directory. In the latter case all ESD files in all
6 // subdirectories are considered.
8 // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
10 TChain* CreateESDChain(
11 const char* aDataDir = "ESDfiles.txt",
14 Bool_t addFileName = kFALSE,
15 Bool_t addFriend = kFALSE,
19 // creates chain of files in a given directory or file containing a list.
20 // In case of directory the structure is expected as:
21 // <aDataDir>/<dir0>/AliESDs.root
22 // <aDataDir>/<dir1>/AliESDs.root
25 // if addFileName is true the list only needs to contain the directories that contain the AliESDs.root files
26 // if addFriend is true a file AliESDfriends.root is expected in the same directory and added to the chain as friend
27 // if check is != 0 the files that work are written back into the textfile with the name check
32 Long_t id, size, flags, modtime;
33 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
35 printf("%s not found.\n", aDataDir);
39 TChain* chain = new TChain("esdTree");
40 TChain* chainFriend = 0;
43 chainFriend = new TChain("esdFriendTree");
47 TString execDir(gSystem->pwd());
48 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
49 TList* dirList = baseDir->GetListOfFiles();
50 Int_t nDirs = dirList->GetEntries();
55 for (Int_t iDir=0; iDir<nDirs; ++iDir)
57 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
58 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
70 TString presentDirName(aDataDir);
71 presentDirName += "/";
72 presentDirName += presentDir->GetName();
74 chain->Add(presentDirName + "/AliESDs.root/esdTree");
79 // Open the input stream
89 // Read the input list of files and add them to the chain
95 if (line.Length() == 0)
104 if (count++ == aRuns)
107 TString esdFile(line);
110 esdFile += "/AliESDs.root";
112 if (esdFile.EndsWith(".zip"))
113 esdFile += "#AliESDs.root";
115 TString esdFileFriend(esdFile);
116 esdFileFriend.ReplaceAll("AliESDs.root", "AliESDfriends.root");
120 TFile* file = TFile::Open(esdFile);
127 TFile* file = TFile::Open(esdFileFriend);
133 outfile << line.Data() << endl;
134 printf("%s\n", line.Data());
142 chainFriend->Add(esdFileFriend);
152 chain->AddFriend(chainFriend);
157 void ChainToTextFile(TChain* chain, const char* target)
159 // write a text list of the files in the chain
161 TObjArray* list = chain->GetListOfFiles();
162 TIterator* iter = list->MakeIterator();
166 outfile.open(target);
168 while ((obj = iter->Next())) {
169 TString fileName(obj->GetTitle());
171 outfile << fileName.Data() << endl;
179 TObjArray* Chain2List(TChain* chain)
181 // returns a TObjArray of TObjStrings of the file names in the chain
183 TObjArray* result = new TObjArray;
185 for (Int_t i=0; i<chain->GetListOfFiles()->GetEntries(); i++)
186 result->Add(new TObjString(chain->GetListOfFiles()->At(i)->GetTitle()));
191 void LookupWrite(TChain* chain, const char* target)
193 // looks up the chain and writes the remaining files to the text file target
197 ChainToTextFile(chain, target);
200 TChain* CreateChain(const char* treeName, const char* aDataDir, Int_t aRuns, Int_t offset = 0)
202 // creates chain of files in a given directory or file containing a list.
204 if (!treeName || !aDataDir)
207 TChain* chain = new TChain(treeName);
209 // Open the input stream
215 // Read the input list of files and add them to the chain
221 if (line.Length() == 0)
230 if (count++ == aRuns)
233 if (line.EndsWith(".zip"))
234 line += "#AliESDs.root";