]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/scripts/MakeESDChain.C
Renames and new scripts
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / scripts / MakeESDChain.C
CommitLineData
5d0ddfc1 1void
2ScanDirectory(TSystemDirectory* dir, TChain* chain, bool recursive)
ab0f914c 3{
5d0ddfc1 4 // gROOT->IndentLevel();
5 // Printf("Scanning %s ...", dir->GetName());
6 // gROOT->IncreaseDirLevel();
7
8
9 // Get list of files, and go back to old working directory
ab0f914c 10 TString oldDir(gSystem->WorkingDirectory());
5d0ddfc1 11 TList* files = dir->GetListOfFiles();
ab0f914c 12 gSystem->ChangeDirectory(oldDir);
13
14 // Sort list of files and check if we should add it
15 files->Sort();
16 TIter next(files);
17 TSystemFile* file = 0;
18 while ((file = static_cast<TSystemFile*>(next()))) {
ab0f914c 19 TString name(file->GetName());
5d0ddfc1 20
21 // Ignore special links
22 if (name == "." || name == "..") continue;
23
24 // Check if this is a directory
25 if (file->IsDirectory()) {
26 if (recursive)
27 ScanDirectory(static_cast<TSystemDirectory*>(file),chain,recursive);
28 continue;
29 }
30
31 // If this is not a root file, ignore
ab0f914c 32 if (!name.EndsWith(".root")) continue;
5d0ddfc1 33
34 // If this file does not contain AliESDs, ignore
ab0f914c 35 if (!name.Contains("AliESDs")) continue;
5d0ddfc1 36
37 // Get the path
ab0f914c 38 TString esd(Form("%s/%s", file->GetTitle(), name.Data()));
5d0ddfc1 39
40 // Print and add
41 // gROOT->IndentLevel();
42 // Printf("adding %s", esd.Data());
ab0f914c 43 chain->Add(esd);
5d0ddfc1 44
45 }
46 // gROOT->DecreaseDirLevel();
47}
48
49TChain*
50MakeESDChain(const char* esddir, bool recursive=false)
51{
52 // --- Our data chain ----------------------------------------------
53 TChain* chain = new TChain("esdTree");
54
55 // --- Get list of ESDs --------------------------------------------
56 // Open source directory, and make sure we go back to were we were
57 TString oldDir(gSystem->WorkingDirectory());
58 TSystemDirectory d(esddir, esddir);
59 ScanDirectory(&d, chain, recursive);
60
61 // chain->GetListOfFiles()->ls();
62
ab0f914c 63 return chain;
64}