3 * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk>
4 * @date Fri Jan 6 11:46:30 2012
8 * @ingroup pwglf_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
17 * @param pattern Pattern filenames must match
19 * @return true on success
21 * @ingroup pwglf_forward_qa_scripts
23 Bool_t ScanDirectory(TSystemDirectory* dir,
28 TString fnPattern = pattern;
33 // Get list of files, and go back to old working directory
34 TString oldDir(gSystem->WorkingDirectory());
35 TList* files = dir->GetListOfFiles();
36 if (!gSystem->ChangeDirectory(oldDir)) {
37 Error("ScanDirectory", "Failed to go back to %s", oldDir.Data());
41 Warning("ScanDirectory", "No files found in %s", dir->GetName());
48 // Sort list of files and check if we should add it
51 TSystemFile* file = 0;
52 while ((file = static_cast<TSystemFile*>(next()))) {
53 TString name(file->GetName());
54 TString title(file->GetTitle());
55 TString full(gSystem->ConcatFileName(file->GetTitle(), name.Data()));
56 if (file->IsA() == TSystemDirectory::Class()) full = title;
57 if (name == "." || name == "..") {
62 if (gSystem->GetPathInfo(full.Data(), fs)) {
63 Warning("ScanDirectory", "Cannot stat %s (%s)", full.Data(),
64 gSystem->WorkingDirectory());
67 // Check if this is a directory
68 if (file->IsDirectory(full)) {
70 TSystemDirectory* d = new TSystemDirectory(file->GetName(),
72 if (ScanDirectory(d,list,pattern,recursive))
79 // If this is not a root file, ignore
80 if (!name.EndsWith(".root")) {
84 // If this file does not contain AliESDs, ignore
85 if (!name.Contains(fnPattern)) {
90 toAdd.Add(new TObjString(full));
93 TIter nextAdd(&toAdd);
95 while ((s = static_cast<TObjString*>(nextAdd()))) {
98 if (toAdd.GetEntries() > 0) ret = true;
100 gSystem->ChangeDirectory(oldDir);
103 //____________________________________________________________________
105 * Get the list of trending files
107 * @param input Start directory
109 * @return List of files
111 * @ingroup pwglf_forward_qa_scripts
114 GetListOfFiles(const char* input=".")
116 TList* ret = new TList;
118 // if (dir == ".") dir = "";
120 TString savdir(gSystem->WorkingDirectory());
121 TSystemDirectory d(gSystem->BaseName(dir.Data()), dir.Data());
122 if (!ScanDirectory(&d, ret, "tree_", false)) {
126 gSystem->ChangeDirectory(savdir);
127 if (ret) ret->Sort();
131 //____________________________________________________________________
135 * @param dir Input directory
136 * @param prodYear Production year
137 * @param prodLetter Production letter
139 * @ingroup pwglf_forward_qa_scripts
142 RunFinalQA(const char* dir, Int_t prodYear=0, const char* prodLetter="")
145 gROOT->SetMacroPath(Form(".:%s",gROOT->GetMacroPath()));
146 gSystem->Load("libGpad");
147 gSystem->Load("libTree");
149 gROOT->LoadMacro("QABase.h+g");
150 gROOT->LoadMacro("QAPlotter.C+g");
152 QAPlotter p(prodYear, prodLetter[0]);
154 TList* l = GetListOfFiles(dir);
157 while ((o = next())) {
158 p.AddFile(o->GetName());