Belle II Software  light-2403-persian
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 
205  void setWriteSimSteps(const bool writeSimSteps) { m_writeSimSteps = writeSimSteps; }
207  bool getWriteSimSteps() const { return m_writeSimSteps; }
208 
214  void printJobInformation() const;
215 
217  void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
218 
220  std::string getProfileModuleName() const { return m_profileModuleName; }
221 
223  void setLogLevelOverride(int level) { m_logLevelOverride = level; }
224 
226  int getLogLevelOverride() const { return m_logLevelOverride; }
227 
229  void setStreamingObjects(const std::vector<std::string>& strobjs) { m_streamingObjects = strobjs; }
230 
232  const std::vector<std::string>& getStreamingObjects() const { return m_streamingObjects; }
233 
234  // ZMQ Options
236  bool getUseZMQ() const
237  {
238  return m_useZMQ;
239  }
240 
242  void setUseZMQ(bool useZMQ)
243  {
244  m_useZMQ = useZMQ;
245  }
246 
248  const std::string& getZMQSocketAddress() const
249  {
250  return m_zmqSocketAddress;
251  }
252 
254  void setZMQSocketAddress(const std::string& zmqSocketAddress)
255  {
256  m_zmqSocketAddress = zmqSocketAddress;
257  }
258 
260  unsigned int getZMQMaximalWaitingTime() const
261  {
263  }
264 
266  void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
267  {
268  m_zmqMaximalWaitingTime = zmqMaximalWaitingTime;
269  }
270 
272  unsigned int getZMQEventBufferSize() const
273  {
274  return m_zmqEventBufferSize;
275  }
276 
278  void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
279  {
280  m_zmqEventBufferSize = zmqEventBufferSize;
281  }
282 
284  unsigned int getZMQWorkerTimeout() const
285  {
286  return m_zmqWorkerTimeout;
287  }
288 
290  void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
291  {
292  m_zmqWorkerTimeout = zmqWorkerTimeout;
293  }
294 
296  bool getZMQUseEventBackup() const
297  {
298  return m_zmqUseEventBackup;
299  }
300 
302  void setZMQUseEventBackup(bool zmqUseEventBackup)
303  {
304  m_zmqUseEventBackup = zmqUseEventBackup;
305  }
306 
309  {
311  }
312 
314  void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
315  {
316  m_zmqRestartFailedWorkers = zmqRestartFailedWorkers;
317  }
318 
321  {
323  }
324 
326  void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
327  {
328  m_zmqFailOnFailedWorkers = zmqFailOnFailedWorkers;
329  }
330 
331  // DAQ environment
333  bool getZMQDAQEnvironment() const
334  {
335  return m_zmqDAQEnvironment;
336  }
337 
339  void setZMQDAQEnvironment(bool zmqDAQ)
340  {
341  m_zmqDAQEnvironment = zmqDAQ;
342  }
343 
346  {
347  return m_zmqDAQFirstEventExp;
348  }
349 
352  {
353  m_zmqDAQFirstEventExp = exp;
354  }
355 
358  {
359  return m_zmqDAQFirstEventRun;
360  }
361 
364  {
365  m_zmqDAQFirstEventRun = run;
366  }
367 
369  bool isZMQDAQFirstEvent(int exp, int run)
370  {
371  if (exp == m_zmqDAQFirstEventExp && run == m_zmqDAQFirstEventRun)
372  return true;
373  else
374  return false;
375  }
376 
377  private:
378 
379  std::string m_externalsPath;
381  std::string m_steering;
382  unsigned int m_numberEventsOverride;
383  std::vector<std::string> m_inputFilesOverride;
384  std::vector<std::string> m_secondaryInputFilesOverride;
385  std::vector<std::string>
387  std::string m_outputFileOverride;
388  std::string m_outputFileOverrideModule{""};
392  bool m_noStats;
393  bool m_dryRun;
394  std::string m_jobInfoOutput;
395  std::string m_profileModuleName;
396  std::string m_picklePath;
397  std::vector<std::string> m_streamingObjects;
398  unsigned int m_mcEvents;
399  int m_run;
401  unsigned int m_skipNEvents;
405  // ZMQ specific settings
406  bool m_useZMQ = false;
407  std::string m_zmqSocketAddress = "";
408  unsigned int m_zmqMaximalWaitingTime = (3600 * 24) *
409  1000;
410  unsigned int m_zmqEventBufferSize = 1;
411  unsigned int m_zmqWorkerTimeout =
412  0;
413  bool m_zmqUseEventBackup = true;
416  bool m_zmqDAQEnvironment = false;
425  Environment();
426 
430  Environment(const Environment&) = delete;
431 
435  Environment& operator=(const Environment&) = delete;
436 
441 
442  };
443 
445 } //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:416
int m_zmqDAQFirstEventRun
Exp no.
Definition: Environment.h:418
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:284
std::string m_steering
The content of the steering file.
Definition: Environment.h:381
bool getWriteSimSteps() const
Get the flag for writing the simulation steps into an output csv file.
Definition: Environment.h:207
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
Definition: Environment.h:248
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:386
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:380
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:395
void setZMQDAQFirstEventExp(int exp)
set the exp number for DAQ first event
Definition: Environment.h:351
bool isZMQDAQFirstEvent(int exp, int run)
checks the exp/run is DAQ first event
Definition: Environment.h:369
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
Definition: Environment.h:272
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
Definition: Environment.h:314
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:392
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:326
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:217
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:320
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:232
std::string m_externalsPath
The path in which the externals are located.
Definition: Environment.h:379
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
Definition: Environment.h:394
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:414
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
Definition: Environment.h:406
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
Definition: Environment.cc:160
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:408
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:266
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:387
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:333
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:398
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
Definition: Environment.h:278
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:383
bool m_writeSimSteps
bool for writing out the simulation steps into a csv file.
Definition: Environment.h:403
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:260
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:397
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
Definition: Environment.h:302
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
Definition: Environment.h:229
int m_zmqDAQFirstEventExp
Exp no.
Definition: Environment.h:417
bool getVisualizeDataFlow() const
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:181
void setWriteSimSteps(const bool writeSimSteps)
Set the flag for writing the simulation steps into an output csv file.
Definition: Environment.h:205
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:254
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:382
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
Definition: Environment.h:388
bool m_visualizeDataFlow
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:391
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:400
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
Definition: Environment.h:411
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:390
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:223
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:389
int getZMQDAQFirstEventExp() const
get the exp number for DAQ first event
Definition: Environment.h:345
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
Definition: Environment.cc:180
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:339
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:236
LogConfig::ELogRealm m_realm
The realm in which basf2 is executed.
Definition: Environment.h:402
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:290
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
Definition: Environment.h:296
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:357
std::string m_picklePath
Path to the file where the pickled path is stored.
Definition: Environment.h:396
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:407
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
Definition: Environment.h:242
std::vector< std::string > m_secondaryInputFilesOverride
Override secondary input file names for input modules.
Definition: Environment.h:384
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
Definition: Environment.h:413
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:308
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:363
int getLogLevelOverride() const
Get log level override.
Definition: Environment.h:226
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:393
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:401
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
Definition: Environment.h:415
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
Definition: Environment.h:220
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:399
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
Definition: Environment.h:410
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.
Definition: ClusterUtils.h:24