Belle II Software  release-08-01-10
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 setSecondaryInputFilesOverride(const std::vector<std::string>& names) { m_secondaryInputFilesOverride = names; }
107 
109  const std::vector<std::string>& getSecondaryInputFilesOverride() const { return m_secondaryInputFilesOverride; }
110 
112  void setOutputFileOverride(const std::string& name) { m_outputFileOverride = name; }
113 
115  const std::string& getOutputFileOverride() const { return m_outputFileOverride; }
116 
122  std::string consumeOutputFileOverride(const std::string& moduleName);
123 
126  const std::string& getOutputFileOverrideModule() const { return m_outputFileOverrideModule; }
127 
133 
140  void setNumberProcesses(int number) { m_numberProcesses = number; }
141 
145  int getNumberProcesses() const
146  {
147  if (m_numberProcessesOverride >= 0)
149  else
150  return m_numberProcesses;
151  }
152 
158  void setPicklePath(const std::string& path) { m_picklePath = path; }
159 
165  std::string getPicklePath() const { return m_picklePath; }
166 
170  void setSteering(const std::string& steering) { m_steering = steering; };
171 
175  const std::string& getSteering() const { return m_steering; };
176 
179 
181  bool getVisualizeDataFlow() const { return m_visualizeDataFlow; }
182 
184  void setNoStats(bool noStats) { m_noStats = noStats; }
185 
187  bool getNoStats() const { return m_noStats; }
189  void setDryRun(bool dryRun) { m_dryRun = dryRun; }
191  bool getDryRun() const { return m_dryRun; }
192 
194  void setJobInformation(const std::shared_ptr<Path>& path);
195 
197  void setRealm(LogConfig::ELogRealm realm);
200 
206  void printJobInformation() const;
207 
209  void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
210 
212  std::string getProfileModuleName() const { return m_profileModuleName; }
213 
215  void setLogLevelOverride(int level) { m_logLevelOverride = level; }
216 
218  int getLogLevelOverride() const { return m_logLevelOverride; }
219 
221  void setStreamingObjects(const std::vector<std::string>& strobjs) { m_streamingObjects = strobjs; }
222 
224  const std::vector<std::string>& getStreamingObjects() const { return m_streamingObjects; }
225 
226  // ZMQ Options
228  bool getUseZMQ() const
229  {
230  return m_useZMQ;
231  }
232 
234  void setUseZMQ(bool useZMQ)
235  {
236  m_useZMQ = useZMQ;
237  }
238 
240  const std::string& getZMQSocketAddress() const
241  {
242  return m_zmqSocketAddress;
243  }
244 
246  void setZMQSocketAddress(const std::string& zmqSocketAddress)
247  {
248  m_zmqSocketAddress = zmqSocketAddress;
249  }
250 
252  unsigned int getZMQMaximalWaitingTime() const
253  {
255  }
256 
258  void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
259  {
260  m_zmqMaximalWaitingTime = zmqMaximalWaitingTime;
261  }
262 
264  unsigned int getZMQEventBufferSize() const
265  {
266  return m_zmqEventBufferSize;
267  }
268 
270  void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
271  {
272  m_zmqEventBufferSize = zmqEventBufferSize;
273  }
274 
276  unsigned int getZMQWorkerTimeout() const
277  {
278  return m_zmqWorkerTimeout;
279  }
280 
282  void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
283  {
284  m_zmqWorkerTimeout = zmqWorkerTimeout;
285  }
286 
288  bool getZMQUseEventBackup() const
289  {
290  return m_zmqUseEventBackup;
291  }
292 
294  void setZMQUseEventBackup(bool zmqUseEventBackup)
295  {
296  m_zmqUseEventBackup = zmqUseEventBackup;
297  }
298 
301  {
303  }
304 
306  void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
307  {
308  m_zmqRestartFailedWorkers = zmqRestartFailedWorkers;
309  }
310 
313  {
315  }
316 
318  void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
319  {
320  m_zmqFailOnFailedWorkers = zmqFailOnFailedWorkers;
321  }
322 
323  // DAQ environment
325  bool getZMQDAQEnvironment() const
326  {
327  return m_zmqDAQEnvironment;
328  }
329 
331  void setZMQDAQEnvironment(bool zmqDAQ)
332  {
333  m_zmqDAQEnvironment = zmqDAQ;
334  }
335 
338  {
339  return m_zmqDAQFirstEventExp;
340  }
341 
344  {
345  m_zmqDAQFirstEventExp = exp;
346  }
347 
350  {
351  return m_zmqDAQFirstEventRun;
352  }
353 
356  {
357  m_zmqDAQFirstEventRun = run;
358  }
359 
361  bool isZMQDAQFirstEvent(int exp, int run)
362  {
363  if (exp == m_zmqDAQFirstEventExp && run == m_zmqDAQFirstEventRun)
364  return true;
365  else
366  return false;
367  }
368 
369  private:
370 
371  std::string m_externalsPath;
373  std::string m_steering;
374  unsigned int m_numberEventsOverride;
375  std::vector<std::string> m_inputFilesOverride;
376  std::vector<std::string> m_secondaryInputFilesOverride;
377  std::vector<std::string>
379  std::string m_outputFileOverride;
380  std::string m_outputFileOverrideModule{""};
384  bool m_noStats;
385  bool m_dryRun;
386  std::string m_jobInfoOutput;
387  std::string m_profileModuleName;
388  std::string m_picklePath;
389  std::vector<std::string> m_streamingObjects;
390  unsigned int m_mcEvents;
391  int m_run;
393  unsigned int m_skipNEvents;
396  // ZMQ specific settings
397  bool m_useZMQ = false;
398  std::string m_zmqSocketAddress = "";
399  unsigned int m_zmqMaximalWaitingTime = (3600 * 24) *
400  1000;
401  unsigned int m_zmqEventBufferSize = 1;
402  unsigned int m_zmqWorkerTimeout =
403  0;
404  bool m_zmqUseEventBackup = true;
407  bool m_zmqDAQEnvironment = false;
416  Environment();
417 
421  Environment(const Environment&) = delete;
422 
426  Environment& operator=(const Environment&) = delete;
427 
432 
433  };
434 
436 } //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:85
bool m_zmqDAQEnvironment
True in DAQ environment.
Definition: Environment.h:407
int m_zmqDAQFirstEventRun
Exp no.
Definition: Environment.h:409
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:276
std::string m_steering
The content of the steering file.
Definition: Environment.h:373
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
Definition: Environment.h:240
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:378
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:372
void setOutputFileOverride(const std::string &name)
Override output file name for modules.
Definition: Environment.h:112
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overriden output file name, or "" if none was set.
Definition: Environment.cc:67
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling requested.
Definition: Environment.h:387
void setZMQDAQFirstEventExp(int exp)
set the exp number for DAQ first event
Definition: Environment.h:343
bool isZMQDAQFirstEvent(int exp, int run)
checks the exp/run is DAQ first event
Definition: Environment.h:361
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
Definition: Environment.h:264
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
Definition: Environment.h:306
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:384
bool getDryRun() const
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:191
void setNumberProcesses(int number)
Sets the number of processes which should be used for the parallel processing.
Definition: Environment.h:140
const std::list< std::string > & getModuleSearchPaths() const
Returns a list of file paths searched for module libraries.
Definition: Environment.cc:34
void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
If a worker dies, fail also.
Definition: Environment.h:318
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
Definition: Environment.cc:39
void setProfileModuleName(const std::string &name)
Set the name of a module to be profiled.
Definition: Environment.h:209
const std::string & getSteering() const
Returns the steering file content.
Definition: Environment.h:175
void setSteering(const std::string &steering)
Sets the steering file content.
Definition: Environment.h:170
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:312
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:54
~Environment()
The Environment destructor.
const std::vector< std::string > & getStreamingObjects() const
Get list of streaming objects.
Definition: Environment.h:224
std::string m_externalsPath
The path in which the externals are located.
Definition: Environment.h:371
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
Definition: Environment.h:386
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:61
bool m_zmqRestartFailedWorkers
If a worker dies, restart it.
Definition: Environment.h:405
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
Definition: Environment.h:397
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
Definition: Environment.cc:159
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:399
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:258
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:379
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
Definition: Environment.h:145
const std::string & getOutputFileOverride() const
Return overriden output file name, or "" if none was set.
Definition: Environment.h:115
const std::string & getOutputFileOverrideModule() const
Return the name of the module which consumed the OutputFileOverride, "" if no output file override wa...
Definition: Environment.h:126
bool getZMQDAQEnvironment() const
obtain current environment (DAQ or not)
Definition: Environment.h:325
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:390
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
Definition: Environment.h:270
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:375
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:252
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:187
std::vector< std::string > m_streamingObjects
objects to be streamed in Tx module (all if empty)
Definition: Environment.h:389
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
Definition: Environment.h:294
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
Definition: Environment.h:221
int m_zmqDAQFirstEventExp
Exp no.
Definition: Environment.h:408
bool getVisualizeDataFlow() const
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:181
Environment(const Environment &)=delete
Disable/Hide the copy constructor.
void setNumberProcessesOverride(int nproc)
Override number of processes to run in parallel.
Definition: Environment.h:132
void setZMQSocketAddress(const std::string &zmqSocketAddress)
Socket address to use in ZMQ.
Definition: Environment.h:246
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:374
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
Definition: Environment.h:380
bool m_visualizeDataFlow
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:383
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:392
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
Definition: Environment.h:402
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:382
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:215
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:381
int getZMQDAQFirstEventExp() const
get the exp number for DAQ first event
Definition: Environment.h:337
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
Definition: Environment.cc:179
void setEntrySequencesOverride(const std::vector< std::string > &sequences)
Override the number sequences (e.g.
Definition: Environment.h:69
void setZMQDAQEnvironment(bool zmqDAQ)
Set DAQ environment.
Definition: Environment.h:331
const std::vector< std::string > & getSecondaryInputFilesOverride() const
Return overriden secondary input file names, or empty vector if none were set.
Definition: Environment.h:109
bool getUseZMQ() const
Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
Definition: Environment.h:228
LogConfig::ELogRealm m_realm
The realm in which basf2 is executed.
Definition: Environment.h:394
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:282
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
Definition: Environment.h:288
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
int getZMQDAQFirstEventRun() const
get run number for DAQ first event
Definition: Environment.h:349
std::string m_picklePath
Path to the file where the pickled path is stored.
Definition: Environment.h:388
void setSecondaryInputFilesOverride(const std::vector< std::string > &names)
Override secondary input file names for modules.
Definition: Environment.h:106
std::string m_zmqSocketAddress
Socket address to use in ZMQ.
Definition: Environment.h:398
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
Definition: Environment.h:234
std::vector< std::string > m_secondaryInputFilesOverride
Override secondary input file names for input modules.
Definition: Environment.h:376
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
Definition: Environment.h:404
void setPicklePath(const std::string &path)
Sets the path to the file where the pickled path is stored.
Definition: Environment.h:158
bool getZMQRestartFailedWorkers() const
If a worker dies, restart it.
Definition: Environment.h:300
Environment & operator=(const Environment &)=delete
Disable/Hide the copy assignment operator.
void setZMQDAQFirstEventRun(int run)
set run number for DAQ first event
Definition: Environment.h:355
int getLogLevelOverride() const
Get log level override.
Definition: Environment.h:218
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:385
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:393
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
Definition: Environment.h:406
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
Definition: Environment.h:212
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:178
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:184
void setDryRun(bool dryRun)
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:189
std::string getPicklePath() const
Returns the path to the file where the pickled path is stored.
Definition: Environment.h:165
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:199
int m_run
override run for EventInfoSetter.
Definition: Environment.h:391
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
Definition: Environment.h:401
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.