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});
49 B2DEBUG(1,
"DQMHistAnalysisInputRootFile: Constructor done.");
55 if (
m_fileList.size() == 0) B2ERROR(
"File list is empty.");
56 if (
m_runList.size() == 0) B2ERROR(
"Run list is empty.");
57 if (
m_eventsList.size() == 0) B2ERROR(
"Events list is empty.");
58 if (
m_runList.size() !=
m_eventsList.size()) B2ERROR(
"Run list does not have the same size as events list.");
59 if (
m_runList.size() !=
m_fileList.size()) B2ERROR(
"Run list does not have the same size as file list.");
63 B2INFO(
"DQMHistAnalysisInputRootFile: initialized.");
68 boost::replace_all(pattern,
"\\",
"\\\\");
69 boost::replace_all(pattern,
"^",
"\\^");
70 boost::replace_all(pattern,
".",
"\\.");
71 boost::replace_all(pattern,
"$",
"\\$");
72 boost::replace_all(pattern,
"|",
"\\|");
73 boost::replace_all(pattern,
"(",
"\\(");
74 boost::replace_all(pattern,
")",
"\\)");
75 boost::replace_all(pattern,
"[",
"\\[");
76 boost::replace_all(pattern,
"]",
"\\]");
77 boost::replace_all(pattern,
"*",
"\\*");
78 boost::replace_all(pattern,
"+",
"\\+");
79 boost::replace_all(pattern,
"?",
"\\?");
80 boost::replace_all(pattern,
"/",
"\\/");
82 boost::replace_all(pattern,
"\\?",
".");
83 boost::replace_all(pattern,
"\\*",
".*");
85 boost::regex bpattern(pattern);
87 return regex_match(text, bpattern);
92 B2INFO(
"DQMHistAnalysisInputRootFile: beginRun called. Run: " <<
m_runList[
m_run_idx]);
98 B2INFO(
"DQMHistAnalysisInputRootFile: event called.");
134 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
139 std::vector<TH1*> hs;
140 unsigned long long int ts = 0;
142 TIter next(
m_file->GetListOfKeys());
144 while ((key = (TKey*)next())) {
145 TClass* cl = gROOT->GetClass(key->GetClassName());
146 if (ts == 0) ts = key->GetDatime().Convert();
147 if (!cl->InheritsFrom(
"TDirectory"))
continue;
148 TDirectory* d = (TDirectory*)key->ReadObj();
149 std::string dirname = d->GetName();
152 TIter nextd(d->GetListOfKeys());
155 while ((dkey = (TKey*)nextd())) {
156 TClass* dcl = gROOT->GetClass(dkey->GetClassName());
157 if (!dcl->InheritsFrom(
"TH1"))
continue;
158 TH1* h = (TH1*)dkey->ReadObj();
159 if (h->InheritsFrom(
"TH2")) h->SetOption(
"col");
160 else h->SetOption(
"hist");
163 std::string hname = h->GetName();
176 if (!hpass)
continue;
178 if (hname.find(
"/") == std::string::npos) h->SetName((dirname +
"/" + hname).c_str());
186 if (hs.size() == 0) {
187 TIter nexth(
m_file->GetListOfKeys());
189 while ((keyh = (TKey*)nexth())) {
190 TClass* cl = gROOT->GetClass(keyh->GetClassName());
192 if (!cl->InheritsFrom(
"TH1"))
continue;
193 h = (TH1*)keyh->ReadObj();
206 if (!hpass)
continue;
227 for (
size_t i = 0; i < hs.size(); i++) {
230 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
233 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
The base class for the histogram analysis module.
static void clearHistList(void)
Clears the list of 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.
REG_MODULE(arichBtest)
Register the Module.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Abstract base class for different kinds of events.