Belle II Software  release-06-02-00
DQMHistSnapshots.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 : DQMHistSnapshots.cc
10 // Description : DQM Histogram analysis module, generate snapshots of histograms
11 //-
12 
13 
14 #include <framework/core/ModuleParam.templateDetails.h>
15 #include <dqm/analysis/modules/DQMHistSnapshots.h>
16 #include <daq/slc/base/StringUtil.h>
17 #include <TROOT.h>
18 #include <TClass.h>
19 #include <TH1F.h>
20 #include <TH2F.h>
21 
22 using namespace std;
23 using namespace Belle2;
24 
25 //-----------------------------------------------------------------
26 // Register the Module
27 //-----------------------------------------------------------------
28 REG_MODULE(DQMHistSnapshots)
29 
30 //-----------------------------------------------------------------
31 // Implementation
32 //-----------------------------------------------------------------
33 
36 {
37  addParam("CheckInterval", m_check_interval, "Interval between two checks [s]", 180);
38  B2DEBUG(1, "DQMHistSnapshots: Constructor done.");
39 }
40 
41 
42 DQMHistSnapshotsModule::~DQMHistSnapshotsModule() { }
43 
44 void DQMHistSnapshotsModule::initialize()
45 {
46  gROOT->cd();
47  B2DEBUG(20, "DQMHistSnapshots: initialized.");
48 }
49 
50 
51 void DQMHistSnapshotsModule::beginRun()
52 {
53  m_ssnode.clear();
54  B2DEBUG(20, "DQMHistSnapshots: beginRun called.");
55 }
56 
57 DQMHistSnapshotsModule::SSNODE* DQMHistSnapshotsModule::find_snapshot(TString a)
58 {
59  for (auto& it : m_ssnode) {
60  if (it->histo->GetName() == a)
61  return it;
62  }
63  return NULL;
64 }
65 
66 
67 void DQMHistSnapshotsModule::event()
68 {
69 
70  time_t cur_time = time(NULL);
71  int check = 0;
72  if ((m_last_check == 0) || (cur_time - m_last_check > m_check_interval)) {
73  check = 1;
74  m_last_check = cur_time;
75  }
76 
77  const HistList& hlist = getHistList();
78 
79  for (HistList::const_iterator it = hlist.begin(); it != hlist.end(); ++it) {
80  TString a = it->first;
81 
82  SSNODE* n = find_snapshot(a);
83  if (n == NULL) { // no existing snapshot, create new one
84  n = new SSNODE;
85  n->histo = (TH1*) it->second->Clone();
86 
87  StringList s = StringUtil::split(a.Data(), '/');
88  std::string dirname = s[0];
89  std::string hname = s[1];
90  std::string canvas_name = dirname + "/c_" + hname;
91  n->canvas = findCanvas(canvas_name);
92  n->stale = 0;
93 
94  m_ssnode.push_back(n);
95  } else {
96  TH1* h = it->second;
97  if (check == 1) {
98  if (h->GetEntries() > n->histo->GetEntries()) { // histogram has been updated
99  delete n->histo;
100  n->histo = (TH1*)h->Clone();
101  n->stale = 0;
102  } else { // notify that the histogram is stale
103  n->stale = 1;
104  }
105  }
106  if (n->stale == 1 && n->canvas != NULL) {
107  h->SetTitle((h->GetTitle() + string(" [STALLED]")).c_str());
108  }
109  }
110 
111  }
112 }
113 
114 void DQMHistSnapshotsModule::endRun()
115 {
116  B2DEBUG(20, "DQMHistSnapshots: endRun called");
117 }
118 
119 
120 void DQMHistSnapshotsModule::terminate()
121 {
122  B2DEBUG(20, "DQMHistSnapshots: terminate called");
123 }
The base class for the histogram analysis module.
std::map< std::string, TH1 * > HistList
The type of list of histograms.
Class for generating snapshots for histograms.
#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.
The struct for the snapshots.