]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/FORWARD/analysis2/scripts/MakeChain.C
Documentation fixes for doxygen
[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
56199f2b 10 *
11 * @ingroup pwg2_forward_analysis_scripts
b2e7f2d6 12 */
13void
14ScanDirectory(TSystemDirectory* dir, TChain* chain,
15 const char* pattern, bool recursive)
16{
17 // Get list of files, and go back to old working directory
18 TString oldDir(gSystem->WorkingDirectory());
19 TList* files = dir->GetListOfFiles();
20 gSystem->ChangeDirectory(oldDir);
21
22 // Sort list of files and check if we should add it
23 files->Sort();
24 TIter next(files);
25 TSystemFile* file = 0;
26 while ((file = static_cast<TSystemFile*>(next()))) {
27 TString name(file->GetName());
28
29 // Ignore special links
30 if (name == "." || name == "..") continue;
31
32 // Check if this is a directory
33 if (file->IsDirectory()) {
34 if (recursive)
b5c9a732 35 ScanDirectory(static_cast<TSystemDirectory*>(file),chain,
36 pattern,recursive);
b2e7f2d6 37 continue;
38 }
39
40 // If this is not a root file, ignore
41 if (!name.EndsWith(".root")) continue;
42
43 // If this file does not contain the pattern, ignore
44 if (!name.Contains(pattern)) continue;
b5c9a732 45 if (name.Contains("friends")) continue;
b2e7f2d6 46
47 // Get the path
48 TString data(Form("%s/%s", file->GetTitle(), name.Data()));
49
b5c9a732 50 TFile* test = TFile::Open(data.Data(), "READ");
51 if (!test || test->IsZombie()) {
52 Warning("ScanDirectory", "Failed to open file %s", data.Data());
53 continue;
54 }
55 test->Close();
b2e7f2d6 56 chain->Add(data);
57
58 }
59}
60
61/**
62 * Make a chain of specified data
63 *
64 * @param what What data to chain. Possible values are
65 * - ESD Event summary data (AliESD)
66 * - AOD Analysis object data (AliAOD)
67 * - MC Simulation data (galice)
68 * @param datadir Data directory to scan
69 * @param recursive Whether to recurse into sub-directories
70 *
71 * @return Pointer to newly create chain, or null
56199f2b 72 *
73 * @ingroup pwg2_forward_analysis_scripts
b2e7f2d6 74 */
75TChain*
76MakeChain(const char* what, const char* datadir, bool recursive=false)
77{
78 TString w(what);
79 w.ToUpper();
80 const char* treeName = 0;
81 const char* pattern = 0;
82 if (w.Contains("ESD")) { treeName = "esdTree"; pattern = "AliESD"; }
83 else if (w.Contains("AOD")) { treeName = "aodTree"; pattern = "AliAOD"; }
84 else if (w.Contains("MC")) { treeName = "TE"; pattern = "galice"; }
85 else {
86 Error("MakeChain", "Unknown mode '%s' (not one of ESD,AOD, or MC)", what);
87 return 0;
88 }
89
90 // --- Our data chain ----------------------------------------------
91 TChain* chain = new TChain(treeName);
92
93 // --- Get list of ESDs --------------------------------------------
94 // Open source directory, and make sure we go back to were we were
95 TString oldDir(gSystem->WorkingDirectory());
96 TSystemDirectory d(datadir, datadir);
97 ScanDirectory(&d, chain, pattern, recursive);
98
99 return chain;
100}
56199f2b 101//
102// EOF
103//