BmnRoot
Loading...
Searching...
No Matches
BmnReport.cxx
Go to the documentation of this file.
1
7#include "BmnReport.h"
8
10#include "TCanvas.h"
11
12#include <TError.h>
13#include <fstream>
14
15using namespace std;
16
18 : fServer(nullptr)
19 , fMonitorMode(kFALSE)
20 , fInitCanvasesDone(kFALSE)
21 , fReportName("qa_report")
22 , fReportTitle("QA report")
23 , fOutputDir("./")
24 , fR(NULL)
25 , fOut(NULL)
26{}
27
29{
30 for (auto h : fCanvases) {
31 if (h)
32 delete h;
33 }
34}
35
36void BmnReport::CreateReportElement()
37{
38 if (NULL != fR)
39 delete fR;
40 if (NULL != fOut)
41 delete fOut;
42 fR = new BmnHtmlReportElement();
43 fOut = new ofstream(TString(GetOutputDir() + fReportName + ".html").Data());
44}
45
46void BmnReport::DeleteReportElement()
47{
48 if (NULL != fR)
49 delete fR;
50 if (NULL != fOut)
51 delete fOut;
52}
53
55{
56 Draw(); // User has to implement this function!
57 if (!fMonitorMode) {
60
61 CreateReportElement();
62 Create(); // User has to implement this function!
63 DeleteReportElement();
64 }
65}
66
75TCanvas* BmnReport::CreateCanvas(const char* name, const char* title, Int_t ww, Int_t wh)
76{
77 TCanvas* canvas = nullptr;
78 string sname(name);
79 auto it = fCanvasMap.find(sname);
80 if (it == fCanvasMap.end()) {
81 canvas = new TCanvas(name, title, ww, wh);
82 fCanvases.push_back(canvas);
83 fCanvasMap.insert(make_pair(sname, canvas));
84 } else
85 canvas = it->second;
86 return canvas;
87}
88
90{
91 if (GetOutputDir() == "")
92 return;
93 Int_t nofCanvases = fCanvases.size();
94 cout << "nofCanvases = " << nofCanvases << endl;
95 gErrorIgnoreLevel = kWarning;
96 for (Int_t i = 0; i < nofCanvases; i++) {
97 TCanvas* canvas = fCanvases[i];
98 canvas->SaveAs(TString(GetOutputDir() + string(canvas->GetTitle()) + ".png").Data());
99 }
100 gErrorIgnoreLevel = kPrint;
101}
102
104{
105 if (GetOutputDir() == "")
106 return;
107 Int_t nofCanvases = fCanvases.size();
108 for (Int_t i = 0; i < nofCanvases; i++) {
109 fCanvases[i]->Write();
110 }
111}
112
114{
115 Int_t nofCanvases = fCanvases.size();
116 for (Int_t i = 0; i < nofCanvases; i++) {
117 TCanvas* canvas = fCanvases[i];
118 Out() << R()->Image(canvas->GetName(), canvas->GetName());
119 }
120}
121
122void BmnReport::Register(string path)
123{
124 for (auto can : fCanvases) {
125 // printf("reg %s\n", can->GetName());
126 fServer->Register(path.c_str(), can);
127 }
128}
TCanvas * can(nullptr)
int i
Definition P4_F32vec4.h:22
Implementation of BmnReportElement for HTML output.
Implementation of BmnReportElement for text output.
virtual string Image(const string &title, const string &file) const =0
Return string with image tags.
const string & GetOutputDir() const
Definition BmnReport.h:75
virtual void Draw()=0
Pure abstract function which is called from public Create() function. This function has to draw all n...
void PrintCanvases() const
Print images created from canvases in the report.
const BmnReportElement * R() const
Accessor to BmnReportElement object. User has to write the report using available tags from BmnReport...
Definition BmnReport.h:45
BmnReport()
Constructor.
Definition BmnReport.cxx:17
TCanvas * CreateCanvas(const char *name, const char *title, Int_t ww, Int_t wh)
Create canvas and put it to vector of TCanvases. Canvases created with this function will be automati...
Definition BmnReport.cxx:75
void CreateReports()
Create all available report types.
Definition BmnReport.cxx:54
ostream & Out() const
All text output goes to this stream.
Definition BmnReport.h:50
void WriteCanvases() const
Write canvases to file.
void Register(string path)
virtual void Create()=0
Pure abstract function which is called from public Create() function. This function has to write repo...
Bool_t fMonitorMode
Definition BmnReport.h:122
void SaveCanvasesAsImages() const
Save all canvases to images.
Definition BmnReport.cxx:89
THttpServer * fServer
Definition BmnReport.h:121
virtual ~BmnReport()
Destructor.
Definition BmnReport.cxx:28
STL namespace.