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 TString esdFileFriend(esdFile);
113 esdFileFriend.ReplaceAll("AliESDs.root", "AliESDfriends.root");
117 TFile* file = TFile::Open(esdFile);
124 TFile* file = TFile::Open(esdFileFriend);
130 outfile << line.Data() << endl;
131 printf("%s\n", line.Data());
139 chainFriend->Add(esdFileFriend);
149 chain->AddFriend(chainFriend);
154 void ChainToTextFile(TChain* chain, const char* target)
156 // write a text list of the files in the chain
158 TObjArray* list = chain->GetListOfFiles();
159 TIterator* iter = list->MakeIterator();
163 outfile.open(target);
165 while ((obj = iter->Next())) {
166 TString fileName(obj->GetTitle());
168 outfile << fileName.Data() << endl;
176 TObjArray* Chain2List(TChain* chain)
178 // returns a TObjArray of TObjStrings of the file names in the chain
180 TObjArray* result = new TObjArray;
182 for (Int_t i=0; i<chain->GetListOfFiles()->GetEntries(); i++)
183 result->Add(new TObjString(chain->GetListOfFiles()->At(i)->GetTitle()));
188 void LookupWrite(TChain* chain, const char* target)
190 // looks up the chain and writes the remaining files to the text file target
194 ChainToTextFile(chain, target);
197 TChain* CreateChain(const char* treeName, const char* aDataDir, Int_t aRuns, Int_t offset = 0)
199 // creates chain of files in a given directory or file containing a list.
201 if (!treeName || !aDataDir)
204 TChain* chain = new TChain(treeName);
206 // Open the input stream
212 // Read the input list of files and add them to the chain
218 if (line.Length() == 0)
227 if (count++ == aRuns)