// Helper macros for creating chains
-TChain* CreateESDChainFromDir(const char* aDataDir, Int_t aRuns = 20, Int_t offset = 0)
+TChain* CreateESDChain(const char* aDataDir = "ESDfiles.txt", Int_t aRuns = 20, Int_t offset = 0)
{
- // creates chain of files in a given directory. The structure is expected as:
+ // creates chain of files in a given directory or file containing a list.
+ // In case of directory the structure is expected as:
// <aDataDir>/<dir0>/AliESDs.root
// <aDataDir>/<dir1>/AliESDs.root
// ...
if (!aDataDir)
return 0;
+ Long_t id, size, flags, modtime;
+ if (gSystem->GetPathInfo(aDataDir, &id, &size, &flags, &modtime))
+ {
+ printf("%s not found.\n", aDataDir);
+ return 0;
+ }
+
TChain* chain = new TChain("esdTree");
TChain* chaingAlice = 0;
- TString execDir(gSystem->pwd());
- TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
- TList* dirList = baseDir->GetListOfFiles();
- Int_t nDirs = dirList->GetEntries();
- gSystem->cd(execDir);
-
- Int_t count = 0;
-
- for (Int_t iDir=0; iDir<nDirs; ++iDir)
+ if (flags & 2)
{
- TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
- if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
- continue;
+ TString execDir(gSystem->pwd());
+ TSystemDirectory* baseDir = new TSystemDirectory(".", aDataDir);
+ TList* dirList = baseDir->GetListOfFiles();
+ Int_t nDirs = dirList->GetEntries();
+ gSystem->cd(execDir);
+
+ Int_t count = 0;
- if (offset > 0)
+ for (Int_t iDir=0; iDir<nDirs; ++iDir)
{
- --offset;
- continue;
- }
+ TSystemFile* presentDir = (TSystemFile*) dirList->At(iDir);
+ if (!presentDir || !presentDir->IsDirectory() || strcmp(presentDir->GetName(), ".") == 0 || strcmp(presentDir->GetName(), "..") == 0)
+ continue;
+
+ if (offset > 0)
+ {
+ --offset;
+ continue;
+ }
- if (count++ == aRuns)
- break;
+ if (count++ == aRuns)
+ break;
- TString presentDirName(aDataDir);
- presentDirName += "/";
- presentDirName += presentDir->GetName();
+ TString presentDirName(aDataDir);
+ presentDirName += "/";
+ presentDirName += presentDir->GetName();
- chain->Add(presentDirName + "/AliESDs.root/esdTree");
+ chain->Add(presentDirName + "/AliESDs.root/esdTree");
+ }
}
+ else
+ {
+ // Open the input stream
+ ifstream in;
+ in.open(aDataDir);
- return chain;
-}
+ Int_t count = 0;
-TChain* CreateESDChainFromList(const char* listFile, Int_t aRuns = 20)
-{
- // Creates a chain from a file which contains a list of ESD files
+ // Read the input list of files and add them to the chain
+ TString esdfile;
+ while(in.good()) {
+ in >> esdfile;
+ if (!esdfile.Contains("root")) continue; // protection
- if (!listFile)
- return 0;
+ if (offset > 0)
+ {
+ --offset;
+ continue;
+ }
- TChain* chain = new TChain("esdTree");
- TChain* chaingAlice = 0;
+ if (count++ == aRuns)
+ break;
+
+ // add esd file
+ chain->Add(esdfile);
+ }
+
+ in.close();
+ }
- // Open the input stream
- ifstream in;
- in.open(listFile);
+ return chain;
+}
- Int_t count = 0;
+void LookupWrite(TChain* chain, const char* target)
+{
+ // looks up the chain and writes the remaining files to the text file target
- // Read the input list of files and add them to the chain
- TString esdfile;
- while(in.good()) {
- in >> esdfile;
- if (!esdfile.Contains("root")) continue; // protection
+ chain->Lookup();
- if (count++ == aRuns)
- break;
+ TObjArray* list = chain->GetListOfFiles();
+ TIterator* iter = list->MakeIterator();
+ TObject* obj = 0;
- // add esd file
- chain->Add(esdfile);
- }
+ ofstream outfile;
+ outfile.open(target);
- in.close();
+ while ((obj = iter->Next()))
+ outfile << obj->GetTitle() << "#AliESDs.root" << endl;
- chain->Lookup();
+ outfile.close();
- return chain;
+ delete iter;
}