3 // This helper macros creates a chain of AOD files for you.
4 // Source can be either a text file with the file paths or
5 // a directory. In the latter case all AOD files in all
6 // subdirectories are considered.
8 // Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
10 TChain* CreateAODChain(
11 const char* aDataDir = "AODfiles.txt",
14 Bool_t addFileName = kFALSE,
15 const char* check = 0)
17 // creates chain of files in a given directory or file containing a list.
18 // In case of directory the structure is expected as:
19 // <aDataDir>/<dir0>/AliAOD.root
20 // <aDataDir>/<dir1>/AliAOD.root
23 // if addFileName is true the list only needs to contain the directories that contain the AliAODs.root files
24 // if check is != 0 the files that work are written back into the textfile with the name check
29 Long_t id, size, flags, modtime;
30 if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
32 printf("%s not found.\n", aDataDir);
36 TChain* chain = new TChain("aodTree");
37 TChain* chainFriend = 0;
41 TString execDir(gSystem->pwd());
42 TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
43 TList* dirList = baseDir->GetListOfFiles();
44 Int_t nDirs = dirList->GetEntries();
49 for (Int_t iDir=0; iDir<nDirs; ++iDir)
51 TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
52 if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
64 TString presentDirName(aDataDir);
65 presentDirName += "/";
66 presentDirName += presentDir->GetName();
68 chain->Add(presentDirName + "/AliAOD.root/aodTree");
73 // Open the input stream
83 // Read the input list of files and add them to the chain
89 if (line.Length() == 0)
101 TString aodFile(line);
104 aodFile += "/AliAOD.root";
106 if (line.EndsWith(".zip"))
107 aodFile += "#AliAOD.root";
111 TFile* file = TFile::Open(aodFile);
116 outfile << line.Data() << endl;
117 printf("%s\n", line.Data());
133 void ChainToTextFile(TChain* chain, const char* target)
135 // write a text list of the files in the chain
137 TObjArray* list = chain->GetListOfFiles();
138 TIterator* iter = list->MakeIterator();
142 outfile.open(target);
144 while ((obj = iter->Next())) {
145 TString fileName(obj->GetTitle());
147 outfile << fileName.Data() << endl;
155 TObjArray* Chain2List(TChain* chain)
157 // returns a TObjArray of TObjStrings of the file names in the chain
159 TObjArray* result = new TObjArray;
161 for (Int_t i=0; i<chain->GetListOfFiles()->GetEntries(); i++)
162 result->Add(new TObjString(chain->GetListOfFiles()->At(i)->GetTitle()));
167 void LookupWrite(TChain* chain, const char* target)
169 // looks up the chain and writes the remaining files to the text file target
173 ChainToTextFile(chain, target);
176 TChain* CreateChain(const char* treeName, const char* aDataDir, Int_t aRuns, Int_t offset = 0)
178 // creates chain of files in a given directory or file containing a list.
180 if (!treeName || !aDataDir)
183 TChain* chain = new TChain(treeName);
185 // Open the input stream
191 // Read the input list of files and add them to the chain
197 if (line.Length() == 0)
206 if (count++ == aRuns)
209 if (line.EndsWith(".zip"))
210 line += "#AliAOD.root";