Belle II Software  release-05-02-19
ProcHandler.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <set>
9 #include <string>
10 
11 namespace Belle2 {
18  class ProcHandler {
19  public:
28  explicit ProcHandler(unsigned int nWorkerProc, bool markChildrenAsLocal = false);
30  ~ProcHandler();
31 
33  void startInputProcess();
35  void startWorkerProcesses();
37  void startOutputProcess();
38 
45  bool waitForAllProcesses();
46 
48  static bool parallelProcessingUsed();
50  static bool isInputProcess();
52  static bool isWorkerProcess();
54  static bool isOutputProcess();
55 
56 
58  static int numEventProcesses();
59 
61  std::set<int> processList() const;
63  static std::set<int> globalProcessList();
64 
73  static int EvtProcID();
74 
76  static void setProcessID(int processID);
77 
79  static std::string getProcessName();
80 
81  private:
83  bool startProc(std::set<int>* processList, const std::string& procType, int id);
84 
86  std::set<int> m_processList;
87  unsigned int m_numWorkerProcesses;
88  };
90 }
Belle2::ProcHandler::isWorkerProcess
static bool isWorkerProcess()
Return true if the process is a worker process.
Definition: ProcHandler.cc:225
Belle2::ProcHandler::m_numWorkerProcesses
unsigned int m_numWorkerProcesses
Number of worker processes controlled by this ProcHandler.
Definition: ProcHandler.h:87
Belle2::ProcHandler::waitForAllProcesses
bool waitForAllProcesses()
Wait until all forked processes handled by this ProcHandler terminate.
Definition: ProcHandler.cc:261
Belle2::ProcHandler::startInputProcess
void startInputProcess()
Fork and initialize an input process.
Definition: ProcHandler.cc:202
Belle2::ProcHandler::m_markChildrenAsLocal
bool m_markChildrenAsLocal
Anormal termination of child will not stop parent, waitForAllProcesses() returns status.
Definition: ProcHandler.h:85
Belle2::ProcHandler::ProcHandler
ProcHandler(unsigned int nWorkerProc, bool markChildrenAsLocal=false)
Constructor.
Definition: ProcHandler.cc:183
Belle2::ProcHandler::isOutputProcess
static bool isOutputProcess()
Return true if the process is an output process.
Definition: ProcHandler.cc:227
Belle2::ProcHandler::m_processList
std::set< int > m_processList
PIDs of processes controlled by this ProcHandler.
Definition: ProcHandler.h:86
Belle2::ProcHandler::getProcessName
static std::string getProcessName()
Get a name for this process.
Definition: ProcHandler.cc:247
Belle2::ProcHandler::globalProcessList
static std::set< int > globalProcessList()
Return list of all PIDs (from all ProcHandler instances).
Definition: ProcHandler.cc:234
Belle2::ProcHandler::startOutputProcess
void startOutputProcess()
There is no real output process, but marks current process as output.
Definition: ProcHandler.cc:215
Belle2::ProcHandler::~ProcHandler
~ProcHandler()
Destructor.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ProcHandler::startWorkerProcesses
void startWorkerProcesses()
Fork and initialize worker processes.
Definition: ProcHandler.cc:207
Belle2::ProcHandler
A class to manage processes for parallel processing.
Definition: ProcHandler.h:18
Belle2::ProcHandler::EvtProcID
static int EvtProcID()
Return ID of the current process.
Definition: ProcHandler.cc:243
Belle2::ProcHandler::processList
std::set< int > processList() const
Return list of PIDs managed by this ProcHandler instance.
Definition: ProcHandler.cc:238
Belle2::ProcHandler::setProcessID
static void setProcessID(int processID)
Set the process ID of this process.
Definition: ProcHandler.cc:245
Belle2::ProcHandler::isInputProcess
static bool isInputProcess()
Return true if the process is an input process.
Definition: ProcHandler.cc:223
Belle2::ProcHandler::startProc
bool startProc(std::set< int > *processList, const std::string &procType, int id)
Start a new process, adding its PID to processList, and setting s_processID = id.
Definition: ProcHandler.cc:151
Belle2::ProcHandler::parallelProcessingUsed
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
Definition: ProcHandler.cc:221
Belle2::ProcHandler::numEventProcesses
static int numEventProcesses()
Return number of worker processes (configured value, not current)
Definition: ProcHandler.cc:229