Belle II Software  release-05-01-25
GlobalProcHandler.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Soohyung Lee, Anseln Baur, Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/pcore/ProcHelper.h>
13 #include <vector>
14 #include <string>
15 #include <map>
16 
17 namespace Belle2 {
24  class GlobalProcHandler {
25  public:
27  static void initialize(unsigned int nWorkerProc);
28 
30  static bool startInputProcess();
32  static bool startWorkerProcesses(unsigned int numProcesses);
34  static bool startOutputProcess(bool local = false);
36  static bool startProxyProcess();
38  static bool startMonitoringProcess();
39 
41  static void waitForAllProcesses();
42 
44  static bool parallelProcessingUsed();
45 
47  static bool isInputProcess();
49  static bool isWorkerProcess();
51  static bool isOutputProcess();
52 
54  static int numEventProcesses();
56  static int EvtProcID();
57 
59  static std::string getProcessName();
61  static void killAllProcesses();
63  static const std::vector<int>& getPIDList();
64 
66  static bool isProcess(ProcType procType);
67 
69  static ProcType getProcType(int pid);
70  private:
72  static bool startProc(ProcType procType, int id);
73 
75  static ProcType s_procType;
77  static int s_processID;
79  static int s_numEventProcesses;
80 
82  static std::vector<int> s_pidVector;
84  static std::map<int, ProcType> s_startedPIDs;
85 
87  static void addPID(int pid);
89  static bool findPID(int pid);
91  static void removePID(int pid);
93  static void clearPIDs();
95  static bool pidListEmpty();
97  static void childSignalHandler(int);
98  };
100 }
Belle2::ProcType
ProcType
Type of the process used for storing and mapping the child processes in the process handler.
Definition: ProcHelper.h:9
Belle2::GlobalProcHandler::numEventProcesses
static int numEventProcesses()
Return number of worker processes (configured value, not current)
Definition: GlobalProcHandler.cc:269
Belle2::GlobalProcHandler::getPIDList
static const std::vector< int > & getPIDList()
Return the PID list handled by the running GlobalProcHandler. This PID list is updated using the sign...
Definition: GlobalProcHandler.cc:255
Belle2::GlobalProcHandler::startProc
static bool startProc(ProcType procType, int id)
Start a new process, sets the type and id and returns true if in this new process.
Definition: GlobalProcHandler.cc:182
Belle2::GlobalProcHandler::parallelProcessingUsed
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
Definition: GlobalProcHandler.cc:172
Belle2::GlobalProcHandler::initialize
static void initialize(unsigned int nWorkerProc)
Create a new process handler, which will handle nWorkerProc processes.
Definition: GlobalProcHandler.cc:126
Belle2::GlobalProcHandler::s_numEventProcesses
static int s_numEventProcesses
How many processes are handled in this GlobalProcHandler.
Definition: GlobalProcHandler.h:87
Belle2::GlobalProcHandler::getProcessName
static std::string getProcessName()
Get a human readable name for this process. (input, event, output...).
Definition: GlobalProcHandler.cc:219
Belle2::GlobalProcHandler::s_startedPIDs
static std::map< int, ProcType > s_startedPIDs
Which PIDs were started with which types.
Definition: GlobalProcHandler.h:92
Belle2::GlobalProcHandler::removePID
static void removePID(int pid)
Remove a PID from the list by setting it to 0.
Definition: GlobalProcHandler.cc:101
Belle2::GlobalProcHandler::getProcType
static ProcType getProcType(int pid)
Return the proc type of this process.
Definition: GlobalProcHandler.cc:260
Belle2::GlobalProcHandler::startWorkerProcesses
static bool startWorkerProcesses(unsigned int numProcesses)
Fork and initialize as many worker processes as requested.
Definition: GlobalProcHandler.cc:146
Belle2::GlobalProcHandler::isProcess
static bool isProcess(ProcType procType)
Return true if the process is of type procType.
Definition: GlobalProcHandler.cc:177
Belle2::GlobalProcHandler::startProxyProcess
static bool startProxyProcess()
Fork and initialize a proxy process.
Definition: GlobalProcHandler.cc:136
Belle2::GlobalProcHandler::addPID
static void addPID(int pid)
Add a new PID. Is called when forking.
Definition: GlobalProcHandler.cc:83
Belle2::GlobalProcHandler::clearPIDs
static void clearPIDs()
Remove all PIDs.
Definition: GlobalProcHandler.cc:111
Belle2::GlobalProcHandler::s_processID
static int s_processID
Our current process id.
Definition: GlobalProcHandler.h:85
Belle2::GlobalProcHandler::isInputProcess
static bool isInputProcess()
Return true if the process is of type c_Input.
Definition: GlobalProcHandler.cc:284
Belle2::GlobalProcHandler::EvtProcID
static int EvtProcID()
Get the ID of this process. Attention: this ID may not be a stable API feature.
Definition: GlobalProcHandler.cc:236
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::GlobalProcHandler::pidListEmpty
static bool pidListEmpty()
Check if the PID list is empty (only 0).
Definition: GlobalProcHandler.cc:116
Belle2::GlobalProcHandler::killAllProcesses
static void killAllProcesses()
Hard kill all processes.
Definition: GlobalProcHandler.cc:241
Belle2::GlobalProcHandler::findPID
static bool findPID(int pid)
Find a PID in the list and return true, if found.
Definition: GlobalProcHandler.cc:96
Belle2::GlobalProcHandler::startInputProcess
static bool startInputProcess()
Fork and initialize an input process.
Definition: GlobalProcHandler.cc:141
Belle2::GlobalProcHandler::s_pidVector
static std::vector< int > s_pidVector
global list of PIDs managed by GlobalProcHandler.
Definition: GlobalProcHandler.h:90
Belle2::GlobalProcHandler::childSignalHandler
static void childSignalHandler(int)
This function is called on SIG_CLD.
Definition: GlobalProcHandler.cc:40
Belle2::GlobalProcHandler::isWorkerProcess
static bool isWorkerProcess()
Return true if the process is of type c_Worker.
Definition: GlobalProcHandler.cc:279
Belle2::GlobalProcHandler::startOutputProcess
static bool startOutputProcess(bool local=false)
Fork and initialize an output process.
Definition: GlobalProcHandler.cc:156
Belle2::GlobalProcHandler::s_procType
static ProcType s_procType
Our current proc type.
Definition: GlobalProcHandler.h:83
Belle2::GlobalProcHandler::waitForAllProcesses
static void waitForAllProcesses()
Wait until all forked processes handled by this GlobalProcHandler.
Definition: GlobalProcHandler.cc:289
Belle2::GlobalProcHandler::isOutputProcess
static bool isOutputProcess()
Return true if the process is of type c_Output.
Definition: GlobalProcHandler.cc:274
Belle2::GlobalProcHandler::startMonitoringProcess
static bool startMonitoringProcess()
Fork and initialize a monitoring process.
Definition: GlobalProcHandler.cc:166