]>
Commit | Line | Data |
---|---|---|
27fcc3c7 | 1 | /** |
2 | * @file RunQA.C | |
3 | * @author Christian Holm Christensen <cholm@nbi.dk> | |
4 | * @date Thu Nov 17 11:35:08 2011 | |
5 | * | |
6 | * @brief Script to run the QATrender and QAPlotter in one go | |
7 | * | |
8 | * @ingroup pwglf_forward_qa_scripts | |
9 | */ | |
10 | /** | |
11 | * Scan directory (and possibly sub-directories) for trending files | |
12 | * | |
13 | * @param dir Start directory | |
14 | * @param list List to add file names to | |
15 | * @param recursive Whether to scan recursively | |
16 | * | |
17 | * @return true on success | |
18 | * | |
19 | * @deprecated Use the RunFileQA and RunFinalQA instead. | |
20 | * @ingroup pwglf_forward_qa_scripts | |
21 | */ | |
22 | Bool_t ScanDirectory(TSystemDirectory* dir, TList* list, | |
23 | bool recursive=false) | |
24 | { | |
25 | TString fnPattern = "trending_"; | |
26 | ||
27 | // Assume failure | |
28 | Bool_t ret = false; | |
29 | ||
30 | // Get list of files, and go back to old working directory | |
31 | TString oldDir(gSystem->WorkingDirectory()); | |
32 | TList* files = dir->GetListOfFiles(); | |
33 | if (!gSystem->ChangeDirectory(oldDir)) { | |
34 | Error("ScanDirectory", "Failed to go back to %s", oldDir.Data()); | |
35 | return false; | |
36 | } | |
37 | if (!files) { | |
38 | Warning("ScanDirectory", "No files found in %s", dir->GetName()); | |
39 | return false; | |
40 | } | |
41 | // files->ls(); | |
42 | ||
43 | TList toAdd; | |
44 | ||
45 | // Sort list of files and check if we should add it | |
46 | // files->Sort(); | |
47 | TIter next(files); | |
48 | TSystemFile* file = 0; | |
49 | while ((file = static_cast<TSystemFile*>(next()))) { | |
50 | TString name(file->GetName()); | |
51 | TString title(file->GetTitle()); | |
52 | TString full(gSystem->ConcatFileName(file->GetTitle(), name.Data())); | |
53 | if (file->IsA() == TSystemDirectory::Class()) full = title; | |
54 | // Ignore special links | |
55 | // Info("ScanDirectory", "name=%s title=%s full=%s", | |
56 | // name.Data(), title.Data(), full.Data()); | |
57 | if (name == "." || name == "..") { | |
58 | // Info("ScanDirectory", "Ignoring %s", name.Data()); | |
59 | continue; | |
60 | } | |
61 | ||
62 | FileStat_t fs; | |
63 | if (gSystem->GetPathInfo(full.Data(), fs)) { | |
64 | Warning("ScanDirectory", "Cannot stat %s (%s)", full.Data(), | |
65 | gSystem->WorkingDirectory()); | |
66 | continue; | |
67 | } | |
68 | // Check if this is a directory | |
69 | if (file->IsDirectory(full)) { | |
70 | if (recursive) { | |
71 | TSystemDirectory* d = new TSystemDirectory(file->GetName(), | |
72 | full.Data()); | |
73 | if (ScanDirectory(d,chain,type,recursive,mc)) | |
74 | ret = true; | |
75 | delete d; | |
76 | } | |
77 | continue; | |
78 | } | |
79 | ||
80 | // If this is not a root file, ignore | |
81 | if (!name.EndsWith(".root")) { | |
82 | // Info("ScanDirectory", "Ignoring non-ROOT file %s", name.Data()); | |
83 | continue; | |
84 | } | |
85 | ||
86 | // If this file does not contain AliESDs, ignore | |
87 | if (!name.Contains(fnPattern)) { | |
88 | // Info("ScanDirectory", "%s does not match pattern %s", | |
89 | // name.Data(), fnPattern.Data()); | |
90 | continue; | |
91 | } | |
92 | ||
93 | // Add | |
94 | // Info("ScanDirectory", "Adding %s", full.Data()); | |
95 | toAdd.Add(new TObjString(full)); | |
96 | } | |
97 | ||
98 | TIter nextAdd(&toAdd); | |
99 | TObjString* s = 0; | |
100 | while ((s = static_cast<TObjString*>(nextAdd()))) { | |
101 | // Info("ScanDirectory", "Adding %s", s->GetString().Data()); | |
102 | list->Add(s); | |
103 | } | |
104 | if (toAdd.GetEntries() > 0) ret = true; | |
105 | ||
106 | gSystem->ChangeDirectory(oldDir); | |
107 | return ret; | |
108 | } | |
109 | /** | |
110 | * Get the list of trending files | |
111 | * | |
112 | * @param input Start directory | |
113 | * | |
114 | * @return List of files | |
115 | * | |
116 | * @ingroup pwglf_forward_qa_scripts | |
117 | */ | |
118 | TList* | |
119 | GetListOfFiles(const char* input=".") | |
120 | { | |
121 | TList* ret = new TList; | |
122 | TString dir(input); | |
123 | // if (dir == ".") dir = ""; | |
124 | ||
125 | TString savdir(gSystem->WorkingDirectory()); | |
126 | TSystemDirectory d(gSystem->BaseName(dir.Data()), dir.Data()); | |
127 | if (!ScanDirectory(&d, ret, false)) { | |
128 | delete ret; | |
129 | ret = 0; | |
130 | } | |
131 | gSystem->ChangeDirectory(savdir); | |
132 | if (ret) ret->Sort(); | |
133 | return ret; | |
134 | } | |
135 | ||
136 | /** | |
137 | * Run the QATrender and QAPlotter. | |
138 | * | |
139 | * The QATrender is run over the list of files (runs) to produce the | |
140 | * file <tt>forward_trending.root</tt> which contains a TTree of QA | |
141 | * information - one entry per run. | |
142 | * | |
143 | * The QATrender will also produce two files per run: | |
144 | * | |
145 | * - <tt>qa_<i>runNo</i>.root</tt> which contains TCanvas objects of | |
146 | * the finished plots. | |
147 | * | |
148 | * - <tt>qa_<i>runNo</i>.pdf</tt> which is a PDF of the TCanvases | |
149 | * mentioned above. | |
150 | * | |
151 | * The QAPlotter is then run over the <tt>forward_trending.root</tt> | |
152 | * file and produces two files | |
153 | * | |
154 | * - <tt>qa_<i>first-run</i>-<i>last-run</i>.root</tt> which contains | |
155 | * TCanvas objects of the finished plots. It also contains the | |
156 | * TMultiGraph objects painted in the canvases. | |
157 | * | |
158 | * - <tt>qa_<i>first-run</i>-<i>last-run</i>.pdf</tt> which is a PDF | |
159 | * of the TCanvases mentioned above. | |
160 | * | |
161 | * The QAPlotter will also produce PNGs of each canvas. | |
162 | * | |
163 | * if @a runNo is larger than zero, given, then only the that run will | |
164 | * be processed and only by QATrender. In addition, PNGs of each | |
165 | * canvas is produced. | |
166 | * | |
167 | * @param runNo (optional) Run number. If greater than 0, only this | |
168 | * run will be processed | |
169 | * @param input Input directory | |
170 | * @param what (expert) Flag of what to do | |
171 | * @param keep | |
172 | * | |
173 | * @ingroup pwglf_forward_qa_scripts | |
174 | */ | |
175 | void | |
64557aeb | 176 | RunQAOld(const char* input=".", Bool_t keep=true, Int_t runNo=-1, |
177 | UShort_t what=0x3) | |
27fcc3c7 | 178 | { |
179 | gROOT->SetMacroPath(Form(".:$(ALICE_ROOT)/PWGLF/FORWARD/analysis2/qa:" | |
180 | "$(ALICE_ROOT)/PWGLF/FORWARD/analysis2/corrs:%s", | |
181 | gROOT->GetMacroPath())); | |
182 | gSystem->AddIncludePath("-I${ALICE_ROOT}/PWGLF/FORWARD/analysis2/qa"); | |
183 | gSystem->Load("libGpad"); | |
184 | gSystem->Load("libTree"); | |
185 | ||
186 | if (runNo > 0) what = 0x1; // Only do first pass | |
187 | ||
188 | gROOT->LoadMacro("QATrender.C+g"); | |
189 | gROOT->LoadMacro("QAPlotter.C+g"); | |
190 | if (what & 0x1) { | |
191 | QATrender t(keep, runNo > 0); | |
192 | ||
193 | TList* l = 0; | |
194 | if (runNo < 0) l = GetListOfFiles(input); | |
195 | else { | |
196 | TObjString* s = new TObjString(""); | |
197 | s->String() = gSystem->ConcatFileName(input, Form("trending_%09d.root", | |
198 | runNo)); | |
199 | l = new TList; | |
200 | l->Add(s); | |
201 | } | |
202 | if (!l) { | |
203 | Error("RunQA", "No trending files found"); | |
204 | return; | |
205 | } | |
206 | // l->ls(); | |
207 | TIter next(l); | |
208 | TObjString* s = 0; | |
209 | while ((s = static_cast<TObjString*>(next()))) { | |
210 | Info("Run", "Adding file %s", s->GetName()); | |
211 | t.AddFile(s->GetName()); | |
212 | } | |
213 | t.Run(); | |
214 | } | |
215 | if (what & 0x2) { | |
216 | QAPlotter p; | |
217 | p.Run(); | |
218 | } | |
219 | } | |
220 | // | |
221 | // EOF | |
222 | // |