Belle II Software light-2406-ragdoll
GlobalProcHandler.h
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#pragma once
9
10#include <framework/pcore/ProcHelper.h>
11#include <vector>
12#include <string>
13#include <map>
14
15namespace Belle2 {
23 public:
25 static void initialize(unsigned int nWorkerProc);
26
28 static bool startInputProcess();
30 static bool startWorkerProcesses(unsigned int numProcesses);
32 static bool startOutputProcess(bool local = false);
34 static bool startProxyProcess();
36 static bool startMonitoringProcess();
37
39 static void waitForAllProcesses();
40
42 static bool parallelProcessingUsed();
43
45 static bool isInputProcess();
47 static bool isWorkerProcess();
49 static bool isOutputProcess();
50
52 static int numEventProcesses();
54 static int EvtProcID();
55
57 static std::string getProcessName();
59 static void killAllProcesses();
61 static const std::vector<int>& getPIDList();
62
64 static bool isProcess(ProcType procType);
65
67 static ProcType getProcType(int pid);
68 private:
70 static bool startProc(ProcType procType, int id);
71
75 static int s_processID;
78
80 static std::vector<int> s_pidVector;
82 static std::map<int, ProcType> s_startedPIDs;
83
85 static void addPID(int pid);
87 static bool findPID(int pid);
89 static void removePID(int pid);
91 static void clearPIDs();
93 static bool pidListEmpty();
95 static void childSignalHandler(int);
96 };
98}
A class to manage processes for parallel processing.
static bool startOutputProcess(bool local=false)
Fork and initialize an output process.
static bool isWorkerProcess()
Return true if the process is of type c_Worker.
static bool findPID(int pid)
Find a PID in the list and return true, if found.
static int EvtProcID()
Get the ID of this process. Attention: this ID may not be a stable API feature.
static ProcType getProcType(int pid)
Return the proc type of this process.
static int numEventProcesses()
Return number of worker processes (configured value, not current)
static bool isOutputProcess()
Return true if the process is of type c_Output.
static int s_numEventProcesses
How many processes are handled in this GlobalProcHandler.
static bool startProc(ProcType procType, int id)
Start a new process, sets the type and id and returns true if in this new process.
static bool isInputProcess()
Return true if the process is of type c_Input.
static std::map< int, ProcType > s_startedPIDs
Which PIDs were started with which types.
static bool startInputProcess()
Fork and initialize an input process.
static int s_processID
Our current process id.
static void initialize(unsigned int nWorkerProc)
Create a new process handler, which will handle nWorkerProc processes.
static void clearPIDs()
Remove all PIDs.
static bool startMonitoringProcess()
Fork and initialize a monitoring process.
static bool pidListEmpty()
Check if the PID list is empty (only 0).
static void childSignalHandler(int)
This function is called on SIG_CLD.
static void addPID(int pid)
Add a new PID. Is called when forking.
static ProcType s_procType
Our current proc type.
static bool parallelProcessingUsed()
Returns true if multiple processes have been spawned, false in single-core mode.
static bool startWorkerProcesses(unsigned int numProcesses)
Fork and initialize as many worker processes as requested.
static void removePID(int pid)
Remove a PID from the list by setting it to 0.
static void waitForAllProcesses()
Wait until all forked processes handled by this GlobalProcHandler.
static const std::vector< int > & getPIDList()
Return the PID list handled by the running GlobalProcHandler. This PID list is updated using the sign...
static bool isProcess(ProcType procType)
Return true if the process is of type procType.
static bool startProxyProcess()
Fork and initialize a proxy process.
static void killAllProcesses()
Hard kill all processes.
static std::vector< int > s_pidVector
global list of PIDs managed by GlobalProcHandler.
static std::string getProcessName()
Get a human readable name for this process. (input, event, output...).
ProcType
Type of the process used for storing and mapping the child processes in the process handler.
Definition: ProcHelper.h:16
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24