CbmRoot
Loading...
Searching...
No Matches
CbmReport.cxx
Go to the documentation of this file.
1/* Copyright (C) 2011-2020 GSI/JINR-LIT, Darmstadt/Dubna
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Andrey Lebedev [committer], Florian Uhlig */
4
11#include "CbmReport.h"
12
13#include "CbmHtmlReportElement.h" // for CbmHtmlReportElement
14#include "CbmLatexReportElement.h" // for CbmLatexReportElement
15#include "CbmReportElement.h" // for CbmReportElement
16#include "CbmTextReportElement.h" // for CbmTextReportElement
17#include "CbmUtils.h" // for SaveCanvasAsImage
18
19#include <TCanvas.h> // for TCanvas
20#include <TObject.h> // for TObject
21
22#include <fstream> // for ofstream
23#include <string> // for operator+, operator==
24
25using std::ofstream;
26using std::string;
27
29 : TObject()
30 , fReportName("qa_report")
31 , fReportTitle("QA report")
32 , fOutputDir("./")
33 , fReportType(kCoutReport)
34 , fR(nullptr)
35 , fOut(nullptr)
36 , fCanvases()
37{
38}
39
41
43{
44 fReportType = reportType;
45 if (nullptr != fR) delete fR;
46 if (nullptr != fOut && fReportType != kCoutReport) delete fOut;
47 if (reportType == kLatexReport) {
49 fOut = new ofstream(string(GetOutputDir() + fReportName + ".tex").c_str());
50 }
51 else if (reportType == kHtmlReport) {
53 fOut = new ofstream(string(GetOutputDir() + fReportName + ".html").c_str());
54 }
55 else if (reportType == kTextReport) {
57 fOut = new ofstream(string(GetOutputDir() + fReportName + ".txt").c_str());
58 }
59 else if (reportType == kCoutReport) {
61 fOut = &std::cout;
62 }
63}
64
66{
67 // if (nullptr != fR) delete fR;
68 // if (nullptr != fOut && fReportType != kCoutReport) delete fOut;
69}
70
72{
73 Draw(); // User has to implement this function!
75 // WriteCanvases();
76
78 Create(); // User has to implement this function!
80
82 Create(); // User has to implement this function!
84
86 Create(); // User has to implement this function!
88
90 Create(); // User has to implement this function!
92}
93
94TCanvas* CbmReport::CreateCanvas(const char* name, const char* title, Int_t ww, Int_t wh)
95{
96 TCanvas* canvas = new TCanvas(name, title, ww, wh);
97 fCanvases.push_back(canvas);
98 return canvas;
99}
100
102{
103 if (GetOutputDir() == "") return;
104 Int_t nofCanvases = fCanvases.size();
105 for (Int_t i = 0; i < nofCanvases; i++) {
106 TCanvas* canvas = fCanvases[i];
107 Cbm::SaveCanvasAsImage(canvas, GetOutputDir() + "/png/", "png");
108 Cbm::SaveCanvasAsImage(canvas, GetOutputDir() + "/eps/", "eps");
109 }
110}
111
113{
114 if (GetOutputDir() == "") return;
115 Int_t nofCanvases = fCanvases.size();
116 for (Int_t i = 0; i < nofCanvases; i++) {
117 fCanvases[i]->Write();
118 }
119}
120
122{
123 Int_t nofCanvases = fCanvases.size();
124 for (Int_t i = 0; i < nofCanvases; i++) {
125 TCanvas* canvas = fCanvases[i];
126 Out() << R()->Image(canvas->GetName(), string("png/" + string(canvas->GetName())).c_str());
127 }
128}
129
ClassImp(CbmConverterManager)
Implementation of CbmReportElement for HTML output.
Implementation of CbmReportElement for Latex output.
Abstract class for basic report elements (headers, tables, images etc.).
ReportType
Enumeration defines different report types.
Definition CbmReport.h:32
@ kTextReport
Definition CbmReport.h:36
@ kHtmlReport
Definition CbmReport.h:34
@ kLatexReport
Definition CbmReport.h:35
@ kCoutReport
Definition CbmReport.h:33
Implementation of CbmLitReportElement for text output.
Implementation of CbmReportElement for text output.
Implementation of CbmLitReportElement for Latex output.
virtual std::string Image(const std::string &title, const std::string &file) const =0
Return string with image tags.
Base class for reports.
Definition CbmReport.h:45
void WriteCanvases() const
Write canvases to file.
std::ostream & Out() const
All text output goes to this stream.
Definition CbmReport.h:66
CbmReport()
Constructor.
Definition CbmReport.cxx:28
void DeleteReportElement()
Delete report element. Normally should be called at the end of Create function.
Definition CbmReport.cxx:65
ReportType fReportType
Definition CbmReport.h:142
void SaveCanvasesAsImages() const
Save all canvases to images.
void CreateReportElement(ReportType reportType)
Create concrete CbmReportElement instance based on report type.
Definition CbmReport.cxx:42
CbmReportElement * fR
Definition CbmReport.h:143
std::vector< TCanvas * > fCanvases
Definition CbmReport.h:149
virtual ~CbmReport()
Destructor.
Definition CbmReport.cxx:40
void PrintCanvases() const
Print images created from canvases in the report.
std::string fReportName
Definition CbmReport.h:139
virtual void Draw()=0
Pure abstract function which is called from public Create() function. This function has to draw all n...
std::ostream * fOut
Definition CbmReport.h:144
const CbmReportElement * R() const
Accessor to CbmReportElement object. User has to write the report using available tags from CbmReport...
Definition CbmReport.h:61
void CreateReports()
Create all available report types.
Definition CbmReport.cxx:71
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 CbmReport.cxx:94
const std::string & GetOutputDir() const
Definition CbmReport.h:76
virtual void Create()=0
Pure abstract function which is called from public Create() function. This function has to write repo...
Implementation of CbmLitReportElement for text output.
void SaveCanvasAsImage(TCanvas *c, const string &dir, const string &option)
Definition CbmUtils.cxx:36