Belle II Software  release-05-02-19
Environment.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2012 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Andreas Moll, Thomas Kuhr *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
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 
126  void setNumberProcessesOverride(int nproc) { m_numberProcessesOverride = nproc; }
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 
195  void printJobInformation() const;
196 
198  void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
199 
201  std::string getProfileModuleName() const { return m_profileModuleName; }
202 
204  void setLogLevelOverride(int level) { m_logLevelOverride = level; }
205 
207  int getLogLevelOverride() const { return m_logLevelOverride; }
208 
210  void setStreamingObjects(const std::vector<std::string>& strobjs) { m_streamingObjects = strobjs; }
211 
213  const std::vector<std::string>& getStreamingObjects() const { return m_streamingObjects; }
214 
215  // ZMQ Options
217  bool getUseZMQ() const
218  {
219  return m_useZMQ;
220  }
221 
223  void setUseZMQ(bool useZMQ)
224  {
225  m_useZMQ = useZMQ;
226  }
227 
229  const std::string& getZMQSocketAddress() const
230  {
232  }
233 
235  void setZMQSocketAddress(const std::string& zmqSocketAddress)
236  {
237  m_zmqSocketAddress = zmqSocketAddress;
238  }
239 
241  unsigned int getZMQMaximalWaitingTime() const
242  {
244  }
245 
247  void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
248  {
249  m_zmqMaximalWaitingTime = zmqMaximalWaitingTime;
250  }
251 
253  unsigned int getZMQEventBufferSize() const
254  {
256  }
257 
259  void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
260  {
261  m_zmqEventBufferSize = zmqEventBufferSize;
262  }
263 
265  unsigned int getZMQWorkerTimeout() const
266  {
268  }
269 
271  void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
272  {
273  m_zmqWorkerTimeout = zmqWorkerTimeout;
274  }
275 
277  bool getZMQUseEventBackup() const
278  {
280  }
281 
283  void setZMQUseEventBackup(bool zmqUseEventBackup)
284  {
285  m_zmqUseEventBackup = zmqUseEventBackup;
286  }
287 
289  bool getZMQRestartFailedWorkers() const
290  {
292  }
293 
295  void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
296  {
297  m_zmqRestartFailedWorkers = zmqRestartFailedWorkers;
298  }
299 
301  bool getZMQFailOnFailedWorkers() const
302  {
304  }
305 
307  void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
308  {
309  m_zmqFailOnFailedWorkers = zmqFailOnFailedWorkers;
310  }
311 
312  private:
313 
314  std::string m_externalsPath;
316  std::string m_steering;
317  unsigned int m_numberEventsOverride;
318  std::vector<std::string> m_inputFilesOverride;
319  std::vector<std::string>
321  std::string m_outputFileOverride;
322  std::string m_outputFileOverrideModule{""};
326  bool m_noStats;
327  bool m_dryRun;
328  std::string m_jobInfoOutput;
329  std::string m_profileModuleName;
330  std::string m_picklePath;
331  std::vector<std::string> m_streamingObjects;
332  unsigned int m_mcEvents;
333  int m_run;
335  unsigned int m_skipNEvents;
337  // ZMQ specific settings
338  bool m_useZMQ = false;
339  std::string m_zmqSocketAddress = "";
340  unsigned int m_zmqMaximalWaitingTime = 100 * 1000;
341  unsigned int m_zmqEventBufferSize = 2;
342  unsigned int m_zmqWorkerTimeout =
343  0;
344  bool m_zmqUseEventBackup = false;
345  bool m_zmqRestartFailedWorkers = false;
354 
358  Environment(const Environment&) = delete;
359 
363  Environment& operator=(const Environment&) = delete;
364 
368  ~Environment();
369 
370  };
371 
373 } //end of namespace Belle2
Belle2::Environment::setZMQEventBufferSize
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
Definition: Environment.h:267
Belle2::Environment::setJobInformation
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
Definition: Environment.cc:160
Belle2::Environment::getZMQRestartFailedWorkers
bool getZMQRestartFailedWorkers() const
If a worker dies, restart it.
Definition: Environment.h:297
Belle2::Environment::setZMQSocketAddress
void setZMQSocketAddress(const std::string &zmqSocketAddress)
Socket address to use in ZMQ.
Definition: Environment.h:243
Belle2::Environment::m_zmqWorkerTimeout
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
Definition: Environment.h:350
Belle2::Environment::getVisualizeDataFlow
bool getVisualizeDataFlow() const
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:183
Belle2::Environment::m_jobInfoOutput
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
Definition: Environment.h:336
Belle2::Environment::getPicklePath
std::string getPicklePath() const
Returns the path to the file where the pickled path is stored.
Definition: Environment.h:167
Belle2::Environment::getNumberOfMCEvents
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
Definition: Environment.h:102
Belle2::Environment::setNumberEventsOverride
void setNumberEventsOverride(unsigned int nevents)
Override the number of events in run 1 for EventInfoSetter module.
Definition: Environment.h:71
Belle2::Environment::getZMQUseEventBackup
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
Definition: Environment.h:285
Belle2::Environment::setNumberProcessesOverride
void setNumberProcessesOverride(int nproc)
Override number of processes to run in parallel.
Definition: Environment.h:134
Belle2::Environment::setProfileModuleName
void setProfileModuleName(const std::string &name)
Set the name of a module to be profiled.
Definition: Environment.h:206
Belle2::Environment::setZMQUseEventBackup
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
Definition: Environment.h:291
Belle2::Environment::m_numberProcessesOverride
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:331
Belle2::Environment::m_run
int m_run
override run for EventInfoSetter.
Definition: Environment.h:341
Belle2::Environment::setStreamingObjects
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
Definition: Environment.h:218
Belle2::Environment::setSkipEventsOverride
void setSkipEventsOverride(unsigned int skipEvents)
Set skipNEvents override.
Definition: Environment.h:94
Belle2::Environment::setZMQWorkerTimeout
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:279
Belle2::Environment::setLogLevelOverride
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:212
Belle2::Environment::getInputFilesOverride
const std::vector< std::string > & getInputFilesOverride() const
Return overriden input file names, or empty vector if none were set.
Definition: Environment.h:111
Belle2::Environment::m_numberProcesses
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:323
Belle2::Environment::m_zmqMaximalWaitingTime
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:348
Belle2::Environment::m_externalsPath
std::string m_externalsPath
The path in which the externals are located.
Definition: Environment.h:322
Belle2::Environment::getEntrySequencesOverride
std::vector< std::string > getEntrySequencesOverride() const
Returns the number sequences (e.g.
Definition: Environment.h:80
Belle2::Environment::setZMQMaximalWaitingTime
void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:255
Belle2::Environment::getDryRun
bool getDryRun() const
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:193
Belle2::Environment::setInputFilesOverride
void setInputFilesOverride(const std::vector< std::string > &names)
Override input file names for modules.
Definition: Environment.h:108
Belle2::Environment::m_skipNEvents
unsigned int m_skipNEvents
override skipNEvents for EventInfoSetter/RootInput.
Definition: Environment.h:343
Belle2::Environment::m_numberEventsOverride
unsigned int m_numberEventsOverride
Override number of events in the first run.
Definition: Environment.h:325
Belle2::Environment::setNoStats
void setNoStats(bool noStats)
Disable collection of statistics during event processing.
Definition: Environment.h:186
Belle2::Environment::isMC
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:57
Belle2::Environment::m_noStats
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:334
Belle2::Environment::m_zmqEventBufferSize
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
Definition: Environment.h:349
Belle2::Environment::getZMQFailOnFailedWorkers
bool getZMQFailOnFailedWorkers() const
If a worker dies, fail also.
Definition: Environment.h:309
Belle2::Environment::m_profileModuleName
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling requested.
Definition: Environment.h:337
Belle2::Environment::getExperimentOverride
int getExperimentOverride() const
Get experiment override, or -1 if unset.
Definition: Environment.h:91
Belle2::Environment::m_outputFileOverrideModule
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
Definition: Environment.h:330
Belle2::Environment::getZMQEventBufferSize
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
Definition: Environment.h:261
Belle2::Environment::setEntrySequencesOverride
void setEntrySequencesOverride(const std::vector< std::string > &sequences)
Override the number sequences (e.g.
Definition: Environment.h:77
Belle2::Environment::setSteering
void setSteering(const std::string &steering)
Sets the steering file content.
Definition: Environment.h:172
Belle2::Environment::setRunExperimentOverride
void setRunExperimentOverride(int run, int experiment)
Override run and experiment for EventInfoSetter.
Definition: Environment.h:86
Belle2::Environment::m_zmqFailOnFailedWorkers
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
Definition: Environment.h:354
Belle2::Environment::Environment
Environment()
Set up environment from standard BELLE2_ environment variables.
Definition: Environment.cc:82
Belle2::Environment::operator=
Environment & operator=(const Environment &)=delete
Disable/Hide the copy assignment operator.
Belle2::Environment::getRunOverride
int getRunOverride() const
Get run override, or -1 if unset.
Definition: Environment.h:89
Belle2::Environment::m_outputFileOverride
std::string m_outputFileOverride
Override name of output file for output module.
Definition: Environment.h:329
Belle2::Environment::setNumberProcesses
void setNumberProcesses(int number)
Sets the number of processes which should be used for the parallel processing.
Definition: Environment.h:142
Belle2::Environment::m_streamingObjects
std::vector< std::string > m_streamingObjects
objects to be streamed in Tx module (all if empty)
Definition: Environment.h:339
Belle2::Environment::getNumberProcesses
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
Definition: Environment.h:147
Belle2::Environment::getSkipEventsOverride
unsigned int getSkipEventsOverride() const
Get skipNEvents override, or 0 if unset.
Definition: Environment.h:96
Belle2::Environment::m_mcEvents
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:340
Belle2::Environment::consumeOutputFileOverride
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overriden output file name, or "" if none was set.
Definition: Environment.cc:64
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Environment::setUseZMQ
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
Definition: Environment.h:231
Belle2::Environment::m_picklePath
std::string m_picklePath
Path to the file where the pickled path is stored.
Definition: Environment.h:338
Belle2::Environment::~Environment
~Environment()
The Environment destructor.
Belle2::Environment::getModuleSearchPaths
const std::list< std::string > & getModuleSearchPaths() const
Returns a list of file paths searched for module libraries.
Definition: Environment.cc:37
Belle2::Environment::setZMQFailOnFailedWorkers
void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
If a worker dies, fail also.
Definition: Environment.h:315
Belle2::Environment::setPicklePath
void setPicklePath(const std::string &path)
Sets the path to the file where the pickled path is stored.
Definition: Environment.h:160
Belle2::Environment::m_experiment
int m_experiment
override experiment for EventInfoSetter.
Definition: Environment.h:342
Belle2::Environment::getSteering
const std::string & getSteering() const
Returns the steering file content.
Definition: Environment.h:177
Belle2::Environment::getZMQMaximalWaitingTime
unsigned int getZMQMaximalWaitingTime() const
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:249
Belle2::Environment::m_inputFilesOverride
std::vector< std::string > m_inputFilesOverride
Override input file names for input modules.
Definition: Environment.h:326
Belle2::Environment::getNumberOfEvents
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
Definition: Environment.cc:42
Belle2::Environment::getOutputFileOverrideModule
const std::string & getOutputFileOverrideModule() const
Return the name of the module which consumed the OutputFileOverride, "" if no output file override wa...
Definition: Environment.h:128
Belle2::Environment::getNoStats
bool getNoStats() const
Disable collection of statistics during event processing.
Definition: Environment.h:189
Belle2::Environment::m_dryRun
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:335
Belle2::Environment::getUseZMQ
bool getUseZMQ() const
Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
Definition: Environment.h:225
Belle2::Environment::setNumberOfMCEvents
void setNumberOfMCEvents(unsigned int n)
Set number of generated events (for EventInfoSetter).
Definition: Environment.h:105
Belle2::Environment
This class stores all environment information required to run the framework, such as module or data f...
Definition: Environment.h:40
Belle2::Environment::m_visualizeDataFlow
bool m_visualizeDataFlow
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:333
Belle2::Environment::setZMQRestartFailedWorkers
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
Definition: Environment.h:303
Belle2::Environment::getNumberEventsOverride
unsigned int getNumberEventsOverride() const
Returns number of events in run 1 for EventInfoSetter module, or 0 for no override.
Definition: Environment.h:74
Belle2::Environment::getZMQWorkerTimeout
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:273
Belle2::Environment::setExternalsPath
void setExternalsPath(const std::string &externalsPath)
Sets the path which points to the externals directory of the framework.
Definition: Environment.h:61
Belle2::Environment::m_zmqUseEventBackup
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
Definition: Environment.h:352
Belle2::Environment::getZMQSocketAddress
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
Definition: Environment.h:237
Belle2::Environment::m_entrySequencesOverride
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:328
Belle2::Environment::m_useZMQ
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
Definition: Environment.h:346
Belle2::Environment::Instance
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:31
Belle2::Environment::m_zmqSocketAddress
std::string m_zmqSocketAddress
Socket address to use in ZMQ.
Definition: Environment.h:347
Belle2::Environment::getStreamingObjects
const std::vector< std::string > & getStreamingObjects() const
Get list of streaming objects.
Definition: Environment.h:221
Belle2::Environment::m_zmqRestartFailedWorkers
bool m_zmqRestartFailedWorkers
If a worker dies, restart it.
Definition: Environment.h:353
Belle2::Environment::m_logLevelOverride
int m_logLevelOverride
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:332
Belle2::Environment::getProfileModuleName
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
Definition: Environment.h:209
Belle2::Environment::getOutputFileOverride
const std::string & getOutputFileOverride() const
Return overriden output file name, or "" if none was set.
Definition: Environment.h:117
Belle2::Environment::setOutputFileOverride
void setOutputFileOverride(const std::string &name)
Override output file name for modules.
Definition: Environment.h:114
Belle2::Environment::setDryRun
void setDryRun(bool dryRun)
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:191
Belle2::Environment::getExternalsPath
const std::string & getExternalsPath() const
Returns the path which points to the externals directory of the framework.
Definition: Environment.h:68
Belle2::Environment::getLogLevelOverride
int getLogLevelOverride() const
Get log level override.
Definition: Environment.h:215
Belle2::Environment::setVisualizeDataFlow
void setVisualizeDataFlow(bool on)
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:180
Belle2::Environment::printJobInformation
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
Definition: Environment.cc:180
Belle2::Environment::m_steering
std::string m_steering
The content of the steering file.
Definition: Environment.h:324