15#include <dqm/analysis/modules/DQMHistAnalysisInputRootFile.h>
20#include <boost/regex.hpp>
21#include <boost/algorithm/string/replace.hpp>
39 addParam(
"FileList",
m_fileList,
"List of input files", std::vector<std::string> {
"input_histo.root"});
40 addParam(
"SelectHistograms",
m_histograms,
"List of histogram name patterns, empty for all. Support wildcard matching (* and ?).",
41 std::vector<std::string>());
49 B2DEBUG(1,
"DQMHistAnalysisInputRootFile: Constructor done.");
54 if (
m_fileList.size() == 0) B2FATAL(
"File list is empty.");
58 if (
m_fileList.size() !=
m_eventsList.size()) B2ERROR(
"File list does not have the same size as events list.");
65 m_c_info =
new TCanvas(
"DQMInfo/c_info",
"");
76 B2INFO(
"DQMHistAnalysisInputRootFile: initialized.");
81 boost::replace_all(pattern,
"\\",
"\\\\");
82 boost::replace_all(pattern,
"^",
"\\^");
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,
"/",
"\\/");
95 boost::replace_all(pattern,
"\\?",
".");
96 boost::replace_all(pattern,
"\\*",
".*");
98 boost::regex bpattern(pattern);
100 return regex_match(text, bpattern);
105 B2INFO(
"DQMHistAnalysisInputRootFile: beginRun called.");
111 TH1* h = (TH1*)key->ReadObj();
112 if (h ==
nullptr)
return;
113 std::string hname = h->GetName();
115 if (hname.find(
"/") == std::string::npos) {
117 hname = dirname +
"/" + hname;
118 h->SetName(hname.c_str());
144 if (hname.find(
":") != std::string::npos) {
145 B2ERROR(
"histogram or folder name with : is problematic");
147 TString a = h->GetName();
148 a.ReplaceAll(
":",
"");
150 B2DEBUG(1,
"DQMHistAnalysisInput2: get histo " << a.Data());
155 h->SetEntries(h->GetEntries()*scale);
158 inputHistList.push_back(h);
163 B2INFO(
"DQMHistAnalysisInputRootFile: event called.");
164 TH1::AddDirectory(
false);
199 std::vector<TH1*> inputHistList;
201 unsigned long long int ts = 0;
203 TIter next(
m_file->GetListOfKeys());
204 while (
auto key = (TKey*)next()) {
205 TClass* cl = gROOT->GetClass(key->GetClassName());
206 if (ts == 0) ts = key->GetDatime().Convert();
207 if (cl->InheritsFrom(
"TDirectory")) {
208 TDirectory* d = (TDirectory*)key->ReadObj();
209 std::string dirname = d->GetName();
212 TIter nextd(d->GetListOfKeys());
214 while (
auto dkey = (TKey*)nextd()) {
215 if (gROOT->GetClass(dkey->GetClassName())->InheritsFrom(
"TH1")) {
220 }
else if (cl->InheritsFrom(
"TH1")) {
230 m_h_expno->SetTitle(std::to_string(expno).c_str());
231 inputHistList.push_back((TH1*)(
m_h_expno->Clone()));
234 m_h_runno->SetTitle(std::to_string(runno).c_str());
235 inputHistList.push_back((TH1*)(
m_h_runno->Clone()));
239 inputHistList.push_back((TH1*)(
m_h_rtype->Clone()));
245 for (
auto& h : inputHistList) {
246 if (std::string(h->GetName()) == std::string(
"DQMInfo/expno")) {
248 expno = atoi(h->GetTitle());
250 h->SetTitle(std::to_string(expno).c_str());
253 if (std::string(h->GetName()) == std::string(
"DQMInfo/runno")) {
255 runno = atoi(h->GetTitle());
257 h->SetTitle(std::to_string(runno).c_str());
260 if (std::string(h->GetName()) == std::string(
"DQMInfo/rtype")) {
262 rtype = h->GetTitle();
264 h->SetTitle(rtype.c_str());
267 if (std::string(h->GetName()) == std::string(
"DAQ/Nevent")) {
271 h->SetEntries(h->GetEntries()*scale);
276 if (
m_c_info !=
nullptr)
m_c_info->SetTitle((
"OFFLINE: Exp " + std::to_string(expno) +
", Run " + std::to_string(
277 runno) +
", RunType " + rtype +
", Last Changed NEVER, Last Updated NEVER, Last DQM event NEVER").c_str());
298 for (
size_t i = 0; i < inputHistList.size(); i++) {
299 TH1* h = inputHistList[i];
301 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
304 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
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.
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 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.