3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Author: The ALICE Off-line Project. *
7 * Contributors are mentioned in the code where appropriate. *
9 * Permission to use, copy, modify and distribute this software and its *
10 * documentation strictly for non-commercial purposes is hereby granted *
11 * without fee, provided that the above copyright notice appears in all *
12 * copies and that both the copyright notice and this permission notice *
13 * appear in the supporting documentation. The authors make no claims *
14 * about the suitability of this software for any purpose. It is *
15 * provided "as is" without express or implied warranty. *
16 **************************************************************************/
18 // This helper macros creates a chain of AOD files for you. Source can be either a text
19 // file with the file paths or a directory. In the latter case all AOD files in all subdirectories
22 // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
24 TChain* CreateAODChain(const char* aDataDir = "AODfiles.txt", Int_t aRuns = 20, Int_t offset = 0, Bool_t addFileName = kFALSE, Bool_t addFriend = kFALSE, const char* check = 0)
26 // creates chain of files in a given directory or file containing a list.
27 // In case of directory the structure is expected as:
28 // <aDataDir>/<dir0>/AliAODs.root
29 // <aDataDir>/<dir1>/AliAODs.root
32 // if addFileName is true the list only needs to contain the directories that contain the AliAODs.root files
33 // if check is != 0 the files that work are written back into the textfile with the name check
38 Long_t id, size, flags, modtime;
39 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
41 printf("%s not found.\n", aDataDir);
45 TChain* chain = new TChain("aodTree");
46 TChain* chainFriend = 0;
49 // chainFriend = new TChain("esdFriendTree");
53 TString execDir(gSystem->pwd());
54 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
55 TList* dirList = baseDir->GetListOfFiles();
56 Int_t nDirs = dirList->GetEntries();
61 for (Int_t iDir=0; iDir<nDirs; ++iDir)
63 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
64 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
76 TString presentDirName(aDataDir);
77 presentDirName += "/";
78 presentDirName += presentDir->GetName();
80 chain->Add(presentDirName + "/AliAODs.root/aodTree");
85 // Open the input stream
95 // Read the input list of files and add them to the chain
101 if (line.Length() == 0)
110 if (count++ == aRuns)
113 TString aodFile(line);
116 aodFile += "/AliAODs.root";
121 TFile* file = TFile::Open(aodFile);
128 TFile* file = TFile::Open(esdFileFriend);
134 outfile << line.Data() << endl;
135 printf("%s\n", line.Data());
143 // chainFriend->Add(esdFileFriend);
153 // chain->AddFriend(chainFriend);
158 void ChainToTextFile(TChain* chain, const char* target)
160 // write a text list of the files in the chain
162 TObjArray* list = chain->GetListOfFiles();
163 TIterator* iter = list->MakeIterator();
167 outfile.open(target);
169 while ((obj = iter->Next())) {
170 TString fileName(obj->GetTitle());
172 outfile << fileName.Data() << endl;
180 TObjArray* Chain2List(TChain* chain)
182 // returns a TObjArray of TObjStrings of the file names in the chain
184 TObjArray* result = new TObjArray;
186 for (Int_t i=0; i<chain->GetListOfFiles()->GetEntries(); i++)
187 result->Add(new TObjString(chain->GetListOfFiles()->At(i)->GetTitle()));
192 void LookupWrite(TChain* chain, const char* target)
194 // looks up the chain and writes the remaining files to the text file target
198 ChainToTextFile(chain, target);
201 TChain* CreateChain(const char* treeName, const char* aDataDir, Int_t aRuns, Int_t offset = 0)
203 // creates chain of files in a given directory or file containing a list.
205 if (!treeName || !aDataDir)
208 TChain* chain = new TChain(treeName);
210 // Open the input stream
216 // Read the input list of files and add them to the chain
222 if (line.Length() == 0)
231 if (count++ == aRuns)