CbmRoot
CbmReport.cxx
Go to the documentation of this file.
1 
7 #include "CbmReport.h"
8 
9 #include "CbmHtmlReportElement.h" // for CbmHtmlReportElement
10 #include "CbmLatexReportElement.h" // for CbmLatexReportElement
11 #include "CbmReportElement.h" // for CbmReportElement
12 #include "CbmTextReportElement.h" // for CbmTextReportElement
13 #include "CbmUtils.h" // for SaveCanvasAsImage
14 
15 #include <TCanvas.h> // for TCanvas
16 #include <TObject.h> // for TObject
17 
18 #include <fstream> // for ofstream
19 #include <string> // for operator+, operator==
20 
21 using std::ofstream;
22 using std::string;
23 
25  : TObject()
26  , fReportName("qa_report")
27  , fReportTitle("QA report")
28  , fOutputDir("./")
29  , fReportType(kCoutReport)
30  , fR(nullptr)
31  , fOut(nullptr)
32  , fCanvases() {}
33 
35 
37  fReportType = reportType;
38  if (nullptr != fR) delete fR;
39  if (nullptr != fOut && fReportType != kCoutReport) delete fOut;
40  if (reportType == kLatexReport) {
41  fR = new CbmLatexReportElement();
42  fOut = new ofstream(string(GetOutputDir() + fReportName + ".tex").c_str());
43  } else if (reportType == kHtmlReport) {
44  fR = new CbmHtmlReportElement();
45  fOut = new ofstream(string(GetOutputDir() + fReportName + ".html").c_str());
46  } else if (reportType == kTextReport) {
47  fR = new CbmTextReportElement();
48  fOut = new ofstream(string(GetOutputDir() + fReportName + ".txt").c_str());
49  } else if (reportType == kCoutReport) {
50  fR = new CbmTextReportElement();
51  fOut = &std::cout;
52  }
53 }
54 
56  // if (nullptr != fR) delete fR;
57  // if (nullptr != fOut && fReportType != kCoutReport) delete fOut;
58 }
59 
61  Draw(); // User has to implement this function!
63  // WriteCanvases();
64 
66  Create(); // User has to implement this function!
68 
70  Create(); // User has to implement this function!
72 
74  Create(); // User has to implement this function!
76 
78  Create(); // User has to implement this function!
80 }
81 
82 TCanvas* CbmReport::CreateCanvas(const char* name,
83  const char* title,
84  Int_t ww,
85  Int_t wh) {
86  TCanvas* canvas = new TCanvas(name, title, ww, wh);
87  fCanvases.push_back(canvas);
88  return canvas;
89 }
90 
92  if (GetOutputDir() == "") return;
93  Int_t nofCanvases = fCanvases.size();
94  for (Int_t i = 0; i < nofCanvases; i++) {
95  TCanvas* canvas = fCanvases[i];
96  Cbm::SaveCanvasAsImage(canvas, GetOutputDir() + "/png/", "png");
97  Cbm::SaveCanvasAsImage(canvas, GetOutputDir() + "/eps/", "eps");
98  }
99 }
100 
102  if (GetOutputDir() == "") return;
103  Int_t nofCanvases = fCanvases.size();
104  for (Int_t i = 0; i < nofCanvases; i++) {
105  fCanvases[i]->Write();
106  }
107 }
108 
110  Int_t nofCanvases = fCanvases.size();
111  for (Int_t i = 0; i < nofCanvases; i++) {
112  TCanvas* canvas = fCanvases[i];
113  Out() << R()->Image(canvas->GetName(),
114  string("png/" + string(canvas->GetName())).c_str());
115  }
116 }
117 
CbmReport::CreateCanvas
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:82
CbmReport::~CbmReport
virtual ~CbmReport()
Destructor.
Definition: CbmReport.cxx:34
kLatexReport
@ kLatexReport
Definition: CbmReport.h:27
CbmLatexReportElement.h
Implementation of CbmReportElement for Latex output.
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
kHtmlReport
@ kHtmlReport
Definition: CbmReport.h:27
CbmReportElement::Image
virtual std::string Image(const std::string &title, const std::string &file) const =0
Return string with image tags.
CbmReport::fR
CbmReportElement * fR
Definition: CbmReport.h:134
kCoutReport
@ kCoutReport
Definition: CbmReport.h:27
CbmReport::DeleteReportElement
void DeleteReportElement()
Delete report element. Normally should be called at the end of Create function.
Definition: CbmReport.cxx:55
CbmReport::R
const CbmReportElement * R() const
Accessor to CbmReportElement object. User has to write the report using available tags from CbmReport...
Definition: CbmReport.h:51
ReportType
ReportType
Enumeration defines different report types.
Definition: CbmReport.h:27
CbmHtmlReportElement.h
Implementation of CbmReportElement for HTML output.
kTextReport
@ kTextReport
Definition: CbmReport.h:27
CbmReportElement.h
Abstract class for basic report elements (headers, tables, images etc.).
CbmReport::fOut
std::ostream * fOut
Definition: CbmReport.h:135
CbmReport::PrintCanvases
void PrintCanvases() const
Print images created from canvases in the report.
Definition: CbmReport.cxx:109
CbmReport::WriteCanvases
void WriteCanvases() const
Write canvases to file.
Definition: CbmReport.cxx:101
CbmReport::fCanvases
std::vector< TCanvas * > fCanvases
Definition: CbmReport.h:140
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmReport::Draw
virtual void Draw()=0
Pure abstract function which is called from public Create() function. This function has to draw all n...
CbmUtils.h
CbmReport::SaveCanvasesAsImages
void SaveCanvasesAsImages() const
Save all canvases to images.
Definition: CbmReport.cxx:91
CbmReport::CreateReportElement
void CreateReportElement(ReportType reportType)
Create concrete CbmReportElement instance based on report type.
Definition: CbmReport.cxx:36
CbmReport::GetOutputDir
const std::string & GetOutputDir() const
Definition: CbmReport.h:66
CbmReport::Out
std::ostream & Out() const
All text output goes to this stream.
Definition: CbmReport.h:56
CbmReport::fReportType
ReportType fReportType
Definition: CbmReport.h:133
CbmReport::CbmReport
CbmReport()
Constructor.
Definition: CbmReport.cxx:24
Cbm::SaveCanvasAsImage
void SaveCanvasAsImage(TCanvas *c, const std::string &dir, const std::string &option)
Definition: CbmUtils.cxx:20
CbmReport
Base class for reports.
Definition: CbmReport.h:35
CbmTextReportElement
Implementation of CbmLitReportElement for text output.
Definition: CbmTextReportElement.h:24
CbmReport.h
CbmReport::Create
virtual void Create()=0
Pure abstract function which is called from public Create() function. This function has to write repo...
CbmLatexReportElement
Implementation of CbmLitReportElement for Latex output.
Definition: CbmLatexReportElement.h:23
CbmReport::CreateReports
void CreateReports()
Create all available report types.
Definition: CbmReport.cxx:60
CbmReport::fReportName
std::string fReportName
Definition: CbmReport.h:130
CbmTextReportElement.h
Implementation of CbmLitReportElement for text output.
CbmHtmlReportElement
Implementation of CbmReportElement for text output.
Definition: CbmHtmlReportElement.h:23