10 #include <framework/core/ModuleParam.templateDetails.h>
11 #include <dqm/analysis/modules/DQMHistDeltaHisto.h>
12 #include <daq/slc/base/StringUtil.h>
33 addParam(
"Interval", m_interval,
"Interval time for diff histos [s]", 180);
34 addParam(
"MonitoredHistos", m_monitored_histos,
"List of histograms to monitor", vector<string>());
35 B2DEBUG(20,
"DQMHistDeltaHisto: Constructor done.");
39 DQMHistDeltaHistoModule::~DQMHistDeltaHistoModule() { }
41 void DQMHistDeltaHistoModule::initialize()
44 B2DEBUG(20,
"DQMHistDeltaHisto: initialized.");
45 for (
auto& histoname : m_monitored_histos) {
47 m_histos_queues[histoname] = hq;
49 m_evtMetaDataPtr.isRequired();
53 void DQMHistDeltaHistoModule::beginRun()
55 B2DEBUG(20,
"DQMHistDeltaHisto: beginRun called.");
56 for (
auto& histoname : m_monitored_histos) {
57 queue<SSNODE*>& hq = m_histos_queues[histoname];
67 TCanvas* DQMHistDeltaHistoModule::find_canvas(TString canvas_name)
69 TIter nextkey(gROOT->GetListOfCanvases());
70 TObject* obj =
nullptr;
72 while ((obj =
dynamic_cast<TObject*
>(nextkey()))) {
73 if (obj->IsA()->InheritsFrom(
"TCanvas")) {
74 if (obj->GetName() == canvas_name)
75 return dynamic_cast<TCanvas*
>(obj);
81 void DQMHistDeltaHistoModule::clear_node(
SSNODE* n)
87 void DQMHistDeltaHistoModule::event()
90 B2DEBUG(20,
"DQMHistDeltaHisto: event called.");
91 if (!m_evtMetaDataPtr.isValid()) {
92 B2ERROR(
"No valid EventMetaData.");
95 time_t cur_mtime = m_evtMetaDataPtr->getTime();
97 for (
auto& histoname : m_monitored_histos) {
98 TH1* hh = findHist(histoname.c_str());
99 if (hh ==
nullptr)
continue;
100 if (hh->GetDimension() != 1)
continue;
101 queue<SSNODE*>& hq = m_histos_queues[histoname];
104 n->histo = (TH1*)hh->Clone();
105 n->diff_histo = (TH1*)hh->Clone();
106 n->time_modified = cur_mtime;
109 while (!hq.empty()) {
111 if ((cur_mtime - nn->
time_modified < m_interval) || (hq.size() == 1)) {
112 if (hq.back()->time_modified == cur_mtime) {
116 n->histo = (TH1*)hh->Clone();
117 n->diff_histo = (TH1*)hh->Clone();
118 n->diff_histo->Add(nn->
histo, -1);
119 n->time_modified = cur_mtime;
129 TString a = histoname;
130 StringList s = StringUtil::split(a.Data(),
'/');
131 std::string dirname = s[0];
132 std::string hname = s[1];
133 std::string canvas_name = dirname +
"/c_" + hname;
134 TCanvas* c = find_canvas(canvas_name);
135 if (c ==
nullptr)
continue;
136 TH1* h_diff = hq.back()->diff_histo;
137 h_diff->SetName((a +
"_diff").Data());
138 if (h_diff->Integral() != 0) h_diff->Scale(hh->Integral() / h_diff->Integral());
140 h_diff->SetLineColor(kRed);
141 h_diff->SetLineStyle(kDotted);
142 h_diff->SetStats(kFALSE);
143 h_diff->Draw(
"hist,same");
150 void DQMHistDeltaHistoModule::endRun()
152 B2DEBUG(20,
"DQMHistDeltaHisto: endRun called");
156 void DQMHistDeltaHistoModule::terminate()
158 B2DEBUG(20,
"DQMHistDeltaHisto: terminate called");