BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnReport.cxx
Go to the documentation of this file.
1/**
2 * \file BmnReport.cxx
3 * \brief Base class for reports.
4 * \author Andrey Lebedev <andrey.lebedev@gsi.de>
5 * \date 2011
6 */
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)
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
37{
38 if (NULL != fR)
39 delete fR;
40 if (NULL != fOut)
41 delete fOut;
43 fOut = new ofstream(TString(GetOutputDir() + fReportName + ".html").Data());
44}
45
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
62 Create(); // User has to implement this function!
64 }
65}
66
67/**
68 * @brief Create or just find already created
69 * @param name
70 * @param title
71 * @param ww
72 * @param wh
73 * @return
74 */
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;
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 }
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.
int Int_t
constexpr Bool_t kFALSE
constexpr Int_t kWarning
constexpr Int_t kPrint
Int_t gErrorIgnoreLevel
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.
void PrintCanvases() const
Print images created from canvases in the report.
BmnReportElement * fR
Definition BmnReport.h:139
const BmnReportElement * R() const
Accessor to BmnReportElement object.
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.
Definition BmnReport.cxx:75
vector< TCanvas * > fCanvases
Definition BmnReport.h:145
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
Bool_t fInitCanvasesDone
Definition BmnReport.h:123
string fOutputDir
Definition BmnReport.h:138
string fReportTitle
Definition BmnReport.h:137
void WriteCanvases() const
Write canvases to file.
void DeleteReportElement()
Delete report element.
Definition BmnReport.cxx:46
ostream * fOut
Definition BmnReport.h:140
void Register(string path)
string fReportName
Definition BmnReport.h:136
virtual void Create()=0
Pure abstract function which is called from public Create() function.
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
void CreateReportElement()
Create concrete BmnReportElement instance based on the report type.
Definition BmnReport.cxx:36
map< string, TCanvas * > fCanvasMap
Definition BmnReport.h:146
const char * GetTitle() const override
void SaveAs(const char *filename="", Option_t *option="") const override
const char * GetName() const override
const char * Data() const
Definition json.hpp:4446