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>
18 #include <sys/types.h>
30 RbTupleManager::RbTupleManager() =
default;
32 RbTupleManager::~RbTupleManager() =
default;
34 RbTupleManager::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 to open directory" << dir);
69 while ((dirp = readdir(dp)) !=
nullptr) {
70 std::string curfile = std::string(dirp->d_name);
71 if (curfile.compare(0, compfile.size(), compfile) == 0) {
73 unlink((
m_workdir +
"/" + curfile).c_str());
77 cout <<
"HistoManager : old temporary histogram files deleted" << endl;
91 std::string fileNamePlusId =
m_workdir +
"/" +
93 m_root =
new TFile(fileNamePlusId.c_str(),
"update");
96 B2INFO(
"RbTupleManager : histo file opened for process " << procid <<
"(" << getpid() <<
")");
100 B2INFO(
"RbTupleManager : initialized for single process");
102 if (
m_root ==
nullptr)
return -1;
143 printf(
"RbTupleManager::hadd started\n");
146 TFileMerger merger(
false,
false);
148 B2ERROR(
"RbTupleManager:: error to open output file " <<
m_filename);
157 if ((dp = opendir(dir.c_str())) ==
nullptr) {
158 B2ERROR(
"Error to open directory" << dir);
162 std::vector<std::string> filenames;
166 printf(
"compfile = %s\n", compfile.c_str());
167 while ((dirp = readdir(dp)) !=
nullptr) {
168 std::string curfile = std::string(dirp->d_name);
170 if (curfile.compare(0, compfile.size(), compfile) == 0) {
171 printf(
"RbTupleManager:: adding file =%s\n", curfile.c_str());
172 merger.AddFile((
m_workdir +
"/" + curfile).c_str());
173 filenames.push_back(
m_workdir +
"/" + curfile);
179 if (!merger.Merge()) {
181 B2ERROR(
"RbTupleManager:: error to merge files");
187 vector<string>::iterator it;
188 for (it = filenames.begin(); it != filenames.end(); ++it) {
190 unlink(hfile.c_str());
194 printf(
"RbTupleManager: histogram files are added\n");