10#include <dqm/analysis/modules/DQMHistAnalysisOutputMonObj.h>
11#include <framework/dataobjects/EventMetaData.h>
12#include <framework/datastore/DataStore.h>
13#include <framework/datastore/StoreObjPtr.h>
38 addParam(
"Filename",
m_filename,
"Output root filename (if not set mon_e{exp}r{run}.root is used", std::string(
""));
39 addParam(
"TreeFile",
m_treeFile,
"If set, entry to run summary TTree from TreeFile is made", std::string(
""));
40 addParam(
"ProcID",
m_procID,
"Processing id (online,proc10, etc.)", std::string(
"online"));
46 B2DEBUG(20,
"DQMHistAnalysisOutputMonObj: Constructor done.");
54 B2DEBUG(20,
"DQMHistAnalysisOutputMonObj: initialized.");
63 B2DEBUG(20,
"DQMHistAnalysisOutputMonObj: beginRun called.");
69 B2DEBUG(20,
"DQMHistAnalysisOutputMonObj: event called.");
74 B2INFO(
"DQMHistAnalysisOutputMonObj: endRun called");
79 TH1* hrun =
findHist(
"DQMInfo/runno");
80 TH1* hexp =
findHist(
"DQMInfo/expno");
82 int run = hrun ? std::stoi(hrun->GetTitle()) :
m_run;
83 int exp = hexp ? std::stoi(hexp->GetTitle()) :
m_exp;
86 else fname = TString::Format(
"mon_e%04dr%06d_%s.root", exp, run,
m_procID.c_str());
88 TH1* runtype =
findHist(
"DQMInfo/rtype");
95 TFile* f =
new TFile(fname,
"NEW");
98 B2WARNING(
"File " <<
LogVar(
"MonitoringObject file",
99 fname) <<
" already exists additional data will be appended! previous metadata is kept.");
100 f =
new TFile(fname,
"UPDATE");
107 time_t ts = lastEvtMeta->getTime() / 1e9;
109 timeinfo = localtime(&ts);
118 for (
const auto& obj : objts) {
120 if (exist) f->Delete(obj.second.GetName() + TString(
";*"));
132 TFile* treeFile =
new TFile(
m_treeFile.c_str(),
"update");
133 auto* tree = (TTree*)treeFile->Get(
"tree");
135 if (tree == NULL) tree =
new TTree(
"tree",
"tree");
148 auto b_run = tree->GetBranch(
"run");
149 auto b_exp = tree->GetBranch(
"exp");
150 auto b_release = tree->GetBranch(
"release");
151 auto b_gt = tree->GetBranch(
"gt");
152 auto b_datetime = tree->GetBranch(
"datetime");
153 auto b_rtype = tree->GetBranch(
"rtype");
154 auto b_procID = tree->GetBranch(
"procID");
155 auto b_nevt = tree->GetBranch(
"nevt");
171 if (!b_run) tree->Branch(
"run", &run,
"run/I");
172 else b_run->SetAddress(&run);
173 if (!b_exp) tree->Branch(
"exp", &expe,
"exp/I");
174 else b_exp->SetAddress(&expe);
175 if (!b_nevt) tree->Branch(
"nevt", &nevt,
"nevt/I");
176 else b_nevt->SetAddress(&nevt);
177 if (!b_release) tree->Branch(
"release", rel,
"release/C");
178 else b_release->SetAddress(rel);
179 if (!b_gt) tree->Branch(
"gt", db,
"gt/C");
180 else b_gt->SetAddress(db);
181 if (!b_datetime) tree->Branch(
"datetime", date,
"datetime/C");
182 else b_datetime->SetAddress(date);
183 if (!b_rtype) tree->Branch(
"rtype", rtype,
"rtype/C");
184 else b_rtype->SetAddress(rtype);
185 if (!b_procID) tree->Branch(
"procID", procID,
"procID/C");
186 else b_procID->SetAddress(procID);
191 for (
auto& obj : objts) {
192 auto& vars =
const_cast<std::map<std::string, float>&
>(obj.second.getVariables());
193 auto& upErr =
const_cast<std::map<std::string, float>&
>(obj.second.getUpError());
194 auto& lowErr =
const_cast<std::map<std::string, float>&
>(obj.second.getLowError());
195 auto& strVars = obj.second.getStringVariables();
197 for (
auto& var : vars) {
198 std::string brname = obj.first +
"_" + var.first;
199 auto branch = tree->GetBranch((brname).c_str());
201 branch = tree->Branch((brname).c_str(), &(var.second));
203 }
else branch->SetAddress(&(var.second));
205 auto vvE1 = upErr.find(var.first);
206 auto vvE2 = lowErr.find(var.first);
208 if (vvE1 != upErr.end() && vvE2 == lowErr.end()) {
209 auto errBranch = tree->GetBranch((brname).c_str() + TString(
"_err"));
211 errBranch = tree->Branch((brname).c_str() + TString(
"_err"), &(vvE1->second));
213 }
else errBranch->SetAddress(&(vvE1->second));
216 if (vvE1 != upErr.end() && vvE2 != lowErr.end()) {
217 auto errBranch1 = tree->GetBranch((brname).c_str() + TString(
"_upErr"));
219 errBranch1 = tree->Branch((brname).c_str() + TString(
"_upErr"), &(vvE1->second));
221 }
else errBranch1->SetAddress(&(vvE1->second));
223 auto errBranch2 = tree->GetBranch((brname).c_str() + TString(
"_dwErr"));
225 errBranch2 = tree->Branch((brname).c_str() + TString(
"_dwErr"), &(vvE2->second));
227 }
else errBranch2->SetAddress(&(vvE2->second));
232 for (
auto& var : strVars) {
233 std::string brname = obj.first +
"_" + var.first;
234 char* cc =
const_cast<char*
>((var.second).c_str());
235 auto branch = tree->GetBranch((brname).c_str());
237 std::string ty = brname +
"/C";
238 branch = tree->Branch((brname).c_str(), cc, ty.c_str());
240 }
else branch->SetAddress(cc);
245 tree->Write(0, TObject::kWriteDelete, 0);
252 TTree* tree = (TTree*)branch->GetTree();
253 int nentr = tree->GetEntries();
254 for (
int i = 0; i < nentr; i++) {
264 B2INFO(
"DQMHistAnalysisOutputMonObj: terminate called");
The base class for the histogram analysis module.
std::map< std::string, MonitoringObject > MonObjList
The type of list of MonitoringObjects.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static MonObjList & getMonObjList()
Get the list of MonitoringObjects.
void initialize() override final
Initializer.
std::string m_runtype
run type
void terminate() override final
This method is called at the end of the event processing.
void event() override final
This method is called for each event.
std::string m_procID
processing id (online,proc10,etc)
~DQMHistAnalysisOutputMonObjModule()
Destructor.
void fillBranch(TBranch *br)
if new variables is added to run summary TTree this files
int m_exp
experiment number
void endRun() override final
This method is called if the current run ends.
DQMHistAnalysisOutputMonObjModule()
Constructor.
std::string m_filename
file name of root file
void beginRun() override final
Called when entering a new run.
void addTreeEntry()
Makes entry with monitoring variables in the run summary TTree.
DQMFileMetaData * m_metaData
output file meta data
std::string m_treeFile
if set, entry with monitoring variables is made in the run summary TTree
void setDescription(const std::string &description)
Sets the description of the module.
Type-safe access to single objects in the data store.
Class to store variables with their name which were sent to the logging service.
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.