9#include <dqm/analysis/modules/DQMHistAnalysisOutputFile.h>
35 setDescription(
"Module to save histograms from DQMHistAnalysisModules");
40 "prefix of the output filename {prefix}dqm_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_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.");
55 B2DEBUG(20,
"DQMHistAnalysisOutputFile: initialized.");
60 B2DEBUG(20,
"DQMHistAnalysisOutputFile: event called.");
66 B2INFO(
"DQMHistAnalysisOutputFile: endRun called");
73 B2INFO(
"DQMHistAnalysisOutputFile: terminate called");
90 ss << std::setfill(
'0') << std::setw(4) << exp;
91 ss <<
"r" << std::setfill(
'0') << std::setw(6) << run;
95 TFile f(ss.str().data(),
"recreate");
100 seq = gROOT->GetListOfCanvases() ;
102 B2INFO(
"found canvases");
105 while ((obj = (TObject*)next())) {
106 if (obj->InheritsFrom(
"TCanvas")) {
107 B2DEBUG(1,
"Saving canvas " << obj->GetName());
115 TSeqCollection* files;
116 files = gROOT->GetListOfFiles() ;
118 B2INFO(
"found keys");
119 TIter nextfile(files) ;
122 while ((file = (TObject*)nextfile())) {
123 if (file->InheritsFrom(
"TFile")) {
124 B2INFO(
"File name: " << file->GetName() <<
" title " << file->GetTitle());
125 if (file == &f || file->GetName() ==
m_filename)
continue;
127 TList* list = ((TFile*)file)->GetListOfKeys() ;
133 while ((key = (TKey*)next())) {
134 TString skey(key->GetClassName());
135 if (skey.BeginsWith(TString(
"Belle2::")))
continue;
136 TClass clkey(key->GetClassName());
137 if (clkey.InheritsFrom(
"TH1")) {
138 obj = key->ReadObj() ;
139 B2INFO(
"Histo name: " << obj->GetName() <<
" title " << obj->GetTitle());
141 d = old = gDirectory;
142 TString myl = obj->GetName();
145 while (myl.Tokenize(tok, from,
"/")) {
149 if (myl.Tokenize(dummy, fr,
151 auto e = d->GetDirectory(tok);
164 ((TH1*)obj)->SetName(tok);
171 B2INFO(
"Others name: " << file->GetName() <<
" title " << file->GetTitle());
The base class for the histogram analysis module.
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()
Destructor.
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.