9#include <dqm/analysis/modules/DQMHistAnalysisOutputFile.h>
35 setDescription(
"Module to save histograms from DQMHistAnalysisModules");
40 "prefix of the output filename {prefix}dqm_canvas_e####r######.root is generated (unless Filename is set)", std::string(
""));
41 addParam(
"Filename",
m_filename,
"name of the output file (default is {prefix}dqm_canvas_e####r######.root)", std::string(
""));
45 addParam(
"SavePerRun",
m_savePerRun,
"Whether save to file for each run (not usable in online analysis!)",
false);
46 B2DEBUG(20,
"DQMHistAnalysisOutputFile: Constructor done.");
52 B2DEBUG(20,
"DQMHistAnalysisOutputFile: initialized.");
57 B2DEBUG(20,
"DQMHistAnalysisOutputFile: event called.");
63 B2INFO(
"DQMHistAnalysisOutputFile: endRun called");
70 B2INFO(
"DQMHistAnalysisOutputFile: terminate called");
87 ss << std::setfill(
'0') << std::setw(4) << exp;
88 ss <<
"r" << std::setfill(
'0') << std::setw(6) << run;
92 TFile f(ss.str().data(),
"recreate");
97 seq = gROOT->GetListOfCanvases() ;
99 B2INFO(
"found canvases");
102 while ((obj = (TObject*)next())) {
103 if (obj->InheritsFrom(
"TCanvas")) {
104 B2DEBUG(1,
"Saving canvas " << obj->GetName());
112 TSeqCollection* files;
113 files = gROOT->GetListOfFiles() ;
115 B2INFO(
"found keys");
116 TIter nextfile(files) ;
119 while ((file = (TObject*)nextfile())) {
120 if (file->InheritsFrom(
"TFile")) {
121 B2INFO(
"File name: " << file->GetName() <<
" title " << file->GetTitle());
122 if (file == &f || file->GetName() ==
m_filename)
continue;
124 TList* list = ((TFile*)file)->GetListOfKeys() ;
130 while ((key = (TKey*)next())) {
131 TString skey(key->GetClassName());
132 if (skey.BeginsWith(TString(
"Belle2::")))
continue;
133 TClass clkey(key->GetClassName());
134 if (clkey.InheritsFrom(
"TH1")) {
135 obj = key->ReadObj() ;
136 B2INFO(
"Histo name: " << obj->GetName() <<
" title " << obj->GetTitle());
138 d = old = gDirectory;
139 TString myl = obj->GetName();
142 while (myl.Tokenize(tok, from,
"/")) {
146 if (myl.Tokenize(dummy, fr,
148 auto e = d->GetDirectory(tok);
161 ((TH1*)obj)->SetName(tok);
168 B2INFO(
"Others name: " << file->GetName() <<
" title " << file->GetTitle());
DQMHistAnalysisModule()
Constructor / Destructor.
bool m_saveCanvases
Write all Canvases to file.
void initialize() override final
Initializer.
bool m_savePerEvent
Whether save to file per event.
std::string m_prefix
prefix for the output file name
bool m_saveHistos
Write all Histos to file.
std::string m_folder
output folder to save root file
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.
void endRun() override final
This method is called if the current run ends.
std::string m_filename
file name of root file
StoreObjPtr< EventMetaData > m_eventMetaDataPtr
event metadata object
void save_to_file()
Opens the root file and saves the content.
DQMHistAnalysisOutputFileModule()
Constructor.
bool m_savePerRun
Whether save to file per run.
void setDescription(const std::string &description)
Sets the description of the module.
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.