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>());
43 addParam(
"RunList",
m_runList,
"Run Number List", std::vector<unsigned int> {1u});
44 addParam(
"EventsList",
m_eventsList,
"Number of events for each run", std::vector<unsigned int> {10u});
51 B2DEBUG(1,
"DQMHistAnalysisInputRootFile: Constructor done.");
57 if (
m_fileList.size() == 0) B2ERROR(
"File list is empty.");
58 if (
m_runList.size() == 0) B2ERROR(
"Run list is empty.");
59 if (
m_eventsList.size() == 0) B2ERROR(
"Events list is empty.");
60 if (
m_runList.size() !=
m_eventsList.size()) B2ERROR(
"Run list does not have the same size as events list.");
61 if (
m_runList.size() !=
m_fileList.size()) B2ERROR(
"Run list does not have the same size as file list.");
67 m_c_info =
new TCanvas(
"DQMInfo/c_info",
"");
71 m_h_expno =
new TH1F(
"DQMInfo/expno",
"", 1, 0, 1);
72 m_h_runno =
new TH1F(
"DQMInfo/runno",
"", 1, 0, 1);
73 m_h_rtype =
new TH1F(
"DQMInfo/rtype",
"", 1, 0, 1);
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. Run: " <<
m_runList[
m_run_idx]);
112 B2INFO(
"DQMHistAnalysisInputRootFile: event called.");
113 TH1::AddDirectory(
false);
149 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
154 std::vector<TH1*> hs;
155 unsigned long long int ts = 0;
157 TIter next(
m_file->GetListOfKeys());
159 while ((key = (TKey*)next())) {
160 TClass* cl = gROOT->GetClass(key->GetClassName());
161 if (ts == 0) ts = key->GetDatime().Convert();
162 if (!cl->InheritsFrom(
"TDirectory"))
continue;
163 TDirectory* d = (TDirectory*)key->ReadObj();
164 std::string dirname = d->GetName();
167 TIter nextd(d->GetListOfKeys());
170 while ((dkey = (TKey*)nextd())) {
171 TClass* dcl = gROOT->GetClass(dkey->GetClassName());
172 if (!dcl->InheritsFrom(
"TH1"))
continue;
173 TH1* h = (TH1*)dkey->ReadObj();
174 if (h->InheritsFrom(
"TH2")) h->SetOption(
"col");
175 else h->SetOption(
"hist");
178 std::string hname = h->GetName();
191 if (!hpass)
continue;
193 if (hname.find(
"/") == std::string::npos) h->SetName((dirname +
"/" + hname).c_str());
201 if (hs.size() == 0) {
202 TIter nexth(
m_file->GetListOfKeys());
204 while ((keyh = (TKey*)nexth())) {
205 TClass* cl = gROOT->GetClass(keyh->GetClassName());
207 if (!cl->InheritsFrom(
"TH1"))
continue;
208 h = (TH1*)keyh->ReadObj();
221 if (!hpass)
continue;
230 if (
m_c_info != NULL)
m_c_info->SetTitle((
"OFFLINE: Exp " + std::to_string(
m_expno) +
", Run " + std::to_string(
231 runno) +
", RunType " +
m_runType +
", Last Changed NEVER, Last Updated NEVER, Last DQM event NEVER").c_str());
243 m_h_runno->SetTitle(std::to_string(runno).c_str());
254 for (
size_t i = 0; i < hs.size(); i++) {
257 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
260 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
The base class for the histogram analysis module.
static void clearHistList(void)
Clears the list of histograms.
static void clearRefList(void)
Clears the list of ref histograms.
void setRunType(std::string &t)
Set the Run Type.
void setEventProcessed(int e)
Set the number of processed events.
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 ExtractEvent(std::vector< TH1 * > &hs)
Extract event processed from daq histogram, called from input 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.