Belle II Software development
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 <TROOT.h>
17#include <TClass.h>
18#include <TH1F.h>
19#include <TH2F.h>
20
21using namespace std;
22using namespace Belle2;
23
24//-----------------------------------------------------------------
25// Register the Module
26//-----------------------------------------------------------------
27REG_MODULE(DQMHistSnapshots);
28
29//-----------------------------------------------------------------
30// Implementation
31//-----------------------------------------------------------------
32
35{
36 addParam("CheckInterval", m_check_interval, "Interval between two checks [s]", 180);
37 B2DEBUG(1, "DQMHistSnapshots: Constructor done.");
38}
39
40
42
44{
45 gROOT->cd();
46 B2DEBUG(20, "DQMHistSnapshots: initialized.");
47}
48
49
51{
52 m_ssnode.clear();
53 B2DEBUG(20, "DQMHistSnapshots: beginRun called.");
54}
55
57{
58 for (auto& it : m_ssnode) {
59 if (it->histo->GetName() == a)
60 return it;
61 }
62 return NULL;
63}
64
65
67{
68
69 time_t cur_time = time(NULL);
70 int check = 0;
71 if ((m_last_check == 0) || (cur_time - m_last_check > m_check_interval)) {
72 check = 1;
73 m_last_check = cur_time;
74 }
75
76 for (auto& it : getHistList()) {
77 auto name = it.first;
78
79 SSNODE* n = find_snapshot(name);
80 if (n == NULL) { // no existing snapshot, create new one
81 n = new SSNODE;
82 n->histo = (TH1*) it.second.getHist()->Clone();
83
84 auto s = StringSplit(name, '/');
85 auto dirname = s.at(0);
86 auto hname = s.at(1);
87 std::string canvas_name = dirname + "/c_" + hname;
88 n->canvas = findCanvas(canvas_name);
89 n->stale = 0;
90
91 m_ssnode.push_back(n);
92 } else {
93 auto h = it.second.getHist();
94 if (check == 1) {
95 if (h->GetEntries() > n->histo->GetEntries()) { // histogram has been updated
96 delete n->histo;
97 n->histo = (TH1*)h->Clone();
98 n->stale = 0;
99 } else { // notify that the histogram is stale
100 n->stale = 1;
101 }
102 }
103 if (n->stale == 1 && n->canvas != NULL) {
104 h->SetTitle((h->GetTitle() + string(" [STALLED]")).c_str());
105 }
106 }
107
108 }
109}
110
112{
113 B2DEBUG(20, "DQMHistSnapshots: endRun called");
114}
115
116
118{
119 B2DEBUG(20, "DQMHistSnapshots: terminate called");
120}
The base class for the histogram analysis module.
TCanvas * findCanvas(TString cname)
Find canvas by name.
std::vector< std::string > StringSplit(const std::string &s, const char delim)
Helper function for string token split.
static HistList & getHistList()
Get the list of the histograms.
void initialize() override final
Initializer.
int m_check_interval
Interval between checks in second.
std::vector< SSNODE * > m_ssnode
List of snapshots.
void terminate() override final
This method is called at the end of the event processing.
void event() override final
This method is called for each event.
void endRun() override final
This method is called if the current run ends.
time_t m_last_check
The time for the last check.
void beginRun() override final
Called when entering a new run.
SSNODE * find_snapshot(TString a)
Find a snapshot by the histogram's name.
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.
STL namespace.
The struct for the snapshots.