3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Fri Jan 6 11:46:30 2012
8 * @ingroup pwg2_forward_qa_scripts
10 //____________________________________________________________________
12 * Scan directory (and possibly sub-directories) for trending files
14 * @param dir Start directory
15 * @param list List to add file names to
16 * @param recursive Whether to scan recursively
18 * @return true on success
20 * @ingroup pwg2_forward_qa_scripts
22 Bool_t ScanDirectory(TSystemDirectory* dir,
27 TString fnPattern = pattern;
32 // Get list of files, and go back to old working directory
33 TString oldDir(gSystem->WorkingDirectory());
34 TList* files = dir->GetListOfFiles();
35 if (!gSystem->ChangeDirectory(oldDir)) {
36 Error("ScanDirectory", "Failed to go back to %s", oldDir.Data());
40 Warning("ScanDirectory", "No files found in %s", dir->GetName());
47 // Sort list of files and check if we should add it
50 TSystemFile* file = 0;
51 while ((file = static_cast<TSystemFile*>(next()))) {
52 TString name(file->GetName());
53 TString title(file->GetTitle());
54 TString full(gSystem->ConcatFileName(file->GetTitle(), name.Data()));
55 if (file->IsA() == TSystemDirectory::Class()) full = title;
56 if (name == "." || name == "..") {
61 if (gSystem->GetPathInfo(full.Data(), fs)) {
62 Warning("ScanDirectory", "Cannot stat %s (%s)", full.Data(),
63 gSystem->WorkingDirectory());
66 // Check if this is a directory
67 if (file->IsDirectory(full)) {
69 TSystemDirectory* d = new TSystemDirectory(file->GetName(),
71 if (ScanDirectory(d,list,pattern,recursive))
78 // If this is not a root file, ignore
79 if (!name.EndsWith(".root")) {
83 // If this file does not contain AliESDs, ignore
84 if (!name.Contains(fnPattern)) {
89 toAdd.Add(new TObjString(full));
92 TIter nextAdd(&toAdd);
94 while ((s = static_cast<TObjString*>(nextAdd()))) {
97 if (toAdd.GetEntries() > 0) ret = true;
99 gSystem->ChangeDirectory(oldDir);
102 //____________________________________________________________________
104 * Get the list of trending files
106 * @param input Start directory
108 * @return List of files
110 * @ingroup pwg2_forward_qa_scripts
113 GetListOfFiles(const char* input=".")
115 TList* ret = new TList;
117 // if (dir == ".") dir = "";
119 TString savdir(gSystem->WorkingDirectory());
120 TSystemDirectory d(gSystem->BaseName(dir.Data()), dir.Data());
121 if (!ScanDirectory(&d, ret, "tree_", false)) {
125 gSystem->ChangeDirectory(savdir);
126 if (ret) ret->Sort();
130 //____________________________________________________________________
136 * @ingroup pwg2_forward_qa_scripts
139 RunFinalQA(const char* dir)
142 gROOT->SetMacroPath(Form(".:$(ALICE_ROOT)/PWG2/FORWARD/analysis2/qa:"
143 "$(ALICE_ROOT)/PWG2/FORWARD/analysis2/corrs:%s",
144 gROOT->GetMacroPath()));
145 gSystem->AddIncludePath("-I${ALICE_ROOT}/PWG2/FORWARD/analysis2/qa");
146 gSystem->Load("libGpad");
147 gSystem->Load("libTree");
149 gROOT->LoadMacro("QABase.h+g");
150 gROOT->LoadMacro("QAPlotter.C+g");
154 TList* l = GetListOfFiles(dir);
157 while ((o = next())) {
158 p.AddFile(o->GetName());