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>
30RbTupleManager::RbTupleManager() =
default;
32RbTupleManager::~RbTupleManager() =
default;
34RbTupleManager::RbTupleManager(
int nproc,
const char* file,
const char* workdir):
35 m_nproc(nproc), m_filename(file), m_workdir(workdir)
62 if ((dp = opendir(dir.c_str())) ==
nullptr) {
63 B2ERROR(
"Error on opening the directory."
64 <<
LogVar(
"directory", dir));
70 while ((dirp = readdir(dp)) !=
nullptr) {
71 std::string curfile = std::string(dirp->d_name);
72 if (curfile.compare(0, compfile.size(), compfile) == 0) {
74 unlink((
m_workdir +
"/" + curfile).c_str());
78 B2INFO(
"RbTupleManager: old temporary histogram files deleted.");
92 std::string fileNamePlusId =
m_workdir +
"/" +
94 m_root =
new TFile(fileNamePlusId.c_str(),
"update");
97 B2INFO(
"RbTupleManager: histogram file opened."
98 <<
LogVar(
"process", procid)
99 <<
LogVar(
"pid", getpid()));
103 B2INFO(
"RbTupleManager: initialized for single process.");
105 if (
m_root ==
nullptr)
return -1;
146 B2INFO(
"RbTupleManager: hadd started.");
149 TFileMerger merger(
false,
false);
151 B2ERROR(
"RbTupleManager: error on opening the output file."
161 if ((dp = opendir(dir.c_str())) ==
nullptr) {
162 B2ERROR(
"RbTubleManager: error on opening the directory."
163 <<
LogVar(
"directory", dir));
167 std::vector<std::string> filenames;
171 B2INFO(
LogVar(
"compfile", compfile));
172 while ((dirp = readdir(dp)) !=
nullptr) {
173 std::string curfile = std::string(dirp->d_name);
175 if (curfile.compare(0, compfile.size(), compfile) == 0) {
176 printf(
"RbTupleManager:: adding file =%s\n", curfile.c_str());
177 merger.AddFile((
m_workdir +
"/" + curfile).c_str());
178 filenames.push_back(
m_workdir +
"/" + curfile);
184 if (!merger.Merge()) {
186 B2ERROR(
"RbTupleManager: error on merging files.");
192 vector<string>::iterator it;
193 for (it = filenames.begin(); it != filenames.end(); ++it) {
195 unlink(hfile.c_str());
199 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.