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>
32 DQMHistAnalysisOutputMonObjModule::DQMHistAnalysisOutputMonObjModule()
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(fname,
"NEW");
98 B2WARNING(
"File " <<
LogVar(
"MonitoringObject file",
99 fname) <<
" already exists and it will not be rewritten. If desired please delete file and re-run.");
106 time_t ts = lastEvtMeta->getTime() / 1e9;
108 timeinfo = localtime(&ts);
116 for (
const auto& obj : objts)(obj.second)->Write();
127 TFile* treeFile =
new TFile(
m_treeFile.c_str(),
"update");
128 auto* tree = (TTree*)treeFile->Get(
"tree");
130 if (tree == NULL) tree =
new TTree(
"tree",
"tree");
143 auto b_run = tree->GetBranch(
"run");
144 auto b_exp = tree->GetBranch(
"exp");
145 auto b_release = tree->GetBranch(
"release");
146 auto b_gt = tree->GetBranch(
"gt");
147 auto b_datetime = tree->GetBranch(
"datetime");
148 auto b_rtype = tree->GetBranch(
"rtype");
149 auto b_procID = tree->GetBranch(
"procID");
150 auto b_nevt = tree->GetBranch(
"nevt");
166 if (!b_run) tree->Branch(
"run", &run,
"run/I");
167 else b_run->SetAddress(&run);
168 if (!b_exp) tree->Branch(
"exp", &expe,
"exp/I");
169 else b_exp->SetAddress(&expe);
170 if (!b_nevt) tree->Branch(
"nevt", &nevt,
"nevt/I");
171 else b_nevt->SetAddress(&nevt);
172 if (!b_release) tree->Branch(
"release", rel,
"release/C");
173 else b_release->SetAddress(rel);
174 if (!b_gt) tree->Branch(
"gt", db,
"gt/C");
175 else b_gt->SetAddress(db);
176 if (!b_datetime) tree->Branch(
"datetime", datee,
"datetime/C");
177 else b_datetime->SetAddress(datee);
178 if (!b_rtype) tree->Branch(
"rtype", rtype,
"rtype/C");
179 else b_rtype->SetAddress(rtype);
180 if (!b_procID) tree->Branch(
"procID", procID,
"procID/C");
181 else b_procID->SetAddress(procID);
186 for (
const auto& obj : objts) {
187 std::map<std::string, float>& vars =
const_cast<std::map<std::string, float>&
>((obj.second)->getVariables());
188 std::map<std::string, float>& upErr =
const_cast<std::map<std::string, float>&
>((obj.second)->getUpError());
189 std::map<std::string, float>& lowErr =
const_cast<std::map<std::string, float>&
>((obj.second)->getLowError());
191 const std::vector<std::pair<std::string, std::string>>& strVars = (obj.second)->getStringVariables();
193 for (
auto& var : vars) {
194 std::string brname = obj.first +
"_" + var.first;
195 auto branch = tree->GetBranch((brname).c_str());
197 branch = tree->Branch((brname).c_str(), &(var.second));
199 }
else branch->SetAddress(&(var.second));
201 auto vvE1 = upErr.find(var.first);
202 auto vvE2 = lowErr.find(var.first);
204 if (vvE1 != upErr.end() && vvE2 == lowErr.end()) {
205 auto errBranch = tree->GetBranch((brname).c_str() + TString(
"_err"));
207 errBranch = tree->Branch((brname).c_str() + TString(
"_err"), &(vvE1->second));
209 }
else errBranch->SetAddress(&(vvE1->second));
212 if (vvE1 != upErr.end() && vvE2 != lowErr.end()) {
213 auto errBranch1 = tree->GetBranch((brname).c_str() + TString(
"_upErr"));
215 errBranch1 = tree->Branch((brname).c_str() + TString(
"_upErr"), &(vvE1->second));
217 }
else errBranch1->SetAddress(&(vvE1->second));
219 auto errBranch2 = tree->GetBranch((brname).c_str() + TString(
"_dwErr"));
221 errBranch2 = tree->Branch((brname).c_str() + TString(
"_dwErr"), &(vvE2->second));
223 }
else errBranch2->SetAddress(&(vvE2->second));
228 for (
auto& var : strVars) {
229 std::string brname = obj.first +
"_" + var.first;
230 char* cc =
const_cast<char*
>((var.second).c_str());
231 auto branch = tree->GetBranch((brname).c_str());
233 std::string ty = brname +
"/C";
234 branch = tree->Branch((brname).c_str(), cc, ty.c_str());
236 }
else branch->SetAddress(cc);
241 tree->Write(0, TObject::kWriteDelete, 0);
248 TTree* tree = (TTree*)branch->GetTree();
249 int nentr = tree->GetEntries();
250 for (
int i = 0; i < nentr; i++) {
260 B2INFO(
"DQMHistAnalysisOutputMonObj: terminate called");
The base class for the histogram analysis module.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
std::map< std::string, MonitoringObject * > MonObjList
The type of list of MonitoringObjects.
static const 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.
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.