]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/scripts/MakeChain.C
Modifications to Run.sh script
[u/mrichter/AliRoot.git] / PWG2 / FORWARD / analysis2 / scripts / MakeChain.C
CommitLineData
b2e7f2d6 1/**
2 * Scan a directory (optionally recursive) for data files to add to
3 * the chain. Only ROOT files, and files which name contain the
4 * passed pattern are considered.
5 *
6 * @param dir Directory to scan
7 * @param chain Chain to add data to
8 * @param pattern Pattern that the file name must contain
9 * @param recursive Whether to scan recursively
10 */
f00964c7 11
b2e7f2d6 12void
13ScanDirectory(TSystemDirectory* dir, TChain* chain,
14 const char* pattern, bool recursive)
15{
16 // Get list of files, and go back to old working directory
17 TString oldDir(gSystem->WorkingDirectory());
18 TList* files = dir->GetListOfFiles();
19 gSystem->ChangeDirectory(oldDir);
20
21 // Sort list of files and check if we should add it
22 files->Sort();
23 TIter next(files);
24 TSystemFile* file = 0;
25 while ((file = static_cast<TSystemFile*>(next()))) {
26 TString name(file->GetName());
27
28 // Ignore special links
29 if (name == "." || name == "..") continue;
30
31 // Check if this is a directory
32 if (file->IsDirectory()) {
33 if (recursive)
f00964c7 34 ScanDirectory(static_cast<TSystemDirectory*>(file),chain,pattern,recursive);
b2e7f2d6 35 continue;
36 }
37
38 // If this is not a root file, ignore
39 if (!name.EndsWith(".root")) continue;
40
41 // If this file does not contain the pattern, ignore
42 if (!name.Contains(pattern)) continue;
43
44 // Get the path
45 TString data(Form("%s/%s", file->GetTitle(), name.Data()));
46
47 chain->Add(data);
48
49 }
50}
51
52/**
53 * Make a chain of specified data
54 *
55 * @param what What data to chain. Possible values are
56 * - ESD Event summary data (AliESD)
57 * - AOD Analysis object data (AliAOD)
58 * - MC Simulation data (galice)
59 * @param datadir Data directory to scan
60 * @param recursive Whether to recurse into sub-directories
61 *
62 * @return Pointer to newly create chain, or null
63 */
64TChain*
65MakeChain(const char* what, const char* datadir, bool recursive=false)
66{
67 TString w(what);
68 w.ToUpper();
69 const char* treeName = 0;
70 const char* pattern = 0;
71 if (w.Contains("ESD")) { treeName = "esdTree"; pattern = "AliESD"; }
72 else if (w.Contains("AOD")) { treeName = "aodTree"; pattern = "AliAOD"; }
73 else if (w.Contains("MC")) { treeName = "TE"; pattern = "galice"; }
74 else {
75 Error("MakeChain", "Unknown mode '%s' (not one of ESD,AOD, or MC)", what);
76 return 0;
77 }
78
79 // --- Our data chain ----------------------------------------------
80 TChain* chain = new TChain(treeName);
81
82 // --- Get list of ESDs --------------------------------------------
83 // Open source directory, and make sure we go back to were we were
84 TString oldDir(gSystem->WorkingDirectory());
85 TSystemDirectory d(datadir, datadir);
86 ScanDirectory(&d, chain, pattern, recursive);
87
88 return chain;
89}