Belle II Software  release-08-00-10
DQMHistAnalysisOutputImages.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 //+
9 // File : DQMHistAnalysisOutputImages.cc
10 // Description : DQM Output, send Canvases to jsroot server.
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisOutputImages.h>
15 #include <TROOT.h>
16 #include <TClass.h>
17 #include <TObject.h>
18 #include <TCanvas.h>
19 #include <ctime>
20 
21 using namespace std;
22 using namespace Belle2;
23 
24 //-----------------------------------------------------------------
25 // Register the Module
26 //-----------------------------------------------------------------
27 REG_MODULE(DQMHistAnalysisOutputImages);
28 
29 //-----------------------------------------------------------------
30 // Implementation
31 //-----------------------------------------------------------------
32 
33 DQMHistAnalysisOutputImagesModule::DQMHistAnalysisOutputImagesModule()
35 {
36  setDescription("Module to produce output images during 'events' for dqm steering scripts.");
37  //Parameter definition
38  addParam("CanvasSaveDefault", m_canvasSaveDefault, "Save untagged canvases", false);
39  addParam("OutputPath", m_outputPath, "Set output path", std::string(""));
40  addParam("asPNG", m_asPNG, "Save as PNG files", true);
41  addParam("asJPEG", m_asJPEG, "Save as JPEG files", false);
42  addParam("asPDF", m_asPDF, "Save as PDF files", false);
43  addParam("asJSON", m_asJSON, "Save as JSON files", false);
44  addParam("asROOT", m_asROOT, "Save as ROOT files", false);
45  B2DEBUG(20, "DQMHistAnalysisOutputImages: Constructor done.");
46 }
47 
49 {
50  B2DEBUG(20, "DQMHistAnalysisOutputImages: event called.");
51 
52  TSeqCollection* seq = gROOT->GetListOfCanvases();
53  TIter nextkey(seq);
54  TObject* obj = 0;
55 
56  std::string outpath;
57  if (m_outputPath != "") outpath = m_outputPath + "/"; // make sure slash is added, but only if path not empty
58 
59  auto& clist = getCanvasUpdatedList();
60  int saved_canvases = 0;
61 
62  while ((obj = (TObject*)nextkey())) {
63  if (obj->IsA()->InheritsFrom("TCanvas")) {
64  TCanvas* c = (TCanvas*) obj;
65  auto process_canvas = m_canvasSaveDefault;
66 
67  auto it = clist.find(c->GetName());
68  if (it != clist.end()) {
69  process_canvas = it->second;
70  }
71  if (!process_canvas) continue;
72  saved_canvases++;
73 
74  if (m_asPNG) c->Print((outpath + c->GetName() + ".png").c_str());
75  if (m_asJPEG) c->Print((outpath + c->GetName() + ".jpg").c_str());
76  if (m_asPDF) c->Print((outpath + c->GetName() + ".pdf").c_str());
77  if (m_asROOT) c->Print((outpath + c->GetName() + ".root").c_str());
78  if (m_asJSON) c->Print((outpath + c->GetName() + ".json").c_str());
79  }
80  }
81  B2INFO("Saved " << saved_canvases << " of " << seq->GetEntries() << " objects.");
82 }
83 
The base class for the histogram analysis module.
static const CanvasUpdatedList & getCanvasUpdatedList()
Get the list of the canvas update status.
bool m_canvasSaveDefault
Save untagged canvase by default.
void event() override final
This method is called for each event.
std::string m_outputPath
Output path for saving images in sub-folders.
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.