9#include <framework/core/HistoModule.h>
10#include <framework/pcore/RbTuple.h>
11#include <framework/pcore/ProcHandler.h>
13#include <framework/logging/Logger.h>
15#include <TFileMerger.h>
28RbTupleManager::RbTupleManager() =
default;
30RbTupleManager::~RbTupleManager() =
default;
32RbTupleManager::RbTupleManager(
int nproc,
const char* file,
const char* workdir):
33 m_nproc(nproc), m_filename(file), m_workdir(workdir)
60 if ((dp = opendir(dir.c_str())) ==
nullptr) {
61 B2ERROR(
"Error on opening the directory."
62 <<
LogVar(
"directory", dir));
68 while ((dirp = readdir(dp)) !=
nullptr) {
69 std::string curfile = std::string(dirp->d_name);
70 if (curfile.compare(0, compfile.size(), compfile) == 0) {
72 unlink((
m_workdir +
"/" + curfile).c_str());
76 B2INFO(
"RbTupleManager: old temporary histogram files deleted.");
90 std::string fileNamePlusId =
m_workdir +
"/" +
92 m_root =
new TFile(fileNamePlusId.c_str(),
"update");
95 B2INFO(
"RbTupleManager: histogram file opened."
96 <<
LogVar(
"process", procid)
97 <<
LogVar(
"pid", getpid()));
101 B2INFO(
"RbTupleManager: initialized for single process.");
103 if (
m_root ==
nullptr)
return -1;
144 B2INFO(
"RbTupleManager: hadd started.");
147 TFileMerger merger(
false,
false);
149 B2ERROR(
"RbTupleManager: error on opening the output file."
159 if ((dp = opendir(dir.c_str())) ==
nullptr) {
160 B2ERROR(
"RbTubleManager: error on opening the directory."
161 <<
LogVar(
"directory", dir));
165 std::vector<std::string> filenames;
169 B2INFO(
LogVar(
"compfile", compfile));
170 while ((dirp = readdir(dp)) !=
nullptr) {
171 std::string curfile = std::string(dirp->d_name);
173 if (curfile.compare(0, compfile.size(), compfile) == 0) {
174 printf(
"RbTupleManager:: adding file =%s\n", curfile.c_str());
175 merger.AddFile((
m_workdir +
"/" + curfile).c_str());
176 filenames.push_back(
m_workdir +
"/" + curfile);
182 if (!merger.Merge()) {
184 B2ERROR(
"RbTupleManager: error on merging files.");
190 vector<string>::iterator it;
191 for (it = filenames.begin(); it != filenames.end(); ++it) {
193 unlink(hfile.c_str());
197 B2INFO(
"RbTupleManager: histogram files are added.");
HistoModule.h is supposed to be used instead of Module.h for the modules with histogram definitions t...
static int EvtProcID()
Return ID of the current process.
Class to manage histograms defined in registered modules.
TFile * m_root
Histogram output file.
static RbTupleManager & Instance()
Access to singleton.
int hadd(bool deleteflag=true)
Functions to add up all histogram files.
std::string m_workdir
Name of working directory.
int terminate()
Function called by HistoManager module at the end.
std::string m_filename
Name of histogram output file.
int dump()
Function to dump histograms/tuples to the file.
void init(int nprocess, const char *filename, const char *workdir=".")
Global initialization.
int begin(int pid)
Function called by HistoManager module for the first event.
int m_nproc
Number of parallel processes.
void register_module(Module *)
Functions called by analysis modules in mother process.
std::vector< Module * > m_histdefs
registered HistoModules.
static RbTupleManager * s_instance
singleton instance.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.