AliPhysics  6cf2591 (6cf2591)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 {
39  QABase(const TString& dataType,
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  *fTeX << "\\documentclass[landscape,a4paper,12pt]{article}\n"
193  << "\\nonstopmode\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;
202 
203  *fHtml << "<!DOCTYPE html>\n"
204  << "<html>\n"
205  << " <head>\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"
210  << " <script>\n"
211  << " function browseRootFile(file) {\n"
212  << " var o = document.location.origin;\n"
213  << " var b = o;\n"
214  << " if (b.search(/aliqafmd.web.cern.ch/)) b += '/aliqafmd/';\n"
215  << " b += 'jsRoot/';\n"
216  << " var p = o + document.location.pathname;\n"
217  << " p=p.replace(/" << base << ".html/,'');\n"
218  << " if (p[p.lenght-1] != '/') p += '/';\n"
219  << " var u=encodeURIComponent(p+file)+'&menu=no';\n"
220  << " window.open(b + '?url=' + u, '_blank',\n"
221  << " 'location=no,menubar=no,status=no,titlebar=no');\n"
222  << " }\n"
223  << " </script>\n"
224  << " </head>\n"
225  << "<body>\n"
226  << " <h1>" << title << "</h1>\n"
227  << " <table>"
228  << std::endl;
229 
230  gStyle->SetPalette(1);
231  gStyle->SetOptFit(0);
232  gStyle->SetOptStat(0);
233  gStyle->SetOptTitle(1);
234  gStyle->SetTitleW(.4);
235  gStyle->SetTitleH(.1);
236  // gStyle->SetTitleColor(0);
237  gStyle->SetTitleStyle(0);
238  gStyle->SetTitleBorderSize(0);
239  gStyle->SetTitleX(.6);
240 
241  fCanvas = new TCanvas("qa", title, 900, 700);
242  fCanvas->SetFillColor(0);
243  fCanvas->SetBorderSize(0);
244  fCanvas->SetLeftMargin(0.15);
245  fCanvas->SetRightMargin(0.02);
246 
247  fCanvas->SetTopMargin(0.10);
248  fCanvas->SetBottomMargin(0.10);
249 
250  fStore = TFile::Open(Form("%s.root", fTeXName.Data()), "RECREATE");
251  if (!fStore)
252  Warning("MakeCanvas", "Failed to make store %s.root", fTeXName.Data());
253 
254  fToDelete = "";
255  }
261  void CanvasTitle(const char* title)
262  {
263  if (!fCanvas) return;
264 
265  fCanvas->cd();
266  fCanvas->Clear();
267  fCanvas->SetBorderSize(0);
268  fCanvas->SetLeftMargin(0.15);
269  fCanvas->SetRightMargin(0.02);
270 
271  fCanvas->SetTopMargin(0.10);
272  fCanvas->SetBottomMargin(0.10);
273 
274  *fTeX << "\\clearpage\n"
275  << "%% -----------------------------------------------------"
276  << std::endl;
277 
278  TString tit(title);
279  tit.ReplaceAll("#LT", "&lt;");
280  tit.ReplaceAll("#GT", "&gt;");
281  tit.ReplaceAll("#Delta", "&Delta;");
282  tit.ReplaceAll("#xi", "&xi;");
283  tit.ReplaceAll("#sigma", "&sigma;");
284  tit.ReplaceAll("#chi", "&chi;");
285  tit.ReplaceAll("#nu", "&nu;");
286  tit.ReplaceAll("_{p}", "<sub>p</sub>");
287  tit.ReplaceAll("_{z}", "<sub>z</sub>");
288  tit.ReplaceAll("^{2}", "<sup>2</sup>");
289  *fHtml << "<tr><td>" << tit << "</td>" << std::flush;
290 
291  PutCanvasTitle(title);
292  }
298  void PutCanvasTitle(const char* title)
299  {
300  // Put title on top
301  TLatex* topText = new TLatex(.5, .99, title);
302  topText->SetTextAlign(23);
303  topText->SetTextSize(.038);
304  topText->SetTextFont(42);
305  topText->SetTextColor(kBlue+3);
306  topText->SetNDC();
307  topText->Draw();
308  }
314  void PrintCanvas(const char* pngName, UInt_t /*runNo*/)
315  {
316  // TString s(Form("%s_%09d", pngName, runNo));
317  TString s(pngName);
318  PrintCanvas(s.Data());
319  }
327  void PrintCanvas(const char* pngName, TCollection* areas=0)
328  {
329  gSystem->Exec(Form("rm -f %s.png %s.html", pngName, pngName));
330  fCanvas->SaveAs(Form("%s.png", pngName));
331  *fTeX << "\\begin{center}\n"
332  << "\\includegraphics[keepaspectratio,height=\\textheight]{"
333  << pngName << "}\n"
334  << "\\end{center}" << std::endl;
335  *fHtml << "<td><a href='" << pngName << ".html'>Plot</a></td></tr>"
336  << std::endl;
337 
338  std::ofstream img(Form("%s.html", pngName));
339  img << "<!DOCTYPE html>\n"
340  << "<html>\n"
341  << " <head>\n"
342  << " <title>" << pngName << "</title>\n"
343  << " <link rel='stylesheet' href='style.css'></link>\n"
344  << " <link rel='shortcut icon' href='fmd_favicon.png' "
345  << "type='image/x-png'>\n"
346  << " </head>\n"
347  << " <body>\n"
348  << " <h1>" << pngName << "</h1>\n"
349  << " <div id=\"imap\">\n"
350  << " <img src=\"" << pngName << ".png\">\n";
351  if (areas) {
352  TIter next(areas);
353  TObject* o = 0;
354  while ((o = next()))
355  img << " " << o->GetName() << "\n";
356  }
357  img << " </div>\n" << std::endl;
358  WriteImageFooter(img, pngName);
359  img << " </body>\n"
360  << "</html>" << std::endl;
361  img.close();
362  gSystem->Exec(Form("chmod g+rw %s.html", pngName));
363 
364  fToDelete.Append(Form(" %s.png", pngName));
365  TDirectory* d = gDirectory;
366  fStore->cd();
367  fCanvas->Write();
368  d->cd();
369  }
375  virtual void WriteImageFooter(std::ostream& o, const char* /*pngName*/)
376  {
377  TDatime now;
378  o << "<div class='back'>\n"
379  << "<a href='" << fTeXName << ".html'>Back</a>\n"
380  << "</div>\n"
381  << "<div class='change'>\n"
382  << " Last update: " << now.AsString() << "\n"
383  << "</div>" << std::endl;
384  }
391  void Close(bool deletePNGs=true)
392  {
393  const char* base = fTeXName.Data();
394  if (fTeX) {
395  *fTeX << "\\end{document}\n"
396  << "%% EOF" << std::endl;
397  fTeX->close();
398  fTeX = 0;
399 
400  gSystem->Exec(Form("pdflatex %s.tex > /dev/null 2>&1", base));
401  Info("Close", "PDF file %s.pdf generated", base);
402  }
403  if (fHtml) {
404  TDatime now;
405  *fHtml << "</table>" << std::endl;
406  WriteLinks();
407  WriteFooter();
408  *fHtml << "</body></html>" << std::endl;
409  fHtml->close();
410  fHtml = 0;
411  gSystem->Exec(Form("chmod g+rw %s.html", fTeXName.Data()));
412  }
413  if (fStore) {
414  fStore->Write();
415  fStore->Close();
416  gSystem->Exec(Form("chmod 664 %s.root", fTeXName.Data()));
417  }
418  TString cmd(Form("rm -f %s.log %s.aux %s.tex %s",
419  base, base, base,
420  deletePNGs ? fToDelete.Data() : ""));
421  gSystem->Exec(cmd.Data());
422  gSystem->Exec(Form("chmod g+rw %s.pdf %s", base,
423  deletePNGs ? "" : fToDelete.Data()));
424  }
429  virtual void WriteLinks()
430  {
431  const char* jsRoot = "http://cern.ch/aliqafmd/jsRoot/";
432  *fHtml << "<h3>Collection of plots</h3>\n"
433  << "<ul>\n"
434  << " <li><a href='" << fTeXName << ".pdf'>PDF</a></li>\n"
435  << " <li><a href='" << fTeXName << ".root'>ROOT</a>\n"
436  << " <button onclick='browseRootFile(\""
437  << fTeXName << ".root\")'>browse online</button></li>\n"
438  << "</ul>" << std::endl;
439  if (fPeriod.IsNull()) return;
440  Bool_t isMC = (fDataType.EqualTo("sim", TString::kIgnoreCase) ||
441  fPass.BeginsWith("passMC", TString::kIgnoreCase));
442  *fHtml << "<ul>\n"
443  << " <li><a href='https://alimonitor.cern.ch/"
444  << (isMC ? "job_details.jsp" : "production/raw.jsp")
445  << "?jt_field1=" << fPeriod << "'>Production(s)</a></li>\n"
446  << "</ul>" << std::endl;
447  }
452  virtual void WriteFooter()
453  {
454  TDatime now;
455  *fHtml << "<div class='back'>\n"
456  << "<a href='index.html'>Back</a>\n"
457  << "</div>\n"
458  << "<div class='change'>\n"
459  << " Last update: " << now.AsString() << "\n"
460  << "</div>" << std::endl;
461  }
462  // --- Members -----------------------------------------------------
463  QARing* fFMD1i; // Pointer to ring object
464  QARing* fFMD2i; // Pointer to ring object
465  QARing* fFMD2o; // Pointer to ring object
466  QARing* fFMD3i; // Pointer to ring object
467  QARing* fFMD3o; // Pointer to ring object
468  Global* fGlobal; // Pointer to global run object
469  TTree* fTree; // Pointer to tree object
470  TFile* fOutput; // Pointer to tree file
471  TFile* fStore; // Pointer to storage file
472  std::ofstream* fTeX; // pointer to LaTeX stream
473  std::ofstream* fHtml; // pointer to HTML stream
474  TString fTeXName; // Base name of LaTeX file
475  TString fToDelete; // List of files to possibly delete
476  TCanvas* fCanvas; // Pointer to canvas object
477  TString fOutputName; // Output tree file name
478  TString fDataType; // Data type
479  Int_t fYear; // Production year
480  TString fPeriod; // Period identifier
481  TString fPass; // Pass identifier
482 };
483 
484 #endif
485 
486 
487 // Local Variables:
488 // mode: C++
489 // End:
virtual void WriteLinks()
Definition: QABase.h:429
QARing * fFMD2i
Definition: QABase.h:464
const char * title
Definition: MakeQAPdf.C:26
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:391
void PrintCanvas(const char *pngName, UInt_t)
Definition: QABase.h:314
void PrintCanvas(const char *pngName, TCollection *areas=0)
Definition: QABase.h:327
void CanvasTitle(const char *title)
Definition: QABase.h:261
TString fPeriod
Definition: QABase.h:480
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:469
unsigned int UInt_t
Definition: External.C:33
QARing * fFMD2o
Definition: QABase.h:465
Bool_t Init(TTree *tree, bool read=false)
Definition: QARing.h:76
std::ofstream * fHtml
Definition: QABase.h:473
virtual void WriteFooter()
Definition: QABase.h:452
TString fOutputName
Definition: QABase.h:477
Int_t fYear
Definition: QABase.h:479
TString fTeXName
Definition: QABase.h:474
TFile * fOutput
Definition: QABase.h:470
virtual ~QABase()
Definition: QABase.h:98
TString fToDelete
Definition: QABase.h:475
virtual void WriteImageFooter(std::ostream &o, const char *)
Definition: QABase.h:375
void PutCanvasTitle(const char *title)
Definition: QABase.h:298
QARing * fFMD3i
Definition: QABase.h:466
Bool_t isMC
Base class for QA rings.
virtual Bool_t MakeTree(bool read)
Definition: QABase.h:131
QARing * fFMD1i
Definition: QABase.h:463
TString fPass
Definition: QABase.h:481
TFile * fStore
Definition: QABase.h:471
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:476
Global * fGlobal
Definition: QABase.h:468
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:472
TString fDataType
Definition: QABase.h:478
QARing * fFMD3o
Definition: QABase.h:467