11 #include <dqm/analysis/modules/DQMHistAnalysisInputRootFile.h>
13 #include <daq/slc/base/StringUtil.h>
17 #include <boost/regex.hpp>
18 #include <boost/algorithm/string/replace.hpp>
35 addParam(
"FileList", m_file_list,
"List of input files" , std::vector<std::string> {
"input_histo.root"});
36 addParam(
"SelectHistograms", m_histograms,
"List of histogram name patterns, empty for all. Support wildcard matching (* and ?).",
37 std::vector<std::string>());
38 addParam(
"Experiment", m_expno,
"Experiment Nr" , 7u);
39 addParam(
"RunList", m_run_list,
"Run Number List" , std::vector<unsigned int> {1u});
40 addParam(
"EventsList", m_events_list,
"Number of events for each run" , std::vector<unsigned int> {10u});
41 addParam(
"EventInterval", m_interval,
"Time between events (seconds)" , 20u);
42 addParam(
"NullHistogramMode", m_null_histo_mode,
"Test mode for null histograms" ,
false);
43 addParam(
"AutoCanvas", m_autocanvas,
"Automatic creation of canvas",
true);
44 B2DEBUG(1,
"DQMHistAnalysisInputRootFile: Constructor done.");
50 if (
m_file_list.size() == 0) B2ERROR(
"File list is empty.");
51 if (
m_run_list.size() == 0) B2ERROR(
"Run list is empty.");
52 if (
m_events_list.size() == 0) B2ERROR(
"Events list is empty.");
54 if (
m_run_list.size() !=
m_file_list.size()) B2ERROR(
"Run list does not have the same size as file list.");
58 B2INFO(
"DQMHistAnalysisInputRootFile: initialized.");
63 boost::replace_all(pattern,
"\\",
"\\\\");
64 boost::replace_all(pattern,
"^",
"\\^");
65 boost::replace_all(pattern,
".",
"\\.");
66 boost::replace_all(pattern,
"$",
"\\$");
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,
"/",
"\\/");
77 boost::replace_all(pattern,
"\\?",
".");
78 boost::replace_all(pattern,
"\\*",
".*");
80 boost::regex bpattern(pattern);
82 return regex_match(text, bpattern);
92 B2INFO(
"DQMHistAnalysisInputRootFile: event called.");
116 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
121 std::vector<TH1*> hs;
122 unsigned long long int ts = 0;
124 TIter next(
m_file->GetListOfKeys());
126 while ((key = (TKey*)next())) {
127 TClass* cl = gROOT->GetClass(key->GetClassName());
128 if (ts == 0) ts = key->GetDatime().Convert();
129 if (!cl->InheritsFrom(
"TDirectory"))
continue;
130 TDirectory* d = (TDirectory*)key->ReadObj();
131 std::string dirname = d->GetName();
134 TIter nextd(d->GetListOfKeys());
137 while ((dkey = (TKey*)nextd())) {
138 TClass* dcl = gROOT->GetClass(dkey->GetClassName());
139 if (!dcl->InheritsFrom(
"TH1"))
continue;
140 TH1* h = (TH1*)dkey->ReadObj();
141 if (h->InheritsFrom(
"TH2")) h->SetOption(
"col");
142 else h->SetOption(
"hist");
145 std::string hname = h->GetName();
158 if (!hpass)
continue;
160 if (hname.find(
"/") == std::string::npos) h->SetName((dirname +
"/" + hname).c_str());
164 std::string name = dirname +
"_" + hname;
165 if (
m_cs.find(name) ==
m_cs.end()) {
166 TCanvas* c =
new TCanvas((dirname +
"/c_" + hname).c_str(), (
"c_" + hname).c_str());
167 m_cs.insert(std::pair<std::string, TCanvas*>(name, c));
170 TCanvas* c =
m_cs[name];
172 if (h->GetDimension() == 1) {
174 }
else if (h->GetDimension() == 2) {
185 if (hs.size() == 0) {
186 TIter nexth(
m_file->GetListOfKeys());
188 while ((keyh = (TKey*)nexth())) {
189 TClass* cl = gROOT->GetClass(keyh->GetClassName());
191 if (!cl->InheritsFrom(
"TH1"))
continue;
192 h = (TH1*)keyh->ReadObj();
205 if (!hpass)
continue;
211 std::string name = h->GetName();
212 name.replace(name.find(
"/"), 1,
"/c_");
213 if (
m_cs.find(name) ==
m_cs.end()) {
214 TCanvas* c =
new TCanvas(name.c_str(), name.c_str());
215 m_cs.insert(std::pair<std::string, TCanvas*>(name, c));
217 TCanvas* c =
m_cs[name];
219 if (h->GetDimension() == 1) {
221 }
else if (h->GetDimension() == 2) {
230 for (
size_t i = 0; i < hs.size(); i++) {
233 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
241 B2INFO(
"DQMHistAnalysisInputRootFile: event finished. count: " <<
m_count);
248 B2INFO(
"DQMHistAnalysisInputRootFile : endRun called");
254 B2INFO(
"terminate called");