Belle II Software  release-06-01-15
DQMHistAnalysisPlotOnly.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 : DQMHistAnalysisPlotOnly.cc
10 // Description : DQM ANalalysis, plots a list of histograms into canvases
11 //-
12 
13 
14 #include <dqm/analysis/modules/DQMHistAnalysisPlotOnly.h>
15 #include <TDirectory.h>
16 #include <TROOT.h>
17 #include <TClass.h>
18 
19 using namespace std;
20 using namespace Belle2;
21 
22 //-----------------------------------------------------------------
23 // Register the Module
24 //-----------------------------------------------------------------
25 REG_MODULE(DQMHistAnalysisPlotOnly)
26 
27 //-----------------------------------------------------------------
28 // Implementation
29 //-----------------------------------------------------------------
30 
31 
34 {
35  //Parameter definition
36  addParam("HistoList", m_histlist, "histname [, canvasname]");
37  B2DEBUG(1, "DQMHistAnalysisPlotOnly: Constructor done.");
38 }
39 
40 TH1* DQMHistAnalysisPlotOnlyModule::GetHisto(TString histoname)
41 {
42  TH1* hh1;
43  hh1 = findHist(histoname.Data());
44  if (hh1 == NULL) {
45  B2DEBUG(20, "Histo " << histoname << " not in memfile");
46  TDirectory* d = gROOT;
47  TString myl = histoname;
48  TString tok;
49  Ssiz_t from = 0;
50  while (myl.Tokenize(tok, from, "/")) {
51  TString dummy;
52  Ssiz_t f;
53  f = from;
54  if (myl.Tokenize(dummy, f, "/")) { // check if its the last one
55  auto e = d->GetDirectory(tok);
56  if (e) {
57  B2DEBUG(20, "Cd Dir " << tok);
58  d = e;
59  }
60  d->cd();
61  } else {
62  break;
63  }
64  }
65  TObject* obj = d->FindObject(tok);
66  if (obj != NULL) {
67  if (obj->IsA()->InheritsFrom("TH1")) {
68  B2DEBUG(20, "Histo " << histoname << " found in mem");
69  hh1 = (TH1*)obj;
70  }
71  } else {
72  B2DEBUG(20, "Histo " << histoname << " NOT found in mem");
73  }
74  }
75 
76  if (hh1 == NULL) {
77  B2DEBUG(20, "Histo " << histoname << " not found");
78  }
79 
80  return hh1;
81 }
82 
83 DQMHistAnalysisPlotOnlyModule::~DQMHistAnalysisPlotOnlyModule() { }
84 
85 void DQMHistAnalysisPlotOnlyModule::initialize()
86 {
87  B2DEBUG(20, "DQMHistAnalysisPlotOnly: initialized.");
88 
89  m_canvasList.clear();
90  for (auto& it : m_histlist) {
91  TString a = "";
92  if (it.size() == 1) {
93  a = TString(it.at(0).c_str());
94  auto p = a.Last('/');
95  if (p == kNPOS) a = "c_" + a;
96  else a.Insert(p + 1, "c_");
97  } else if (it.size() == 2) {
98  a = it.at(1).c_str();
99  } else continue;
100  TCanvas* c = new TCanvas(a);
101  m_canvasList[it.at(0)] = c;
102  }
103 }
104 
105 
106 void DQMHistAnalysisPlotOnlyModule::beginRun()
107 {
108  B2DEBUG(20, "DQMHistAnalysisPlotOnly: beginRun called.");
109 }
110 
111 void DQMHistAnalysisPlotOnlyModule::event()
112 {
113  for (auto& it : m_canvasList) {
114  gROOT->cd();
115 // TH1 *hh1 = findHist(TString(it.first.c_str()));
116  TH1* hh1 = GetHisto(it.first.c_str());
117  if (hh1 == NULL) {
118  B2DEBUG(10, "Hist " << it.first.c_str() << " not found");
119  continue;
120 // hh1 = findHistLocal(it.first);
121  }
122 
123 // if (it.second) {
124  it.second->cd();
125  if (hh1->GetDimension() == 1) {
126  hh1->Draw("hist");
127  } else if (hh1->GetDimension() == 2) {
128  hh1->Draw("colz");
129  }
130  it.second->Modified();
131  it.second->Update();
132 // }
133 
134  }
135 }
136 
137 void DQMHistAnalysisPlotOnlyModule::endRun()
138 {
139  B2DEBUG(20, "DQMHistAnalysisPlotOnly: endRun called");
140 }
141 
142 
143 void DQMHistAnalysisPlotOnlyModule::terminate()
144 {
145  B2DEBUG(20, "DQMHistAnalysisPlotOnly: terminate called");
146 }
147 
The base class for the histogram analysis module.
The module to plot a list of histograms into canvases.
#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.