14 #include <framework/core/ModuleParam.templateDetails.h>
15 #include <dqm/analysis/modules/DQMHistDeltaHisto.h>
16 #include <daq/slc/base/StringUtil.h>
35 addParam(
"Interval", m_interval,
"Interval time for diff histos [s]", 180);
36 addParam(
"MonitoredHistos", m_monitored_histos,
"List of histograms to monitor", vector<string>());
37 B2DEBUG(20,
"DQMHistDeltaHisto: Constructor done.");
41 DQMHistDeltaHistoModule::~DQMHistDeltaHistoModule() { }
43 void DQMHistDeltaHistoModule::initialize()
46 B2DEBUG(20,
"DQMHistDeltaHisto: initialized.");
47 for (
auto& histoname : m_monitored_histos) {
49 m_histos_queues[histoname] = hq;
51 m_evtMetaDataPtr.isRequired();
55 void DQMHistDeltaHistoModule::beginRun()
57 B2DEBUG(20,
"DQMHistDeltaHisto: beginRun called.");
58 for (
auto& histoname : m_monitored_histos) {
59 queue<SSNODE*>& hq = m_histos_queues[histoname];
69 void DQMHistDeltaHistoModule::clear_node(
SSNODE* n)
75 void DQMHistDeltaHistoModule::event()
78 B2DEBUG(20,
"DQMHistDeltaHisto: event called.");
79 if (!m_evtMetaDataPtr.isValid()) {
80 B2ERROR(
"No valid EventMetaData.");
83 time_t cur_mtime = m_evtMetaDataPtr->getTime();
85 for (
auto& histoname : m_monitored_histos) {
86 TH1* hh = findHist(histoname.c_str());
87 if (hh ==
nullptr)
continue;
88 if (hh->GetDimension() != 1)
continue;
89 queue<SSNODE*>& hq = m_histos_queues[histoname];
92 n->histo = (TH1*)hh->Clone();
93 n->diff_histo = (TH1*)hh->Clone();
94 n->time_modified = cur_mtime;
99 if ((cur_mtime - nn->
time_modified < m_interval) || (hq.size() == 1)) {
100 if (hq.back()->time_modified == cur_mtime) {
104 n->histo = (TH1*)hh->Clone();
105 n->diff_histo = (TH1*)hh->Clone();
106 n->diff_histo->Add(nn->
histo, -1);
107 n->time_modified = cur_mtime;
117 TString a = histoname;
118 StringList s = StringUtil::split(a.Data(),
'/');
119 std::string dirname = s[0];
120 std::string hname = s[1];
121 std::string canvas_name = dirname +
"/c_" + hname;
122 TCanvas* c = findCanvas(canvas_name);
123 if (c ==
nullptr)
continue;
124 TH1* h_diff = hq.back()->diff_histo;
125 h_diff->SetName((a +
"_diff").Data());
126 if (h_diff->Integral() != 0) h_diff->Scale(hh->Integral() / h_diff->Integral());
128 h_diff->SetLineColor(kRed);
129 h_diff->SetLineStyle(kDotted);
130 h_diff->SetStats(kFALSE);
131 h_diff->Draw(
"hist,same");
138 void DQMHistDeltaHistoModule::endRun()
140 B2DEBUG(20,
"DQMHistDeltaHisto: endRun called");
144 void DQMHistDeltaHistoModule::terminate()
146 B2DEBUG(20,
"DQMHistDeltaHisto: terminate called");
The base class for the histogram analysis module.
Class for generating snapshots for histograms.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.
The struct for the snapshots.
TH1 * histo
The histogram for snapshot.
time_t time_modified
Whether the histogram is not updated for a long time.