BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnReport.h
Go to the documentation of this file.
1#ifndef BMNREPORT_H_
2#define BMNREPORT_H_
3
4#include <iostream>
5#include <map>
6#include <string>
7#include <vector>
8// ROOT
9#include <TCanvas.h>
10#include <TFile.h>
11#include <THttpServer.h>
12#include <TObject.h>
13
14using std::map;
15using std::ostream;
16using std::string;
17using std::vector;
18
20
21/**
22 * \class BmnReport
23 * \brief Base class for reports.
24 * \author Andrey Lebedev <andrey.lebedev@gsi.de>
25 * \author Ilnur Gabdrakhmanov <ilnur@jinr.ru> - unificiation for online/offline mode
26 * \date 2011 - 2025
27 */
28class BmnReport : public TObject
29{
30 public:
31 /**
32 * \brief Constructor.
33 */
34 BmnReport();
35
36 /**
37 * \brief Destructor.
38 */
39 virtual ~BmnReport();
40
41 /**
42 * \brief Accessor to BmnReportElement object.
43 * User has to write the report using available tags from BmnReportElement class.
44 */
45 const BmnReportElement* R() const { return fR; }
46
47 /**
48 * \brief All text output goes to this stream.
49 */
50 ostream& Out() const { return *fOut; }
51
52 void Register(string path);
53 void CallDraw() { Draw(); }
54
55 /* Setters */
56 void SetReportName(TString name) { fReportName = name.Data(); }
57 void SetReportTitle(const string& title) { fReportTitle = title; }
58 void SetOutputDir(const string& outputDir) { fOutputDir = outputDir; }
59
60 /* void SetObjDir(TFile* outFile = nullptr)
61 {
62 TDirectory* fDir = nullptr;
63 if (outFile)
64 fDir = outFile->mkdir((fReportName + "_hists").data());
65 //for (auto el : fCanvases)
66 // el->SetDirectory(fDir);
67 } */
68
69 void SetMonitorMode(const Bool_t mm) { fMonitorMode = mm; }
71
72 /* Accessors */
73 const string& GetReportName() const { return fReportName; }
74 const string& GetReportTitle() const { return fReportTitle; }
75 const string& GetOutputDir() const { return fOutputDir; }
77 THttpServer* GetObjServer() const { return fServer; }
78
79 protected:
80 /**
81 * \brief Pure abstract function which is called from public Create() function.
82 * This function has to write report using Out() for output stream and
83 * R() for report elements. This function is called for each report type.
84 */
85 virtual void Create() = 0;
86
87 /**
88 * \brief Pure abstract function which is called from public Create() function.
89 * This function has to draw all necessary histograms and graphs.
90 * It is called only once before report creation.
91 */
92 virtual void Draw() = 0;
93
94 /**
95 * \brief Create all available report types.
96 */
97 void CreateReports();
98
99 /**
100 * \brief Create canvas and put it to vector of TCanvases.
101 * Canvases created with this function will be automatically saved to image and
102 * printed in the report.
103 */
104 TCanvas* CreateCanvas(const char* name, const char* title, Int_t ww, Int_t wh);
105
106 /**
107 * \brief Save all canvases to images.
108 */
109 void SaveCanvasesAsImages() const;
110
111 /**
112 * \brief Write canvases to file.
113 */
114 void WriteCanvases() const;
115
116 /**
117 * \brief Print images created from canvases in the report.
118 */
119 void PrintCanvases() const;
120
124
125 private:
126 /**
127 * \brief Create concrete BmnReportElement instance based on the report type.
128 */
129 void CreateReportElement();
130
131 /**
132 * \brief Delete report element. Normally should be called at the end of Create function.
133 */
134 void DeleteReportElement();
135
136 string fReportName; // Name of report
137 string fReportTitle; // Title of report
138 string fOutputDir; // Output directory for the report files
139 BmnReportElement* fR; // Report element tool
140 mutable ostream* fOut; // Output stream
141
142 // Storage for TCanvas. All Canvases in this vector will be automatically saved
143 // to image and printed in the report.
144 // User can use CreateCanvas function which automatically push created canvas in this vector.
145 vector<TCanvas*> fCanvases;
146 map<string, TCanvas*> fCanvasMap;
147
148 // private:
149
150 BmnReport(const BmnReport&) = delete;
151 BmnReport& operator=(const BmnReport&) = delete;
152
154};
155
156#endif /* BmnREPORT_H_ */
bool Bool_t
int Int_t
#define ClassDef(name, id)
Abstract class for basic report elements (headers, tables, images etc.).
const string & GetReportTitle() const
Definition BmnReport.h:74
void SetMonitorMode(const Bool_t mm)
Definition BmnReport.h:69
void SetReportTitle(const string &title)
Definition BmnReport.h:57
const string & GetOutputDir() const
Definition BmnReport.h:75
virtual void Draw()=0
Pure abstract function which is called from public Create() function.
void SetReportName(TString name)
Definition BmnReport.h:56
void PrintCanvases() const
Print images created from canvases in the report.
BmnReportElement * fR
Definition BmnReport.h:139
BmnReport(const BmnReport &)=delete
void CallDraw()
Definition BmnReport.h:53
const BmnReportElement * R() const
Accessor to BmnReportElement object.
Definition BmnReport.h:45
BmnReport()
Constructor.
Definition BmnReport.cxx:17
void SetOutputDir(const string &outputDir)
Definition BmnReport.h:58
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
void SetObjServer(THttpServer *s)
Definition BmnReport.h:70
string fOutputDir
Definition BmnReport.h:138
string fReportTitle
Definition BmnReport.h:137
THttpServer * GetObjServer() const
Definition BmnReport.h:77
void WriteCanvases() const
Write canvases to file.
BmnReport & operator=(const BmnReport &)=delete
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.
const string & GetReportName() const
Definition BmnReport.h:73
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
Bool_t GetMonitorMode() const
Definition BmnReport.h:76
const char * Data() const