3 * @author Christian Holm Christensen <cholm@nbi.dk>
4 * @date Thu Nov 17 11:58:11 2011
6 * @brief Base class for QA active classes
8 * @ingroup pwglf_forward_qa_scripts
32 * Base class for active QA classes. This manages the I/O files, like
33 * the tree file, the LaTeX file, and the storage file
35 * @ingroup pwglf_forward_qa_scripts
42 * @param single If true, only process one file.
44 QABase(Bool_t single=false)
60 fOutputName("forward_trend.root")
65 * @param o Object to copy from
67 QABase(const QABase& o)
80 fToDelete(o.fToDelete),
83 fOutputName(o.fOutputName)
88 * @return Reference to this object
90 QABase& operator=(const QABase&) { return *this; }
96 if (fFMD1i) { delete fFMD1i; }
97 if (fFMD2i) { delete fFMD2i; }
98 if (fFMD2o) { delete fFMD2o; }
99 if (fFMD3i) { delete fFMD3i; }
100 if (fFMD3o) { delete fFMD3o; }
101 if (fGlobal) { delete fGlobal; }
102 if (fTree) { delete fTree; }
103 if (fOutput) { delete fOutput; }
104 if (fStore) { delete fStore; }
105 if (fTeX) { fTeX->close(); fTeX = 0; }
106 if (fHtml) { fHtml->close(); fHtml = 0; }
109 * Set the output file name
111 * @param name Name of output (tree) file
113 void SetOutputName(const char* name) { fOutputName = name; }
115 * The name of the TTree output file
117 * @return Output file name
119 const char* OutputName() const { return fOutputName.Data(); }
123 * @param read If true, read from file
125 * @return True on success
127 virtual Bool_t MakeTree(bool read)
130 fOutput = new TFile(OutputName(), (read ? "READ" : "RECREATE"));
132 Error("MakeTree", "Failed to open output file");
135 if (read) fTree = static_cast<TTree*>(fOutput->Get("T"));
136 else fTree = new TTree("T", "T");
139 Error("MakeTree", "No tree defined!");
148 * @param read If true initialise for reading tree file
150 * @return True on success
152 Bool_t Init(bool read=false)
154 if (!MakeTree(read)) return false;
156 if (read) fGlobal = Global::SetBranch(fTree);
157 else fGlobal = Global::MakeBranch(fTree);
161 fFMD1i->Init(fTree, read);
162 fFMD2i->Init(fTree, read);
163 fFMD2o->Init(fTree, read);
164 fFMD3i->Init(fTree, read);
165 fFMD3o->Init(fTree, read);
170 * Make a canvas, LaTeX file, and storage file
172 * @param title Title of canvas and files
174 void MakeCanvas(const char* title)
180 const char* base = fTeXName.Data();
181 gSystem->Exec(Form("rm -f %s.tex %s.html %s.root %s.pdf",
182 base, base, base, base));
184 fTeX = new std::ofstream(Form("%s.tex", base));
185 fHtml = new std::ofstream(Form("%s.html", base));
187 *fTeX << "\\documentclass[landscape,a4paper,12pt]{article}\n"
188 << "\\usepackage[margin=2cm,a4paper]{geometry}\n"
189 << "\\usepackage{graphicx}\n"
190 << "\\title{{\\Huge\\bf " << title << "}}\n"
191 << "\\author{{\\LARGE FMD Team}}\n"
192 << "\\date{{\\Large \\today}}\n"
193 << "\\begin{document}\n"
194 << "\\thispagestyle{empty}\n"
195 << "\\maketitle" << std::endl;
199 << " <title>QA information - " << title << "</title>\n"
200 << " <link rel='stylesheet' href='style.css'>\n"
203 << " <h1>" << title << "</h1>\n"
207 gStyle->SetPalette(1);
208 gStyle->SetOptFit(0);
209 gStyle->SetOptStat(0);
210 gStyle->SetOptTitle(1);
211 gStyle->SetTitleW(.4);
212 gStyle->SetTitleH(.1);
213 // gStyle->SetTitleColor(0);
214 gStyle->SetTitleStyle(0);
215 gStyle->SetTitleBorderSize(0);
216 gStyle->SetTitleX(.6);
218 fCanvas = new TCanvas("qa", title, 900, 700);
219 fCanvas->SetFillColor(0);
220 fCanvas->SetBorderSize(0);
221 fCanvas->SetLeftMargin(0.15);
222 fCanvas->SetRightMargin(0.02);
223 fCanvas->SetTopMargin(0.10);
224 fCanvas->SetBottomMargin(0.10);
226 fStore = TFile::Open(Form("%s.root", fTeXName.Data()), "RECREATE");
228 Warning("MakeCanvas", "Failed to make store %s.root", fTeXName.Data());
233 * Put a title on the canvas. Also clears page in LaTeX file
237 void CanvasTitle(const char* title)
239 if (!fCanvas) return;
243 fCanvas->SetBorderSize(0);
244 fCanvas->SetLeftMargin(0.15);
245 fCanvas->SetRightMargin(0.02);
246 fCanvas->SetTopMargin(0.10);
247 fCanvas->SetBottomMargin(0.10);
249 *fTeX << "\\clearpage\n"
250 << "%% -----------------------------------------------------"
254 tit.ReplaceAll("#LT", "<");
255 tit.ReplaceAll("#GT", ">");
256 tit.ReplaceAll("#Delta", "Δ");
257 tit.ReplaceAll("#xi", "ξ");
258 tit.ReplaceAll("#sigma", "σ");
259 tit.ReplaceAll("#chi", "χ");
260 tit.ReplaceAll("#nu", "ν");
261 tit.ReplaceAll("_{p}", "<sub>p</sub>");
262 tit.ReplaceAll("_{z}", "<sub>z</sub>");
263 tit.ReplaceAll("^{2}", "<sup>2</sup>");
264 *fHtml << "<tr><td>" << tit << "</td>" << std::flush;
266 PutCanvasTitle(title);
269 * Put a title on the canvas
273 void PutCanvasTitle(const char* title)
276 TLatex* topText = new TLatex(.5, .99, title);
277 topText->SetTextAlign(23);
278 topText->SetTextSize(.038);
279 topText->SetTextFont(42);
280 topText->SetTextColor(kBlue+3);
285 * Print the canvas to PNG and include it into LaTeX file
287 * @param pngName Base name of PNG
288 * @param runNo Run number to append
290 void PrintCanvas(const char* pngName, UInt_t runNo)
292 TString s(Form("%s_%09d", pngName, runNo));
293 PrintCanvas(s.Data());
296 * Print the canvas to PNG and include it into LaTeX file. Stores
297 * canvas in storage file
299 * @param pngName Base name of PNG
301 void PrintCanvas(const char* pngName)
303 gSystem->Exec(Form("rm -f %s.png %s.html", pngName, pngName));
304 fCanvas->SaveAs(Form("%s.png", pngName));
305 *fTeX << "\\begin{center}\n"
306 << "\\includegraphics[keepaspectratio,height=\\textheight]{"
308 << "\\end{center}" << std::endl;
309 *fHtml << "<td><a href='" << pngName << ".html'>Plot</a></td></tr>"
312 std::ofstream img(Form("%s.html", pngName));
315 << " <title>" << pngName << "</title>\n"
316 << " <link rel='stylesheet' href='style.css'>\n"
319 << " <h1>" << pngName << "</h1>\n"
320 << " <div class='img'>\n"
321 << " <img src='" << pngName << ".png'>\n"
322 << " </div>\n" << std::endl;
323 WriteImageFooter(img, pngName);
325 << "</html>" << std::endl;
327 gSystem->Exec(Form("chmod g+rw %s.html", pngName));
329 fToDelete.Append(Form(" %s.png", pngName));
330 TDirectory* d = gDirectory;
336 * Write out image footer
338 * @param o Output stream
340 virtual void WriteImageFooter(std::ostream& o, const char* /*pngName*/)
343 o << "<div class='back'>\n"
344 << "<a href='" << fTeXName << ".html'>Back</a>\n"
346 << "<div class='change'>\n"
347 << " Last update: " << now.AsString() << "\n"
348 << "</div>" << std::endl;
351 * Close the LaTeX and storage files. Runs PDFLaTeX on LaTeX
352 * file. Makes sure that the files are group writable.
354 * @param deletePNGs If true, delete intermident PNG files
356 void Close(bool deletePNGs=true)
358 const char* base = fTeXName.Data();
360 *fTeX << "\\end{document}\n"
361 << "%% EOF" << std::endl;
365 gSystem->Exec(Form("pdflatex %s.tex > /dev/null 2>&1", base));
366 Info("Close", "PDF file %s.pdf generated", base);
370 *fHtml << "</table>" << std::endl;
373 *fHtml << "</body></html>" << std::endl;
376 gSystem->Exec(Form("chmod g+rw %s.html", fTeXName.Data()));
381 gSystem->Exec(Form("chmod 664 %s.root", fTeXName.Data()));
383 TString cmd(Form("rm -f %s.log %s.aux %s.tex %s",
385 deletePNGs ? fToDelete.Data() : ""));
386 gSystem->Exec(cmd.Data());
387 gSystem->Exec(Form("chmod g+rw %s.pdf %s", base,
388 deletePNGs ? "" : fToDelete.Data()));
394 virtual void WriteLinks()
396 *fHtml << "<h3>Collection of plots</h3>\n"
398 << " <li><a href='" << fTeXName << ".pdf'>PDF</a></li>\n"
399 << " <li><a href='" << fTeXName << ".root'>ROOT</a></li>\n"
400 << "</ul>" << std::endl;
403 * Write full job footer
406 virtual void WriteFooter()
409 *fHtml << "<div class='back'>\n"
410 << "<a href='index.html'>Back</a>\n"
412 << "<div class='change'>\n"
413 << " Last update: " << now.AsString() << "\n"
414 << "</div>" << std::endl;
416 // --- Members -----------------------------------------------------
417 QARing* fFMD1i; // Pointer to ring object
418 QARing* fFMD2i; // Pointer to ring object
419 QARing* fFMD2o; // Pointer to ring object
420 QARing* fFMD3i; // Pointer to ring object
421 QARing* fFMD3o; // Pointer to ring object
422 Global* fGlobal; // Pointer to global run object
423 TTree* fTree; // Pointer to tree object
424 TFile* fOutput; // Pointer to tree file
425 TFile* fStore; // Pointer to storage file
426 std::ofstream* fTeX; // pointer to LaTeX stream
427 std::ofstream* fHtml; // pointer to HTML stream
428 TString fTeXName; // Base name of LaTeX file
429 TString fToDelete; // List of files to possibly delete
430 TCanvas* fCanvas; // Pointer to canvas object
431 Bool_t fSingle; // Whether we're processing one run only
432 TString fOutputName; // Output tree file name