]>
Commit | Line | Data |
---|---|---|
5c75ba4f | 1 | /** |
2 | * @file RunFinalQA.C | |
3 | * @author Christian Holm Christensen <cholm@master.hehi.nbi.dk> | |
4 | * @date Fri Jan 6 11:46:30 2012 | |
5 | * | |
6 | * @brief | |
7 | * | |
bd6f5206 | 8 | * @ingroup pwglf_forward_qa_scripts |
5c75ba4f | 9 | */ |
10 | //____________________________________________________________________ | |
11 | /** | |
12 | * Scan directory (and possibly sub-directories) for trending files | |
13 | * | |
14 | * @param dir Start directory | |
15 | * @param list List to add file names to | |
16 | * @param recursive Whether to scan recursively | |
60db3344 | 17 | * @param pattern Pattern filenames must match |
5c75ba4f | 18 | * |
19 | * @return true on success | |
20 | * | |
bd6f5206 | 21 | * @ingroup pwglf_forward_qa_scripts |
5c75ba4f | 22 | */ |
23 | Bool_t ScanDirectory(TSystemDirectory* dir, | |
24 | TList* list, | |
25 | const char* pattern, | |
26 | bool recursive=false) | |
27 | { | |
28 | TString fnPattern = pattern; | |
29 | ||
30 | // Assume failure | |
31 | Bool_t ret = false; | |
32 | ||
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()); | |
38 | return false; | |
39 | } | |
40 | if (!files) { | |
41 | Warning("ScanDirectory", "No files found in %s", dir->GetName()); | |
42 | return false; | |
43 | } | |
44 | // files->ls(); | |
45 | ||
46 | TList toAdd; | |
47 | ||
48 | // Sort list of files and check if we should add it | |
49 | // files->Sort(); | |
50 | TIter next(files); | |
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 == "..") { | |
58 | continue; | |
59 | } | |
60 | ||
61 | FileStat_t fs; | |
62 | if (gSystem->GetPathInfo(full.Data(), fs)) { | |
63 | Warning("ScanDirectory", "Cannot stat %s (%s)", full.Data(), | |
64 | gSystem->WorkingDirectory()); | |
65 | continue; | |
66 | } | |
67 | // Check if this is a directory | |
68 | if (file->IsDirectory(full)) { | |
69 | if (recursive) { | |
70 | TSystemDirectory* d = new TSystemDirectory(file->GetName(), | |
71 | full.Data()); | |
72 | if (ScanDirectory(d,list,pattern,recursive)) | |
73 | ret = true; | |
74 | delete d; | |
75 | } | |
76 | continue; | |
77 | } | |
78 | ||
79 | // If this is not a root file, ignore | |
80 | if (!name.EndsWith(".root")) { | |
81 | continue; | |
82 | } | |
83 | ||
84 | // If this file does not contain AliESDs, ignore | |
85 | if (!name.Contains(fnPattern)) { | |
86 | continue; | |
87 | } | |
88 | ||
89 | // Add | |
90 | toAdd.Add(new TObjString(full)); | |
91 | } | |
92 | ||
93 | TIter nextAdd(&toAdd); | |
94 | TObjString* s = 0; | |
95 | while ((s = static_cast<TObjString*>(nextAdd()))) { | |
96 | list->Add(s); | |
97 | } | |
98 | if (toAdd.GetEntries() > 0) ret = true; | |
99 | ||
100 | gSystem->ChangeDirectory(oldDir); | |
101 | return ret; | |
102 | } | |
103 | //____________________________________________________________________ | |
104 | /** | |
105 | * Get the list of trending files | |
106 | * | |
107 | * @param input Start directory | |
108 | * | |
109 | * @return List of files | |
110 | * | |
bd6f5206 | 111 | * @ingroup pwglf_forward_qa_scripts |
5c75ba4f | 112 | */ |
113 | TList* | |
114 | GetListOfFiles(const char* input=".") | |
115 | { | |
116 | TList* ret = new TList; | |
117 | TString dir(input); | |
118 | // if (dir == ".") dir = ""; | |
119 | ||
120 | TString savdir(gSystem->WorkingDirectory()); | |
121 | TSystemDirectory d(gSystem->BaseName(dir.Data()), dir.Data()); | |
122 | if (!ScanDirectory(&d, ret, "tree_", false)) { | |
123 | delete ret; | |
124 | ret = 0; | |
125 | } | |
126 | gSystem->ChangeDirectory(savdir); | |
127 | if (ret) ret->Sort(); | |
128 | return ret; | |
129 | } | |
130 | ||
131 | //____________________________________________________________________ | |
132 | /** | |
133 | * | |
134 | * | |
c8b1a7db | 135 | * @param dir Input directory |
136 | * @param prodYear Production year | |
33438b4c | 137 | * @param prodLetter Production letter |
c8b1a7db | 138 | * @param useVar Use variance for errors (rather than min/max) |
5c75ba4f | 139 | * |
bd6f5206 | 140 | * @ingroup pwglf_forward_qa_scripts |
5c75ba4f | 141 | */ |
142 | void | |
2e658fb9 | 143 | RunFinalQA(const char* dir, Int_t prodYear=0, const char* prodLetter="", |
144 | Bool_t useVar=false) | |
5c75ba4f | 145 | { |
146 | int ret = 0; | |
7fbaa8da | 147 | gROOT->SetMacroPath(Form(".:%s",gROOT->GetMacroPath())); |
5c75ba4f | 148 | gSystem->Load("libGpad"); |
149 | gSystem->Load("libTree"); | |
150 | ||
151 | gROOT->LoadMacro("QABase.h+g"); | |
152 | gROOT->LoadMacro("QAPlotter.C+g"); | |
153 | ||
2e658fb9 | 154 | Info("RunFinalQA", "Final QA: %d%c (variance: %s)", |
155 | prodYear, prodLetter[0], (useVar ? "true" : "false")); | |
156 | QAPlotter p(prodYear, prodLetter[0], useVar); | |
5c75ba4f | 157 | |
158 | TList* l = GetListOfFiles(dir); | |
159 | TIter next(l); | |
160 | TObject* o = 0; | |
161 | while ((o = next())) { | |
162 | p.AddFile(o->GetName()); | |
163 | } | |
164 | ||
165 | p.Run(); | |
166 | } | |
167 | // | |
168 | // EOF | |
169 | // |