Belle II Software  release-06-02-00
Environment.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 
9 #pragma once
10 
11 #include <framework/logging/LogConfig.h>
12 
13 #include <list>
14 #include <string>
15 #include <vector>
16 #include <memory>
17 
18 namespace Belle2 {
23  class Path;
24 
32  class Environment {
33 
34  public:
35 
41  static Environment& Instance();
42 
46  const std::list<std::string>& getModuleSearchPaths() const;
47 
53  void setExternalsPath(const std::string& externalsPath) { m_externalsPath = externalsPath; };
54 
60  const std::string& getExternalsPath() const { return m_externalsPath; };
61 
63  void setNumberEventsOverride(unsigned int nevents) { m_numberEventsOverride = nevents; }
64 
66  unsigned int getNumberEventsOverride() const { return m_numberEventsOverride; }
67 
69  void setEntrySequencesOverride(const std::vector<std::string>& sequences) { m_entrySequencesOverride = sequences; }
70 
72  std::vector<std::string> getEntrySequencesOverride() const { return m_entrySequencesOverride; }
73 
75  unsigned int getNumberOfEvents() const;
76 
78  void setRunExperimentOverride(int run, int experiment) { m_run = run; m_experiment = experiment; }
79 
81  int getRunOverride() const { return m_run; }
83  int getExperimentOverride() const { return m_experiment; }
84 
86  void setSkipEventsOverride(unsigned int skipEvents) { m_skipNEvents = skipEvents; }
88  unsigned int getSkipEventsOverride() const { return m_skipNEvents; }
89 
91  bool isMC() const;
92 
94  unsigned int getNumberOfMCEvents() const { return m_mcEvents; }
95 
97  void setNumberOfMCEvents(unsigned int n) { m_mcEvents = n; }
98 
100  void setInputFilesOverride(const std::vector<std::string>& names) { m_inputFilesOverride = names; }
101 
103  const std::vector<std::string>& getInputFilesOverride() const { return m_inputFilesOverride; }
104 
106  void setOutputFileOverride(const std::string& name) { m_outputFileOverride = name; }
107 
109  const std::string& getOutputFileOverride() const { return m_outputFileOverride; }
110 
116  std::string consumeOutputFileOverride(const std::string& moduleName);
117 
120  const std::string& getOutputFileOverrideModule() const { return m_outputFileOverrideModule; }
121 
127 
134  void setNumberProcesses(int number) { m_numberProcesses = number; }
135 
139  int getNumberProcesses() const
140  {
141  if (m_numberProcessesOverride >= 0)
143  else
144  return m_numberProcesses;
145  }
146 
152  void setPicklePath(const std::string& path) { m_picklePath = path; }
153 
159  std::string getPicklePath() const { return m_picklePath; }
160 
164  void setSteering(const std::string& steering) { m_steering = steering; };
165 
169  const std::string& getSteering() const { return m_steering; };
170 
173 
175  bool getVisualizeDataFlow() const { return m_visualizeDataFlow; }
176 
178  void setNoStats(bool noStats) { m_noStats = noStats; }
179 
181  bool getNoStats() const { return m_noStats; }
183  void setDryRun(bool dryRun) { m_dryRun = dryRun; }
185  bool getDryRun() const { return m_dryRun; }
186 
188  void setJobInformation(const std::shared_ptr<Path>& path);
189 
191  void setRealm(LogConfig::ELogRealm realm);
194 
200  void printJobInformation() const;
201 
203  void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
204 
206  std::string getProfileModuleName() const { return m_profileModuleName; }
207 
209  void setLogLevelOverride(int level) { m_logLevelOverride = level; }
210 
212  int getLogLevelOverride() const { return m_logLevelOverride; }
213 
215  void setStreamingObjects(const std::vector<std::string>& strobjs) { m_streamingObjects = strobjs; }
216 
218  const std::vector<std::string>& getStreamingObjects() const { return m_streamingObjects; }
219 
220  // ZMQ Options
222  bool getUseZMQ() const
223  {
224  return m_useZMQ;
225  }
226 
228  void setUseZMQ(bool useZMQ)
229  {
230  m_useZMQ = useZMQ;
231  }
232 
234  const std::string& getZMQSocketAddress() const
235  {
236  return m_zmqSocketAddress;
237  }
238 
240  void setZMQSocketAddress(const std::string& zmqSocketAddress)
241  {
242  m_zmqSocketAddress = zmqSocketAddress;
243  }
244 
246  unsigned int getZMQMaximalWaitingTime() const
247  {
249  }
250 
252  void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
253  {
254  m_zmqMaximalWaitingTime = zmqMaximalWaitingTime;
255  }
256 
258  unsigned int getZMQEventBufferSize() const
259  {
260  return m_zmqEventBufferSize;
261  }
262 
264  void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
265  {
266  m_zmqEventBufferSize = zmqEventBufferSize;
267  }
268 
270  unsigned int getZMQWorkerTimeout() const
271  {
272  return m_zmqWorkerTimeout;
273  }
274 
276  void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
277  {
278  m_zmqWorkerTimeout = zmqWorkerTimeout;
279  }
280 
282  bool getZMQUseEventBackup() const
283  {
284  return m_zmqUseEventBackup;
285  }
286 
288  void setZMQUseEventBackup(bool zmqUseEventBackup)
289  {
290  m_zmqUseEventBackup = zmqUseEventBackup;
291  }
292 
295  {
297  }
298 
300  void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
301  {
302  m_zmqRestartFailedWorkers = zmqRestartFailedWorkers;
303  }
304 
307  {
309  }
310 
312  void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
313  {
314  m_zmqFailOnFailedWorkers = zmqFailOnFailedWorkers;
315  }
316 
317  private:
318 
319  std::string m_externalsPath;
321  std::string m_steering;
322  unsigned int m_numberEventsOverride;
323  std::vector<std::string> m_inputFilesOverride;
324  std::vector<std::string>
326  std::string m_outputFileOverride;
327  std::string m_outputFileOverrideModule{""};
331  bool m_noStats;
332  bool m_dryRun;
333  std::string m_jobInfoOutput;
334  std::string m_profileModuleName;
335  std::string m_picklePath;
336  std::vector<std::string> m_streamingObjects;
337  unsigned int m_mcEvents;
338  int m_run;
340  unsigned int m_skipNEvents;
343  // ZMQ specific settings
344  bool m_useZMQ = false;
345  std::string m_zmqSocketAddress = "";
346  unsigned int m_zmqMaximalWaitingTime = 100 * 1000;
347  unsigned int m_zmqEventBufferSize = 2;
348  unsigned int m_zmqWorkerTimeout =
349  0;
350  bool m_zmqUseEventBackup = false;
359  Environment();
360 
364  Environment(const Environment&) = delete;
365 
369  Environment& operator=(const Environment&) = delete;
370 
375 
376  };
377 
379 } //end of namespace Belle2
This class stores all environment information required to run the framework, such as module or data f...
Definition: Environment.h:32
Environment()
Set up environment from standard BELLE2_ environment variables.
Definition: Environment.cc:86
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:270
std::string m_steering
The content of the steering file.
Definition: Environment.h:321
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
Definition: Environment.h:234
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:325
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:320
void setOutputFileOverride(const std::string &name)
Override output file name for modules.
Definition: Environment.h:106
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overriden output file name, or "" if none was set.
Definition: Environment.cc:68
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling requested.
Definition: Environment.h:334
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
Definition: Environment.h:258
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
Definition: Environment.h:300
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:331
bool getDryRun() const
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:185
void setNumberProcesses(int number)
Sets the number of processes which should be used for the parallel processing.
Definition: Environment.h:134
const std::list< std::string > & getModuleSearchPaths() const
Returns a list of file paths searched for module libraries.
Definition: Environment.cc:35
void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
If a worker dies, fail also.
Definition: Environment.h:312
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
Definition: Environment.cc:40
void setProfileModuleName(const std::string &name)
Set the name of a module to be profiled.
Definition: Environment.h:203
const std::string & getSteering() const
Returns the steering file content.
Definition: Environment.h:169
void setSteering(const std::string &steering)
Sets the steering file content.
Definition: Environment.h:164
const std::vector< std::string > & getInputFilesOverride() const
Return overriden input file names, or empty vector if none were set.
Definition: Environment.h:103
bool getZMQFailOnFailedWorkers() const
If a worker dies, fail also.
Definition: Environment.h:306
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:55
~Environment()
The Environment destructor.
const std::vector< std::string > & getStreamingObjects() const
Get list of streaming objects.
Definition: Environment.h:218
std::string m_externalsPath
The path in which the externals are located.
Definition: Environment.h:319
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
Definition: Environment.h:333
void setNumberEventsOverride(unsigned int nevents)
Override the number of events in run 1 for EventInfoSetter module.
Definition: Environment.h:63
void setRealm(LogConfig::ELogRealm realm)
Set the basf2 execution realm.
Definition: Environment.cc:62
bool m_zmqRestartFailedWorkers
If a worker dies, restart it.
Definition: Environment.h:351
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
Definition: Environment.h:344
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
Definition: Environment.cc:164
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:346
const std::string & getExternalsPath() const
Returns the path which points to the externals directory of the framework.
Definition: Environment.h:60
void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:252
unsigned int getSkipEventsOverride() const
Get skipNEvents override, or 0 if unset.
Definition: Environment.h:88
std::string m_outputFileOverride
Override name of output file for output module.
Definition: Environment.h:326
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
Definition: Environment.h:139
const std::string & getOutputFileOverride() const
Return overriden output file name, or "" if none was set.
Definition: Environment.h:109
const std::string & getOutputFileOverrideModule() const
Return the name of the module which consumed the OutputFileOverride, "" if no output file override wa...
Definition: Environment.h:120
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:337
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
Definition: Environment.h:264
void setRunExperimentOverride(int run, int experiment)
Override run and experiment for EventInfoSetter.
Definition: Environment.h:78
std::vector< std::string > m_inputFilesOverride
Override input file names for input modules.
Definition: Environment.h:323
int getExperimentOverride() const
Get experiment override, or -1 if unset.
Definition: Environment.h:83
unsigned int getZMQMaximalWaitingTime() const
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:246
void setExternalsPath(const std::string &externalsPath)
Sets the path which points to the externals directory of the framework.
Definition: Environment.h:53
bool getNoStats() const
Disable collection of statistics during event processing.
Definition: Environment.h:181
std::vector< std::string > m_streamingObjects
objects to be streamed in Tx module (all if empty)
Definition: Environment.h:336
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
Definition: Environment.h:288
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
Definition: Environment.h:215
bool getVisualizeDataFlow() const
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:175
Environment(const Environment &)=delete
Disable/Hide the copy constructor.
void setNumberProcessesOverride(int nproc)
Override number of processes to run in parallel.
Definition: Environment.h:126
void setZMQSocketAddress(const std::string &zmqSocketAddress)
Socket address to use in ZMQ.
Definition: Environment.h:240
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
Definition: Environment.h:94
unsigned int m_numberEventsOverride
Override number of events in the first run.
Definition: Environment.h:322
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
Definition: Environment.h:327
bool m_visualizeDataFlow
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:330
std::vector< std::string > getEntrySequencesOverride() const
Returns the number sequences (e.g.
Definition: Environment.h:72
int m_experiment
override experiment for EventInfoSetter.
Definition: Environment.h:339
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
Definition: Environment.h:348
int getRunOverride() const
Get run override, or -1 if unset.
Definition: Environment.h:81
int m_logLevelOverride
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:329
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:209
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:328
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
Definition: Environment.cc:184
void setEntrySequencesOverride(const std::vector< std::string > &sequences)
Override the number sequences (e.g.
Definition: Environment.h:69
bool getUseZMQ() const
Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
Definition: Environment.h:222
LogConfig::ELogRealm m_realm
The realm in which basf2 is executed.
Definition: Environment.h:341
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:276
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
Definition: Environment.h:282
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:29
std::string m_picklePath
Path to the file where the pickled path is stored.
Definition: Environment.h:335
std::string m_zmqSocketAddress
Socket address to use in ZMQ.
Definition: Environment.h:345
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
Definition: Environment.h:228
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
Definition: Environment.h:350
void setPicklePath(const std::string &path)
Sets the path to the file where the pickled path is stored.
Definition: Environment.h:152
bool getZMQRestartFailedWorkers() const
If a worker dies, restart it.
Definition: Environment.h:294
Environment & operator=(const Environment &)=delete
Disable/Hide the copy assignment operator.
int getLogLevelOverride() const
Get log level override.
Definition: Environment.h:212
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:332
unsigned int getNumberEventsOverride() const
Returns number of events in run 1 for EventInfoSetter module, or 0 for no override.
Definition: Environment.h:66
unsigned int m_skipNEvents
override skipNEvents for EventInfoSetter/RootInput.
Definition: Environment.h:340
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
Definition: Environment.h:352
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
Definition: Environment.h:206
void setSkipEventsOverride(unsigned int skipEvents)
Set skipNEvents override.
Definition: Environment.h:86
void setVisualizeDataFlow(bool on)
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:172
void setInputFilesOverride(const std::vector< std::string > &names)
Override input file names for modules.
Definition: Environment.h:100
void setNoStats(bool noStats)
Disable collection of statistics during event processing.
Definition: Environment.h:178
void setDryRun(bool dryRun)
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:183
std::string getPicklePath() const
Returns the path to the file where the pickled path is stored.
Definition: Environment.h:159
void setNumberOfMCEvents(unsigned int n)
Set number of generated events (for EventInfoSetter).
Definition: Environment.h:97
LogConfig::ELogRealm getRealm() const
Get the basf2 execution realm.
Definition: Environment.h:193
int m_run
override run for EventInfoSetter.
Definition: Environment.h:338
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
Definition: Environment.h:347
ELogRealm
Definition of the supported execution realms.
Definition: LogConfig.h:48
@ c_None
No specific realm.
Definition: LogConfig.h:48
Abstract base class for different kinds of events.