14#include <dqm/analysis/modules/DQMHistAnalysisInput2.h>
40 B2DEBUG(1,
"DQMHistAnalysisInput2: Constructor done.");
46 m_c_info =
new TCanvas(
"DQMInfo/c_info",
"");
50 B2DEBUG(1,
"DQMHistAnalysisInput2: initialized.");
55 B2DEBUG(1,
"DQMHistAnalysisInput2: beginRun called.");
66 auto h = (TH1*)key->ReadObj();
67 if (h ==
nullptr)
return;
68 std::string hname = h->GetName();
70 if (hname.find(
"/") == std::string::npos) {
72 hname = dirname +
"/" + hname;
73 h->SetName(hname.c_str());
83 if (hname.find(
":") != std::string::npos) {
84 B2ERROR(
"histogram or folder name with : is problematic");
86 TString a = h->GetName();
87 a.ReplaceAll(
":",
"");
89 B2DEBUG(1,
"DQMHistAnalysisInput2: get histo " << a.Data());
92 inputHistList.push_back(h);
100 TH1::AddDirectory(
false);
111 const std::filesystem::file_time_type ftime = std::filesystem::last_write_time(
m_mempath);
114 B2INFO(
"File not updated! -> Sleep");
123 time_t now = time(0);
124 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
125 B2INFO(
"[" << mbstr <<
"] before Load File");
127 std::unique_ptr<TFile> pFile = std::unique_ptr<TFile> (
new TFile(
m_mempath.c_str(),
"READ"));
128 if (pFile->IsZombie()) {
129 B2WARNING(
"DQMHistAnalysisInput2: " <<
m_mempath +
" is Zombie -> Sleep");
136 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
137 B2INFO(
"[" << mbstr <<
"] after LoadFile");
139 const TDatime& mt = pFile->GetModificationDate();
140 TDatime mmt(mt.Convert());
141 std::string expno(
"UNKNOWN"), runno(
"UNKNOWN"), rtype(
"UNKNOWN");
144 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
145 B2INFO(
"[" << mbstr <<
"] before input loop");
155 std::vector<TH1*> inputHistList;
159 TIter next(pFile->GetListOfKeys());
160 while (
auto key = (TKey*)next()) {
161 TClass* cl = gROOT->GetClass(key->GetClassName());
162 if (cl->InheritsFrom(
"TDirectory")) {
163 TDirectory* d = (TDirectory*)key->ReadObj();
164 std::string dirname = d->GetName();
167 TIter nextd(d->GetListOfKeys());
169 while (
auto dkey = (TKey*)nextd()) {
170 if (gROOT->GetClass(dkey->GetClassName())->InheritsFrom(
"TH1")) {
175 }
else if (cl->InheritsFrom(
"TH1")) {
180 for (
auto& h : inputHistList) {
181 if (std::string(h->GetName()) == std::string(
"DQMInfo/expno")) expno = h->GetTitle();
182 if (std::string(h->GetName()) == std::string(
"DQMInfo/runno")) runno = h->GetTitle();
183 if (std::string(h->GetName()) == std::string(
"DQMInfo/rtype")) rtype = h->GetTitle();
187 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
188 B2INFO(
"[" << mbstr <<
"] before Close File");
194 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
195 B2INFO(
"[" << mbstr <<
"] before delete File");
199 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
200 B2INFO(
"[" << mbstr <<
"] after input loop");
202 if (expno == std::string(
"UNKNOWN") || runno == std::string(
"UNKNOWN")) {
203 B2WARNING(
"DQMHistAnalysisInput2: " <<
m_mempath +
": Exp " + expno +
", Run " + runno +
", RunType " + rtype +
", Last Updated " +
206 for (
auto& h : inputHistList)
delete h;
209 if (
m_c_info != NULL)
m_c_info->SetTitle((
m_mempath +
": Exp " + expno +
", Run " + runno +
", RunType " + rtype +
", Last Changed "
211 + mmt.AsString() +
", Last DQM event " + std::string(mbstr)).c_str());
215 B2INFO(
"DQMHistAnalysisInput2: " <<
m_mempath +
": Exp " + expno +
", Run " + runno +
", RunType " + rtype +
", Last Updated " +
242 bool anyupdate =
false;
243 for (
auto& h : inputHistList) {
244 anyupdate |=
addHist(
"", h->GetName(), h);
245 B2DEBUG(1,
"Found : " << h->GetName() <<
" : " << h->GetEntries());
261 B2DEBUG(1,
"DQMHistAnalysisInput2: endRun called");
266 B2DEBUG(1,
"DQMHistAnalysisInput2: terminate called");
277 time_t now = time(0);
278 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&now));
280 strftime(mbstr,
sizeof(mbstr),
"%F %T", localtime(&
m_last_event));
281 fprintf(fh,
"%s,", mbstr);
283 fprintf(fh,
"%s,", mbstr);
285 fprintf(fh,
"%s,", mbstr);
287 fprintf(fh,
"%s\n", mbstr);
The base class for the histogram analysis module.
void clearlist(void)
Clear all static global lists.
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.
void setRunType(std::string &t)
Set the Run Type.
static bool addHist(const std::string &dirname, const std::string &histname, TH1 *h)
Add histogram.
void clearCanvases(void)
Clear content of all Canvases.
static int getEventProcessed(void)
Get the number of processed events.
static void initHistListBeforeEvent(void)
Reset the list of histograms.
void resetDeltaList(void)
Reset Delta.
void setReturnValue(int value)
Sets the return value for this module as integer.
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.