BmnRoot
26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Toggle main menu visibility
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
9
#include "
BmnHtmlReportElement.h
"
10
#include "
TCanvas.h
"
11
12
#include <
TError.h
>
13
#include <fstream>
14
15
using namespace
std
;
16
17
BmnReport::BmnReport
()
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
28
BmnReport::~BmnReport
()
29
{
30
for
(
auto
h :
fCanvases
) {
31
if
(h)
32
delete
h;
33
}
34
}
35
36
void
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
46
void
BmnReport::DeleteReportElement
()
47
{
48
if
(NULL !=
fR
)
49
delete
fR
;
50
if
(NULL !=
fOut
)
51
delete
fOut
;
52
}
53
54
void
BmnReport::CreateReports
()
55
{
56
Draw
();
// User has to implement this function!
57
if
(!
fMonitorMode
) {
58
SaveCanvasesAsImages
();
59
WriteCanvases
();
60
61
CreateReportElement
();
62
Create
();
// User has to implement this function!
63
DeleteReportElement
();
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
*/
75
TCanvas
*
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
89
void
BmnReport::SaveCanvasesAsImages
()
const
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
103
void
BmnReport::WriteCanvases
()
const
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
113
void
BmnReport::PrintCanvases
()
const
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
122
void
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
}
can
TCanvas * can(nullptr)
i
int i
Definition
P4_F32vec4.h:22
BmnHtmlReportElement.h
Implementation of BmnReportElement for HTML output.
BmnReport.h
Int_t
int Int_t
kFALSE
constexpr Bool_t kFALSE
TCanvas.h
TError.h
kWarning
constexpr Int_t kWarning
kPrint
constexpr Int_t kPrint
gErrorIgnoreLevel
Int_t gErrorIgnoreLevel
BmnHtmlReportElement
Implementation of BmnReportElement for text output.
Definition
BmnHtmlReportElement.h:24
BmnReportElement::Image
virtual string Image(const string &title, const string &file) const =0
Return string with image tags.
BmnReport::GetOutputDir
const string & GetOutputDir() const
Definition
BmnReport.h:75
BmnReport::Draw
virtual void Draw()=0
Pure abstract function which is called from public Create() function.
BmnReport::PrintCanvases
void PrintCanvases() const
Print images created from canvases in the report.
Definition
BmnReport.cxx:113
BmnReport::fR
BmnReportElement * fR
Definition
BmnReport.h:139
BmnReport::R
const BmnReportElement * R() const
Accessor to BmnReportElement object.
Definition
BmnReport.h:45
BmnReport::BmnReport
BmnReport()
Constructor.
Definition
BmnReport.cxx:17
BmnReport::CreateCanvas
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
BmnReport::fCanvases
vector< TCanvas * > fCanvases
Definition
BmnReport.h:145
BmnReport::CreateReports
void CreateReports()
Create all available report types.
Definition
BmnReport.cxx:54
BmnReport::Out
ostream & Out() const
All text output goes to this stream.
Definition
BmnReport.h:50
BmnReport::fInitCanvasesDone
Bool_t fInitCanvasesDone
Definition
BmnReport.h:123
BmnReport::fOutputDir
string fOutputDir
Definition
BmnReport.h:138
BmnReport::fReportTitle
string fReportTitle
Definition
BmnReport.h:137
BmnReport::WriteCanvases
void WriteCanvases() const
Write canvases to file.
Definition
BmnReport.cxx:103
BmnReport::DeleteReportElement
void DeleteReportElement()
Delete report element.
Definition
BmnReport.cxx:46
BmnReport::fOut
ostream * fOut
Definition
BmnReport.h:140
BmnReport::Register
void Register(string path)
Definition
BmnReport.cxx:122
BmnReport::fReportName
string fReportName
Definition
BmnReport.h:136
BmnReport::Create
virtual void Create()=0
Pure abstract function which is called from public Create() function.
BmnReport::fMonitorMode
Bool_t fMonitorMode
Definition
BmnReport.h:122
BmnReport::SaveCanvasesAsImages
void SaveCanvasesAsImages() const
Save all canvases to images.
Definition
BmnReport.cxx:89
BmnReport::fServer
THttpServer * fServer
Definition
BmnReport.h:121
BmnReport::~BmnReport
virtual ~BmnReport()
Destructor.
Definition
BmnReport.cxx:28
BmnReport::CreateReportElement
void CreateReportElement()
Create concrete BmnReportElement instance based on the report type.
Definition
BmnReport.cxx:36
BmnReport::fCanvasMap
map< string, TCanvas * > fCanvasMap
Definition
BmnReport.h:146
TCanvas
TPad::GetTitle
const char * GetTitle() const override
TPad::SaveAs
void SaveAs(const char *filename="", Option_t *option="") const override
TPad::GetName
const char * GetName() const override
TString
TString::Data
const char * Data() const
std
Definition
json.hpp:4446
QA
report
BmnReport.cxx
Generated on
for BmnRoot by
1.17.0