AliPhysics  aaf9c62 (aaf9c62)
QABase.h
Go to the documentation of this file.
1 
11 #ifndef QABASE_H
12 #define QABASE_H
13 #ifndef __CINT__
14 # include <TTree.h>
15 # include <TFile.h>
16 # include <TError.h>
17 # include <TCanvas.h>
18 # include <TSystem.h>
19 # include <fstream>
20 # include <TLatex.h>
21 # include <TStyle.h>
22 # include "QARing.h"
23 #else
24 class TTree;
25 class TFile;
26 class QARing;
27 class Global;
28 class TCanvas;
29 #endif
30 
37 struct QABase
38 {
40  Int_t prodYear,
41  const TString& period,
42  const TString& pass)
43  : fFMD1i(0),
44  fFMD2i(0),
45  fFMD2o(0),
46  fFMD3i(0),
47  fFMD3o(0),
48  fGlobal(0),
49  fTree(0),
50  fOutput(0),
51  fStore(0),
52  fTeX(0),
53  fHtml(0),
54  fTeXName("index"),
55  fToDelete(""),
56  fCanvas(0),
57  fOutputName("trending.root"),
58  fDataType(dataType),
59  fYear(prodYear),
60  fPeriod(period),
61  fPass(pass)
62  {}
68  QABase(const QABase& o)
69  : fFMD1i(o.fFMD1i),
70  fFMD2i(o.fFMD2i),
71  fFMD2o(o.fFMD2o),
72  fFMD3i(o.fFMD3i),
73  fFMD3o(o.fFMD3o),
74  fGlobal(o.fGlobal),
75  fTree(o.fTree),
76  fOutput(o.fOutput),
77  fStore(o.fStore),
78  fTeX(o.fTeX),
79  fHtml(o.fHtml),
80  fTeXName(o.fTeXName),
82  fCanvas(o.fCanvas),
84  fDataType(o.fDataType),
85  fYear(o.fYear),
86  fPeriod(o.fPeriod),
87  fPass(o.fPass)
88  {}
94  QABase& operator=(const QABase&) { return *this; }
98  virtual ~QABase()
99  {
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; }
111  }
117  void SetOutputName(const char* name) { fOutputName = name; }
123  const char* OutputName() const { return fOutputName.Data(); }
131  virtual Bool_t MakeTree(bool read)
132  {
133  fOutput = new TFile(OutputName(), (read ? "READ" : "RECREATE"));
134  if (!fOutput) {
135  Error("MakeTree", "Failed to open output file");
136  return false;
137  }
138  if (read) fTree = static_cast<TTree*>(fOutput->Get("T"));
139  else fTree = new TTree("T", "T");
140  if (!fTree) {
141  Error("MakeTree", "No tree defined!");
142  return false;
143  }
144 
145  return true;
146  }
154  Bool_t Init(bool read=false)
155  {
156  if (!MakeTree(read)) return false;
157 
158  if (read) fGlobal = Global::SetBranch(fTree);
160 
161  fToDelete = "";
162 
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);
168 
169  return true;
170  }
176  void MakeCanvas(const char* title)
177  {
178  if (fCanvas) {
179  delete fCanvas;
180  fCanvas = 0;
181  }
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));
185 
186  fTeX = new std::ofstream(Form("%s.tex", base));
187  fHtml = new std::ofstream(Form("%s.html", base));
188 
189  TString texTitle(title);
190  texTitle.ReplaceAll("_", "-");
191 
192  const char* can = "http://aliqafmd.web.cern.ch/aliqafmd/";
193  *fTeX << "\\documentclass[landscape,a4paper,12pt]{article}\n"
194  << "\\nonstopmode\n"
195  << "\\usepackage[margin=2cm,a4paper]{geometry}\n"
196  << "\\usepackage{graphicx}\n"
197  << "\\title{{\\Huge\\bf " << texTitle << "}}\n"
198  << "\\author{{\\LARGE FMD Team}}\n"
199  << "\\date{{\\Large \\today}}\n"
200  << "\\begin{document}\n"
201  << "\\thispagestyle{empty}\n"
202  << "\\maketitle" << std::endl;
203 
204  *fHtml << "<!DOCTYPE html>\n"
205  << "<html>\n"
206  << " <head>\n"
207  << " <title>QA information - " << title << "</title>\n"
208  << " <link rel='stylesheet' href='" << can << "style.css'>\n"
209  << " <link rel='stylesheet' href='style.css'>\n"
210  << " <link rel='shortcut icon' href='" << can
211  << "fmd_favicon.png' type='image/x-png'>\n"
212  << " <link rel='shortcut icon' href='fmd_favicon.png' "
213  << "type='image/x-png'>\n"
214  << " <script>\n"
215  << " function browseRootFile(file) {\n"
216  << " var o = document.location.origin;\n"
217  << " var b = o;\n"
218  << " if (b.search(/aliqafmd.web.cern.ch/)) b += '/aliqafmd/';\n"
219  << " b += 'jsRoot/';\n"
220  << " var p = o + document.location.pathname;\n"
221  << " p=p.replace(/" << base << ".html/,'');\n"
222  << " if (p[p.lenght-1] != '/') p += '/';\n"
223  << " var u=encodeURIComponent(p+file)+'&menu=no';\n"
224  << " window.open(b + '?url=' + u, '_blank',\n"
225  << " 'location=no,menubar=no,status=no,titlebar=no');\n"
226  << " }\n"
227  << " </script>\n"
228  << " </head>\n"
229  << "<body>\n"
230  << " <h1>" << title << "</h1>\n"
231  << " <table>"
232  << std::endl;
233 
234  gStyle->SetPalette(1);
235  gStyle->SetOptFit(0);
236  gStyle->SetOptStat(0);
237  gStyle->SetOptTitle(1);
238  gStyle->SetTitleW(.4);
239  gStyle->SetTitleH(.1);
240  // gStyle->SetTitleColor(0);
241  gStyle->SetTitleStyle(0);
242  gStyle->SetTitleBorderSize(0);
243  gStyle->SetTitleX(.6);
244 
245  fCanvas = new TCanvas("qa", title, 900, 700);
246  fCanvas->SetFillColor(0);
247  fCanvas->SetBorderSize(0);
248  fCanvas->SetLeftMargin(0.15);
249  fCanvas->SetRightMargin(0.02);
250 
251  fCanvas->SetTopMargin(0.10);
252  fCanvas->SetBottomMargin(0.10);
253 
254  fStore = TFile::Open(Form("%s.root", fTeXName.Data()), "RECREATE");
255  if (!fStore)
256  Warning("MakeCanvas", "Failed to make store %s.root", fTeXName.Data());
257 
258  fToDelete = "";
259  }
265  void CanvasTitle(const char* title)
266  {
267  if (!fCanvas) return;
268 
269  fCanvas->cd();
270  fCanvas->Clear();
271  fCanvas->SetBorderSize(0);
272  fCanvas->SetLeftMargin(0.15);
273  fCanvas->SetRightMargin(0.02);
274 
275  fCanvas->SetTopMargin(0.10);
276  fCanvas->SetBottomMargin(0.10);
277 
278  *fTeX << "\\clearpage\n"
279  << "%% -----------------------------------------------------"
280  << std::endl;
281 
282  TString tit(title);
283  tit.ReplaceAll("#LT", "&lt;");
284  tit.ReplaceAll("#GT", "&gt;");
285  tit.ReplaceAll("#Delta", "&Delta;");
286  tit.ReplaceAll("#xi", "&xi;");
287  tit.ReplaceAll("#sigma", "&sigma;");
288  tit.ReplaceAll("#chi", "&chi;");
289  tit.ReplaceAll("#nu", "&nu;");
290  tit.ReplaceAll("_{p}", "<sub>p</sub>");
291  tit.ReplaceAll("_{z}", "<sub>z</sub>");
292  tit.ReplaceAll("^{2}", "<sup>2</sup>");
293  *fHtml << "<tr><td>" << tit << "</td>" << std::flush;
294 
295  PutCanvasTitle(title);
296  }
302  void PutCanvasTitle(const char* title)
303  {
304  // Put title on top
305  TLatex* topText = new TLatex(.5, .99, title);
306  topText->SetTextAlign(23);
307  topText->SetTextSize(.038);
308  topText->SetTextFont(42);
309  topText->SetTextColor(kBlue+3);
310  topText->SetNDC();
311  topText->Draw();
312  }
318  void PrintCanvas(const char* pngName, UInt_t /*runNo*/)
319  {
320  // TString s(Form("%s_%09d", pngName, runNo));
321  TString s(pngName);
322  PrintCanvas(s.Data());
323  }
331  void PrintCanvas(const char* pngName, TCollection* areas=0)
332  {
333  gSystem->Exec(Form("rm -f %s.png %s.html", pngName, pngName));
334  fCanvas->SaveAs(Form("%s.png", pngName));
335  *fTeX << "\\begin{center}\n"
336  << "\\includegraphics[keepaspectratio,height=\\textheight]{"
337  << pngName << "}\n"
338  << "\\end{center}" << std::endl;
339  *fHtml << "<td><a href='" << pngName << ".html'>Plot</a></td></tr>"
340  << std::endl;
341 
342  std::ofstream img(Form("%s.html", pngName));
343  img << "<!DOCTYPE html>\n"
344  << "<html>\n"
345  << " <head>\n"
346  << " <title>" << pngName << "</title>\n"
347  << " <link rel='stylesheet' href='style.css'></link>\n"
348  << " <link rel='shortcut icon' href='fmd_favicon.png' "
349  << "type='image/x-png'>\n"
350  << " </head>\n"
351  << " <body>\n"
352  << " <h1>" << pngName << "</h1>\n"
353  << " <div id=\"imap\">\n"
354  << " <img src=\"" << pngName << ".png\">\n";
355  if (areas) {
356  TIter next(areas);
357  TObject* o = 0;
358  while ((o = next()))
359  img << " " << o->GetName() << "\n";
360  }
361  img << " </div>\n" << std::endl;
362  WriteImageFooter(img, pngName);
363  img << " </body>\n"
364  << "</html>" << std::endl;
365  img.close();
366  gSystem->Exec(Form("chmod g+rw %s.html", pngName));
367 
368  fToDelete.Append(Form(" %s.png", pngName));
369  TDirectory* d = gDirectory;
370  fStore->cd();
371  fCanvas->Write();
372  d->cd();
373  }
379  virtual void WriteImageFooter(std::ostream& o, const char* /*pngName*/)
380  {
381  TDatime now;
382  o << "<div class='back'>\n"
383  << "<a href='" << fTeXName << ".html'>Back</a>\n"
384  << "</div>\n"
385  << "<div class='change'>\n"
386  << " Last update: " << now.AsString() << "\n"
387  << "</div>" << std::endl;
388  }
395  void Close(bool deletePNGs=true)
396  {
397  const char* base = fTeXName.Data();
398  if (fTeX) {
399  *fTeX << "\\end{document}\n"
400  << "%% EOF" << std::endl;
401  fTeX->close();
402  fTeX = 0;
403 
404  gSystem->Exec(Form("pdflatex %s.tex > /dev/null 2>&1", base));
405  Info("Close", "PDF file %s.pdf generated", base);
406  }
407  if (fHtml) {
408  TDatime now;
409  *fHtml << "</table>" << std::endl;
410  WriteLinks();
411  WriteFooter();
412  *fHtml << "</body></html>" << std::endl;
413  fHtml->close();
414  fHtml = 0;
415  gSystem->Exec(Form("chmod g+rw %s.html", fTeXName.Data()));
416  }
417  if (fStore) {
418  fStore->Write();
419  fStore->Close();
420  gSystem->Exec(Form("chmod 664 %s.root", fTeXName.Data()));
421  }
422  TString cmd(Form("rm -f %s.log %s.aux %s.tex %s",
423  base, base, base,
424  deletePNGs ? fToDelete.Data() : ""));
425  gSystem->Exec(cmd.Data());
426  gSystem->Exec(Form("chmod g+rw %s.pdf %s", base,
427  deletePNGs ? "" : fToDelete.Data()));
428  }
433  virtual void WriteLinks()
434  {
435  const char* jsRoot = "http://cern.ch/aliqafmd/jsRoot/";
436  *fHtml << "<h3>Collection of plots</h3>\n"
437  << "<ul>\n"
438  << " <li><a href='" << fTeXName << ".pdf'>PDF</a></li>\n"
439  << " <li><a href='" << fTeXName << ".root'>ROOT</a>\n"
440  << " <button onclick='browseRootFile(\""
441  << fTeXName << ".root\")'>browse online</button></li>\n"
442  << "</ul>" << std::endl;
443  if (fPeriod.IsNull()) return;
444  Bool_t isMC = (fDataType.EqualTo("sim", TString::kIgnoreCase) ||
445  fPass.BeginsWith("passMC", TString::kIgnoreCase));
446  *fHtml << "<ul>\n"
447  << " <li><a href='https://alimonitor.cern.ch/"
448  << (isMC ? "job_details.jsp" : "production/raw.jsp")
449  << "?jt_field1=" << fPeriod << "'>Production(s)</a></li>\n"
450  << "</ul>" << std::endl;
451  }
456  virtual void WriteFooter()
457  {
458  TDatime now;
459  *fHtml << "<div class='back'>\n"
460  << "<a href='index.html'>Back</a>\n"
461  << "</div>\n"
462  << "<div class='change'>\n"
463  << " Last update: " << now.AsString() << "\n"
464  << "</div>" << std::endl;
465  }
466  // --- Members -----------------------------------------------------
467  QARing* fFMD1i; // Pointer to ring object
468  QARing* fFMD2i; // Pointer to ring object
469  QARing* fFMD2o; // Pointer to ring object
470  QARing* fFMD3i; // Pointer to ring object
471  QARing* fFMD3o; // Pointer to ring object
472  Global* fGlobal; // Pointer to global run object
473  TTree* fTree; // Pointer to tree object
474  TFile* fOutput; // Pointer to tree file
475  TFile* fStore; // Pointer to storage file
476  std::ofstream* fTeX; // pointer to LaTeX stream
477  std::ofstream* fHtml; // pointer to HTML stream
478  TString fTeXName; // Base name of LaTeX file
479  TString fToDelete; // List of files to possibly delete
480  TCanvas* fCanvas; // Pointer to canvas object
481  TString fOutputName; // Output tree file name
482  TString fDataType; // Data type
483  Int_t fYear; // Production year
484  TString fPeriod; // Period identifier
485  TString fPass; // Pass identifier
486 };
487 
488 #endif
489 
490 
491 // Local Variables:
492 // mode: C++
493 // End:
virtual void WriteLinks()
Definition: QABase.h:433
QARing * fFMD2i
Definition: QABase.h:468
const char * title
Definition: MakeQAPdf.C:27
QABase(const TString &dataType, Int_t prodYear, const TString &period, const TString &pass)
Definition: QABase.h:39
TSystem * gSystem
static Global * MakeBranch(TTree *tree)
Definition: QAStructs.h:148
void Close(bool deletePNGs=true)
Definition: QABase.h:395
void PrintCanvas(const char *pngName, UInt_t)
Definition: QABase.h:318
void PrintCanvas(const char *pngName, TCollection *areas=0)
Definition: QABase.h:331
void CanvasTitle(const char *title)
Definition: QABase.h:265
TString fPeriod
Definition: QABase.h:484
QABase & operator=(const QABase &)
Definition: QABase.h:94
const char * OutputName() const
Definition: QABase.h:123
int Int_t
Definition: External.C:63
TTree * fTree
Definition: QABase.h:473
unsigned int UInt_t
Definition: External.C:33
QARing * fFMD2o
Definition: QABase.h:469
Bool_t Init(TTree *tree, bool read=false)
Definition: QARing.h:76
std::ofstream * fHtml
Definition: QABase.h:477
virtual void WriteFooter()
Definition: QABase.h:456
TString fOutputName
Definition: QABase.h:481
Int_t fYear
Definition: QABase.h:483
TString fTeXName
Definition: QABase.h:478
TFile * fOutput
Definition: QABase.h:474
virtual ~QABase()
Definition: QABase.h:98
TString fToDelete
Definition: QABase.h:479
virtual void WriteImageFooter(std::ostream &o, const char *)
Definition: QABase.h:379
void PutCanvasTitle(const char *title)
Definition: QABase.h:302
QARing * fFMD3i
Definition: QABase.h:470
Bool_t isMC
Base class for QA rings.
virtual Bool_t MakeTree(bool read)
Definition: QABase.h:131
QARing * fFMD1i
Definition: QABase.h:467
TString fPass
Definition: QABase.h:485
TFile * fStore
Definition: QABase.h:475
Definition: QABase.h:37
Bool_t Init(bool read=false)
Definition: QABase.h:154
QABase(const QABase &o)
Definition: QABase.h:68
void SetOutputName(const char *name)
Definition: QABase.h:117
static Global * SetBranch(TTree *tree)
Definition: QAStructs.h:162
TCanvas * fCanvas
Definition: QABase.h:480
Global * fGlobal
Definition: QABase.h:472
void MakeCanvas(const char *title)
Definition: QABase.h:176
bool Bool_t
Definition: External.C:53
Definition: QARing.h:29
std::ofstream * fTeX
Definition: QABase.h:476
TString fDataType
Definition: QABase.h:482
QARing * fFMD3o
Definition: QABase.h:471