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.
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
11 * @ingroup pwg2_forward_analysis_scripts
14 ScanDirectory(TSystemDirectory* dir, TChain* chain,
15 const char* pattern, bool recursive)
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);
22 // Sort list of files and check if we should add it
25 TSystemFile* file = 0;
26 while ((file = static_cast<TSystemFile*>(next()))) {
27 TString name(file->GetName());
29 // Ignore special links
30 if (name == "." || name == "..") continue;
32 // Check if this is a directory
33 if (file->IsDirectory()) {
35 ScanDirectory(static_cast<TSystemDirectory*>(file),chain,
40 // If this is not a root file, ignore
41 if (!name.EndsWith(".root")) continue;
43 // If this file does not contain the pattern, ignore
44 if (!name.Contains(pattern)) continue;
45 if (name.Contains("friends")) continue;
48 TString data(Form("%s/%s", file->GetTitle(), name.Data()));
50 TFile* test = TFile::Open(data.Data(), "READ");
51 if (!test || test->IsZombie()) {
52 Warning("ScanDirectory", "Failed to open file %s", data.Data());
62 * Make a chain of specified data
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
71 * @return Pointer to newly create chain, or null
73 * @ingroup pwg2_forward_analysis_scripts
76 MakeChain(const char* what, const char* datadir, bool recursive=false)
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"; }
86 Error("MakeChain", "Unknown mode '%s' (not one of ESD,AOD, or MC)", what);
90 // --- Our data chain ----------------------------------------------
91 TChain* chain = new TChain(treeName);
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);