15#include <dqm/analysis/modules/DQMHistAnalysisInputRootFile.h>
20#include <boost/regex.hpp>
21#include <boost/algorithm/string/replace.hpp>
37 setDescription(
"DQM framework core module for reading histograms from (offline) root file, e.g. for MiraBelle");
41 addParam(
"FileList",
m_fileList,
"List of input files", std::vector<std::string> {
"input_histo.root"});
42 addParam(
"SelectHistograms",
m_histograms,
"List of histogram name patterns, empty for all. Support wildcard matching (* and ?).",
43 std::vector<std::string>());
51 B2DEBUG(1,
"DQMHistAnalysisInputRootFile: Constructor done.");
56 if (
m_fileList.size() == 0) B2FATAL(
"File list is empty.");
60 if (
m_fileList.size() !=
m_eventsList.size()) B2ERROR(
"File list does not have the same size as events list.");
67 m_c_info =
new TCanvas(
"DQMInfo/c_info",
"");
78 B2INFO(
"DQMHistAnalysisInputRootFile: initialized.");
83 boost::replace_all(pattern,
"\\",
"\\\\");
84 boost::replace_all(pattern,
"^",
"\\^");
85 boost::replace_all(pattern,
".",
"\\.");
86 boost::replace_all(pattern,
"$",
"\\$");
87 boost::replace_all(pattern,
"|",
"\\|");
88 boost::replace_all(pattern,
"(",
"\\(");
89 boost::replace_all(pattern,
")",
"\\)");
90 boost::replace_all(pattern,
"[",
"\\[");
91 boost::replace_all(pattern,
"]",
"\\]");
92 boost::replace_all(pattern,
"*",
"\\*");
93 boost::replace_all(pattern,
"+",
"\\+");
94 boost::replace_all(pattern,
"?",
"\\?");
95 boost::replace_all(pattern,
"/",
"\\/");
97 boost::replace_all(pattern,
"\\?",
".");
98 boost::replace_all(pattern,
"\\*",
".*");
100 boost::regex bpattern(pattern);
102 return regex_match(text, bpattern);
107 B2INFO(
"DQMHistAnalysisInputRootFile: beginRun called.");
113 TH1* h =
dynamic_cast<TH1*
>(key->ReadObj());
114 if (h ==
nullptr)
return;
115 std::string hname = h->GetName();
117 if (hname.find(
"/") == std::string::npos) {
119 hname = dirname +
"/" + hname;
120 h->SetName(hname.c_str());
146 if (hname.find(
":") != std::string::npos) {
147 B2ERROR(
"histogram or folder name with : is problematic");
149 TString a = h->GetName();
150 a.ReplaceAll(
":",
"");
152 B2DEBUG(1,
"DQMHistAnalysisInput2: get histo " << a.Data());
157 h->SetEntries(h->GetEntries()*scale);
160 inputHistList.push_back(h);
165 B2INFO(
"DQMHistAnalysisInputRootFile: event called.");
166 TH1::AddDirectory(
false);
201 std::vector<TH1*> inputHistList;
203 unsigned long long int ts = 0;
205 TIter next(
m_file->GetListOfKeys());
206 while (
auto key =
dynamic_cast<TKey*
>(next())) {
207 TClass* cl = gROOT->GetClass(key->GetClassName());
208 if (ts == 0) ts = key->GetDatime().Convert();
209 if (cl->InheritsFrom(
"TDirectory")) {
210 TDirectory* d =
static_cast<TDirectory*
>(key->ReadObj());
211 std::string dirname = d->GetName();
214 TIter nextd(d->GetListOfKeys());
216 while (
auto dkey =
dynamic_cast<TKey*
>(nextd())) {
217 if (gROOT->GetClass(dkey->GetClassName())->InheritsFrom(
"TH1")) {
222 }
else if (cl->InheritsFrom(
"TH1")) {
232 m_h_expno->SetTitle(std::to_string(expno).c_str());
233 inputHistList.push_back(
dynamic_cast<TH1*
>(
m_h_expno->Clone()));
236 m_h_runno->SetTitle(std::to_string(runno).c_str());
237 inputHistList.push_back(
dynamic_cast<TH1*
>(
m_h_runno->Clone()));
241 inputHistList.push_back(
dynamic_cast<TH1*
>(
m_h_rtype->Clone()));
244 inputHistList.push_back(
dynamic_cast<TH1*
>(
m_h_fillNEvent->Clone()));
247 for (
auto& h : inputHistList) {
248 if (std::string(h->GetName()) == std::string(
"DQMInfo/expno")) {
250 expno = atoi(h->GetTitle());
252 h->SetTitle(std::to_string(expno).c_str());
255 if (std::string(h->GetName()) == std::string(
"DQMInfo/runno")) {
257 runno = atoi(h->GetTitle());
259 h->SetTitle(std::to_string(runno).c_str());
262 if (std::string(h->GetName()) == std::string(
"DQMInfo/rtype")) {
264 rtype = h->GetTitle();
266 h->SetTitle(rtype.c_str());
269 if (std::string(h->GetName()) == std::string(
"DAQ/Nevent")) {
273 h->SetEntries(h->GetEntries()*scale);
278 if (
m_c_info !=
nullptr)
m_c_info->SetTitle((
"OFFLINE: Exp " + std::to_string(expno) +
", Run " + std::to_string(
279 runno) +
", RunType " + rtype +
", Last Changed NEVER, Last Updated NEVER, Last DQM event NEVER").c_str());
300 for (
size_t i = 0; i < inputHistList.size(); i++) {
301 TH1* h = inputHistList[i];
303 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
306 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
static void ExtractNEvent(std::vector< TH1 * > &hs)
Extract event processed from daq histogram, called from input module.
static void clearHistList(void)
Clears the list of histograms.
static void clearRefList(void)
Clears the list of ref histograms.
DQMHistAnalysisModule()
Constructor / Destructor.
static bool addHist(const std::string &dirname, const std::string &histname, TH1 *h)
Add histogram.
static void ExtractRunType(std::vector< TH1 * > &hs)
Extract Run Type from histogram title, called from input module.
static void initHistListBeforeEvent(void)
Reset the list of histograms.
void setDescription(const std::string &description)
Sets the description of the module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.