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
39 QABase(const TString& dataType,
41 const TString& period,
57 fOutputName("trending.root"),
66 * @param o Object to copy from
68 QABase(const QABase& o)
81 fToDelete(o.fToDelete),
83 fOutputName(o.fOutputName),
84 fDataType(o.fDataType),
92 * @return Reference to this object
94 QABase& operator=(const QABase&) { return *this; }
100 if (fFMD1i) { delete fFMD1i; }
101 if (fFMD2i) { delete fFMD2i; }
102 if (fFMD2o) { delete fFMD2o; }
103 if (fFMD3i) { delete fFMD3i; }
104 if (fFMD3o) { delete fFMD3o; }
105 if (fGlobal) { delete fGlobal; }
106 if (fTree) { delete fTree; }
107 if (fOutput) { delete fOutput; }
108 if (fStore) { delete fStore; }
109 if (fTeX) { fTeX->close(); fTeX = 0; }
110 if (fHtml) { fHtml->close(); fHtml = 0; }
113 * Set the output file name
115 * @param name Name of output (tree) file
117 void SetOutputName(const char* name) { fOutputName = name; }
119 * The name of the TTree output file
121 * @return Output file name
123 const char* OutputName() const { return fOutputName.Data(); }
127 * @param read If true, read from file
129 * @return True on success
131 virtual Bool_t MakeTree(bool read)
133 fOutput = new TFile(OutputName(), (read ? "READ" : "RECREATE"));
135 Error("MakeTree", "Failed to open output file");
138 if (read) fTree = static_cast<TTree*>(fOutput->Get("T"));
139 else fTree = new TTree("T", "T");
141 Error("MakeTree", "No tree defined!");
150 * @param read If true initialise for reading tree file
152 * @return True on success
154 Bool_t Init(bool read=false)
156 if (!MakeTree(read)) return false;
158 if (read) fGlobal = Global::SetBranch(fTree);
159 else fGlobal = Global::MakeBranch(fTree);
163 fFMD1i->Init(fTree, read);
164 fFMD2i->Init(fTree, read);
165 fFMD2o->Init(fTree, read);
166 fFMD3i->Init(fTree, read);
167 fFMD3o->Init(fTree, read);
172 * Make a canvas, LaTeX file, and storage file
174 * @param title Title of canvas and files
176 void MakeCanvas(const char* title)
182 const char* base = fTeXName.Data();
183 gSystem->Exec(Form("rm -f %s.tex %s.html %s.root %s.pdf",
184 base, base, base, base));
186 fTeX = new std::ofstream(Form("%s.tex", base));
187 fHtml = new std::ofstream(Form("%s.html", base));
189 TString texTitle(title);
190 texTitle.ReplaceAll("_", "-");
192 *fTeX << "\\documentclass[landscape,a4paper,12pt]{article}\n"
194 << "\\usepackage[margin=2cm,a4paper]{geometry}\n"
195 << "\\usepackage{graphicx}\n"
196 << "\\title{{\\Huge\\bf " << texTitle << "}}\n"
197 << "\\author{{\\LARGE FMD Team}}\n"
198 << "\\date{{\\Large \\today}}\n"
199 << "\\begin{document}\n"
200 << "\\thispagestyle{empty}\n"
201 << "\\maketitle" << std::endl;
203 *fHtml << "<!DOCTYPE html>\n"
206 << " <title>QA information - " << title << "</title>\n"
207 << " <link rel='stylesheet' href='style.css'>\n"
208 << " <link rel='shortcut icon' href='fmd_favicon.png' "
209 << "type='image/x-png'>\n"
212 << " <h1>" << title << "</h1>\n"
216 gStyle->SetPalette(1);
217 gStyle->SetOptFit(0);
218 gStyle->SetOptStat(0);
219 gStyle->SetOptTitle(1);
220 gStyle->SetTitleW(.4);
221 gStyle->SetTitleH(.1);
222 // gStyle->SetTitleColor(0);
223 gStyle->SetTitleStyle(0);
224 gStyle->SetTitleBorderSize(0);
225 gStyle->SetTitleX(.6);
227 fCanvas = new TCanvas("qa", title, 900, 700);
228 fCanvas->SetFillColor(0);
229 fCanvas->SetBorderSize(0);
230 fCanvas->SetLeftMargin(0.15);
231 fCanvas->SetRightMargin(0.02);
233 fCanvas->SetTopMargin(0.10);
234 fCanvas->SetBottomMargin(0.10);
236 fStore = TFile::Open(Form("%s.root", fTeXName.Data()), "RECREATE");
238 Warning("MakeCanvas", "Failed to make store %s.root", fTeXName.Data());
243 * Put a title on the canvas. Also clears page in LaTeX file
247 void CanvasTitle(const char* title)
249 if (!fCanvas) return;
253 fCanvas->SetBorderSize(0);
254 fCanvas->SetLeftMargin(0.15);
255 fCanvas->SetRightMargin(0.02);
257 fCanvas->SetTopMargin(0.10);
258 fCanvas->SetBottomMargin(0.10);
260 *fTeX << "\\clearpage\n"
261 << "%% -----------------------------------------------------"
265 tit.ReplaceAll("#LT", "<");
266 tit.ReplaceAll("#GT", ">");
267 tit.ReplaceAll("#Delta", "Δ");
268 tit.ReplaceAll("#xi", "ξ");
269 tit.ReplaceAll("#sigma", "σ");
270 tit.ReplaceAll("#chi", "χ");
271 tit.ReplaceAll("#nu", "ν");
272 tit.ReplaceAll("_{p}", "<sub>p</sub>");
273 tit.ReplaceAll("_{z}", "<sub>z</sub>");
274 tit.ReplaceAll("^{2}", "<sup>2</sup>");
275 *fHtml << "<tr><td>" << tit << "</td>" << std::flush;
277 PutCanvasTitle(title);
280 * Put a title on the canvas
284 void PutCanvasTitle(const char* title)
287 TLatex* topText = new TLatex(.5, .99, title);
288 topText->SetTextAlign(23);
289 topText->SetTextSize(.038);
290 topText->SetTextFont(42);
291 topText->SetTextColor(kBlue+3);
296 * Print the canvas to PNG and include it into LaTeX file
298 * @param pngName Base name of PNG
299 * @param runNo Run number to append
301 void PrintCanvas(const char* pngName, UInt_t /*runNo*/)
303 // TString s(Form("%s_%09d", pngName, runNo));
305 PrintCanvas(s.Data());
308 * Print the canvas to PNG and include it into LaTeX file. Stores
309 * canvas in storage file
311 * @param pngName Base name of PNG
312 * @param areas Areas to print
314 void PrintCanvas(const char* pngName, TCollection* areas=0)
316 gSystem->Exec(Form("rm -f %s.png %s.html", pngName, pngName));
317 fCanvas->SaveAs(Form("%s.png", pngName));
318 *fTeX << "\\begin{center}\n"
319 << "\\includegraphics[keepaspectratio,height=\\textheight]{"
321 << "\\end{center}" << std::endl;
322 *fHtml << "<td><a href='" << pngName << ".html'>Plot</a></td></tr>"
325 std::ofstream img(Form("%s.html", pngName));
326 img << "<!DOCTYPE html>\n"
329 << " <title>" << pngName << "</title>\n"
330 << " <link rel='stylesheet' href='style.css'></link>\n"
331 << " <link rel='shortcut icon' href='fmd_favicon.png' "
332 << "type='image/x-png'>\n"
335 << " <h1>" << pngName << "</h1>\n"
336 << " <div id=\"imap\">\n"
337 << " <img src=\"" << pngName << ".png\">\n";
342 img << " " << o->GetName() << "\n";
344 img << " </div>\n" << std::endl;
345 WriteImageFooter(img, pngName);
347 << "</html>" << std::endl;
349 gSystem->Exec(Form("chmod g+rw %s.html", pngName));
351 fToDelete.Append(Form(" %s.png", pngName));
352 TDirectory* d = gDirectory;
358 * Write out image footer
360 * @param o Output stream
362 virtual void WriteImageFooter(std::ostream& o, const char* /*pngName*/)
365 o << "<div class='back'>\n"
366 << "<a href='" << fTeXName << ".html'>Back</a>\n"
368 << "<div class='change'>\n"
369 << " Last update: " << now.AsString() << "\n"
370 << "</div>" << std::endl;
373 * Close the LaTeX and storage files. Runs PDFLaTeX on LaTeX
374 * file. Makes sure that the files are group writable.
376 * @param deletePNGs If true, delete intermident PNG files
378 void Close(bool deletePNGs=true)
380 const char* base = fTeXName.Data();
382 *fTeX << "\\end{document}\n"
383 << "%% EOF" << std::endl;
387 gSystem->Exec(Form("pdflatex %s.tex > /dev/null 2>&1", base));
388 Info("Close", "PDF file %s.pdf generated", base);
392 *fHtml << "</table>" << std::endl;
395 *fHtml << "</body></html>" << std::endl;
398 gSystem->Exec(Form("chmod g+rw %s.html", fTeXName.Data()));
403 gSystem->Exec(Form("chmod 664 %s.root", fTeXName.Data()));
405 TString cmd(Form("rm -f %s.log %s.aux %s.tex %s",
407 deletePNGs ? fToDelete.Data() : ""));
408 gSystem->Exec(cmd.Data());
409 gSystem->Exec(Form("chmod g+rw %s.pdf %s", base,
410 deletePNGs ? "" : fToDelete.Data()));
416 virtual void WriteLinks()
418 *fHtml << "<h3>Collection of plots</h3>\n"
420 << " <li><a href='" << fTeXName << ".pdf'>PDF</a></li>\n"
421 << " <li><a href='" << fTeXName << ".root'>ROOT</a></li>\n"
422 << "</ul>" << std::endl;
423 if (fPeriod.IsNull()) return;
424 Bool_t isMC = (fDataType.EqualTo("sim", TString::kIgnoreCase) ||
425 fPass.BeginsWith("passMC", TString::kIgnoreCase));
427 << " <li><a href='https://alimonitor.cern.ch/"
428 << (isMC ? "job_details.jsp" : "production/raw.jsp")
429 << "?jt_field1=" << fPeriod << "'>Producion(s)</a></li>\n"
430 << "</ul>" << std::endl;
433 * Write full job footer
436 virtual void WriteFooter()
439 *fHtml << "<div class='back'>\n"
440 << "<a href='index.html'>Back</a>\n"
442 << "<div class='change'>\n"
443 << " Last update: " << now.AsString() << "\n"
444 << "</div>" << std::endl;
446 // --- Members -----------------------------------------------------
447 QARing* fFMD1i; // Pointer to ring object
448 QARing* fFMD2i; // Pointer to ring object
449 QARing* fFMD2o; // Pointer to ring object
450 QARing* fFMD3i; // Pointer to ring object
451 QARing* fFMD3o; // Pointer to ring object
452 Global* fGlobal; // Pointer to global run object
453 TTree* fTree; // Pointer to tree object
454 TFile* fOutput; // Pointer to tree file
455 TFile* fStore; // Pointer to storage file
456 std::ofstream* fTeX; // pointer to LaTeX stream
457 std::ofstream* fHtml; // pointer to HTML stream
458 TString fTeXName; // Base name of LaTeX file
459 TString fToDelete; // List of files to possibly delete
460 TCanvas* fCanvas; // Pointer to canvas object
461 TString fOutputName; // Output tree file name
462 TString fDataType; // Data type
463 Int_t fYear; // Production year
464 TString fPeriod; // Period identifier
465 TString fPass; // Pass identifier