15 #include <dqm/analysis/modules/DQMHistAnalysisInputRootFile.h>
17 #include <daq/slc/base/StringUtil.h>
21 #include <boost/regex.hpp>
22 #include <boost/algorithm/string/replace.hpp>
39 addParam(
"FileList", m_file_list,
"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>());
42 addParam(
"Experiment", m_expno,
"Experiment Nr" , 7u);
43 addParam(
"RunList", m_run_list,
"Run Number List" , std::vector<unsigned int> {1u});
44 addParam(
"EventsList", m_events_list,
"Number of events for each run" , std::vector<unsigned int> {10u});
45 addParam(
"EventInterval", m_interval,
"Time between events (seconds)" , 20u);
46 addParam(
"NullHistogramMode", m_null_histo_mode,
"Test mode for null histograms" ,
false);
47 addParam(
"AutoCanvas", m_autocanvas,
"Automatic creation of canvas",
true);
48 B2DEBUG(1,
"DQMHistAnalysisInputRootFile: Constructor done.");
54 if (
m_file_list.size() == 0) B2ERROR(
"File list is empty.");
55 if (
m_run_list.size() == 0) B2ERROR(
"Run list is empty.");
56 if (
m_events_list.size() == 0) B2ERROR(
"Events list is empty.");
58 if (
m_run_list.size() !=
m_file_list.size()) B2ERROR(
"Run list does not have the same size as file list.");
62 B2INFO(
"DQMHistAnalysisInputRootFile: initialized.");
67 boost::replace_all(pattern,
"\\",
"\\\\");
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,
"/",
"\\/");
81 boost::replace_all(pattern,
"\\?",
".");
82 boost::replace_all(pattern,
"\\*",
".*");
84 boost::regex bpattern(pattern);
86 return regex_match(text, bpattern);
96 B2INFO(
"DQMHistAnalysisInputRootFile: event called.");
120 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
125 std::vector<TH1*> hs;
126 unsigned long long int ts = 0;
128 TIter next(
m_file->GetListOfKeys());
130 while ((key = (TKey*)next())) {
131 TClass* cl = gROOT->GetClass(key->GetClassName());
132 if (ts == 0) ts = key->GetDatime().Convert();
133 if (!cl->InheritsFrom(
"TDirectory"))
continue;
134 TDirectory* d = (TDirectory*)key->ReadObj();
135 std::string dirname = d->GetName();
138 TIter nextd(d->GetListOfKeys());
141 while ((dkey = (TKey*)nextd())) {
142 TClass* dcl = gROOT->GetClass(dkey->GetClassName());
143 if (!dcl->InheritsFrom(
"TH1"))
continue;
144 TH1* h = (TH1*)dkey->ReadObj();
145 if (h->InheritsFrom(
"TH2")) h->SetOption(
"col");
146 else h->SetOption(
"hist");
149 std::string hname = h->GetName();
162 if (!hpass)
continue;
164 if (hname.find(
"/") == std::string::npos) h->SetName((dirname +
"/" + hname).c_str());
168 std::string name = dirname +
"_" + hname;
169 if (
m_cs.find(name) ==
m_cs.end()) {
170 TCanvas* c =
new TCanvas((dirname +
"/c_" + hname).c_str(), (
"c_" + hname).c_str());
171 m_cs.insert(std::pair<std::string, TCanvas*>(name, c));
174 TCanvas* c =
m_cs[name];
176 if (h->GetDimension() == 1) {
178 }
else if (h->GetDimension() == 2) {
189 if (hs.size() == 0) {
190 TIter nexth(
m_file->GetListOfKeys());
192 while ((keyh = (TKey*)nexth())) {
193 TClass* cl = gROOT->GetClass(keyh->GetClassName());
195 if (!cl->InheritsFrom(
"TH1"))
continue;
196 h = (TH1*)keyh->ReadObj();
209 if (!hpass)
continue;
215 std::string name = h->GetName();
216 name.replace(name.find(
"/"), 1,
"/c_");
217 if (
m_cs.find(name) ==
m_cs.end()) {
218 TCanvas* c =
new TCanvas(name.c_str(), name.c_str());
219 m_cs.insert(std::pair<std::string, TCanvas*>(name, c));
221 TCanvas* c =
m_cs[name];
223 if (h->GetDimension() == 1) {
225 }
else if (h->GetDimension() == 2) {
234 for (
size_t i = 0; i < hs.size(); i++) {
237 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
245 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
252 B2INFO(
"DQMHistAnalysisInputRootFile : endRun called");
258 B2INFO(
"terminate called");
The base class for the histogram analysis module.
static void addHist(const std::string &dirname, const std::string &histname, TH1 *h)
Add histogram.
static void resetHist()
Clear and reset the list of histograms.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.