Belle II Software  release-06-02-00
HistoManagerModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <framework/modules/histomanager/HistoManagerModule.h>
10 
11 #include <framework/core/Environment.h>
12 #include <framework/pcore/ProcHandler.h>
13 #include <framework/pcore/RbTuple.h>
14 
15 using namespace Belle2;
16 using namespace std;
17 
18 //-----------------------------------------------------------------
19 // Register the Module
20 //-----------------------------------------------------------------
22 
23 //-----------------------------------------------------------------
24 // Implementation
25 //-----------------------------------------------------------------
26 
27 // Implementations
28 HistoManagerModule::HistoManagerModule() : Module(), m_initmain(false), m_tupleManagerInitialized(false)
29 {
30  // Module description
31  setDescription("Manage histograms/Ntuples/TTrees for modules inheriting from the HistoModule class. See https://confluence.desy.de/display/BI/Software+HistogramManagement for details.");
32  setPropertyFlags(Module::c_HistogramManager);
33 
34  // Parameters
35  addParam("histoFileName", m_histoFileName, "Name of histogram output file.", string("histofile.root"));
36  addParam("workDirName", m_workdir, "Name of working directory.", string("."));
37 
38 }
39 
40 HistoManagerModule::~HistoManagerModule() = default;
41 
43 {
44  RbTupleManager::Instance().init(Environment::Instance().getNumberProcesses(), m_histoFileName.c_str(), m_workdir.c_str());
45 
46  m_initmain = true;
47  // cout << "HistoManager::initialization done" << endl;
48 
49 }
50 
52 {
53  if (!m_tupleManagerInitialized) {
54  // cout << "HistoManager:: first pass in beginRun() : proc="
55  // << ProcHandler::EvtProcID() << endl;
57  m_tupleManagerInitialized = true;
58  }
59 }
60 
62 {
63  if (!m_tupleManagerInitialized) {
64  // cout << "HistoManager:: first pass in endRun(): proc="
65  // << ProcHandler::EvtProcID() << endl;
67  m_tupleManagerInitialized = true;
68  }
69 }
70 
72 {
73  if (!m_tupleManagerInitialized) {
74  // cout << "HistoManager:: first pass in event() : proc="
75  // << ProcHandler::EvtProcID() << endl;
77  m_tupleManagerInitialized = true;
78  }
79 }
80 
82 {
83  if (m_tupleManagerInitialized) {
84  // cout << "HistoManager::terminating event process : PID=" << ProcHandler::EvtProcID() << endl;
86  }
87 }
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29
Class definition of HistoManager module.
virtual void initialize() override
module functions
virtual void event() override
This method is the core of the module.
virtual void endRun() override
This method is called if the current run ends.
virtual void terminate() override
This method is called at the end of the event processing.
virtual void beginRun() override
Called when entering a new run.
Base class for Modules.
Definition: Module.h:72
@ c_HistogramManager
This module is used to manage histograms accumulated by other modules.
Definition: Module.h:81
static int EvtProcID()
Return ID of the current process.
Definition: ProcHandler.cc:248
static RbTupleManager & Instance()
Access to singleton.
Definition: RbTuple.cc:40
int terminate()
Function called by HistoManager module at the end.
Definition: RbTuple.cc:118
void init(int nprocess, const char *filename, const char *workdir=".")
Global initialization.
Definition: RbTuple.cc:49
int begin(int pid)
Function called by HistoManager module for the first event.
Definition: RbTuple.cc:89
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.