Belle II Software prerelease-10-00-00a
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#include <framework/gearbox/Const.h>
13
14#include <limits>
15#include <list>
16#include <memory>
17#include <string>
18#include <vector>
19
20namespace Belle2 {
25 class Path;
26
35
36 public:
37
43 static Environment& Instance();
44
48 const std::list<std::string>& getModuleSearchPaths() const;
49
55 void setExternalsPath(const std::string& externalsPath) { m_externalsPath = externalsPath; };
56
62 const std::string& getExternalsPath() const { return m_externalsPath; };
63
65 void setNumberEventsOverride(unsigned int nevents) { m_numberEventsOverride = nevents; }
66
68 unsigned int getNumberEventsOverride() const { return m_numberEventsOverride; }
69
71 void setEntrySequencesOverride(const std::vector<std::string>& sequences) { m_entrySequencesOverride = sequences; }
72
74 std::vector<std::string> getEntrySequencesOverride() const { return m_entrySequencesOverride; }
75
77 unsigned int getNumberOfEvents() const;
78
80 void setRunExperimentOverride(int run, int experiment) { m_run = run; m_experiment = experiment; }
81
83 int getRunOverride() const { return m_run; }
85 int getExperimentOverride() const { return m_experiment; }
86
88 void setSkipEventsOverride(unsigned int skipEvents) { m_skipNEvents = skipEvents; }
90 unsigned int getSkipEventsOverride() const { return m_skipNEvents; }
91
93 bool isMC() const;
94
96 void setRunType(Const::ERunType runType) { m_runType = runType; }
99
101 bool isCosmicRun() const { return (m_runType == Const::c_Cosmic); }
102
104 bool isBeamRun() const { return (m_runType == Const::c_Beam); }
105
107 unsigned int getNumberOfMCEvents() const { return m_mcEvents; }
108
110 void setNumberOfMCEvents(unsigned int n) { m_mcEvents = n; }
111
113 void setInputFilesOverride(const std::vector<std::string>& names) { m_inputFilesOverride = names; }
114
116 const std::vector<std::string>& getInputFilesOverride() const { return m_inputFilesOverride; }
117
119 void setSecondaryInputFilesOverride(const std::vector<std::string>& names) { m_secondaryInputFilesOverride = names; }
120
122 const std::vector<std::string>& getSecondaryInputFilesOverride() const { return m_secondaryInputFilesOverride; }
123
125 void setOutputFileOverride(const std::string& name) { m_outputFileOverride = name; }
126
128 const std::string& getOutputFileOverride() const { return m_outputFileOverride; }
129
135 std::string consumeOutputFileOverride(const std::string& moduleName);
136
139 const std::string& getOutputFileOverrideModule() const { return m_outputFileOverrideModule; }
140
146
153 void setNumberProcesses(int number) { m_numberProcesses = number; }
154
159 {
162 else
163 return m_numberProcesses;
164 }
165
171 void setPicklePath(const std::string& path) { m_picklePath = path; }
172
178 std::string getPicklePath() const { return m_picklePath; }
179
183 void setSteering(const std::string& steering) { m_steering = steering; };
184
188 const std::string& getSteering() const { return m_steering; };
189
192
195
197 void setNoStats(bool noStats) { m_noStats = noStats; }
198
200 bool getNoStats() const { return m_noStats; }
202 void setDryRun(bool dryRun) { m_dryRun = dryRun; }
204 bool getDryRun() const { return m_dryRun; }
205
207 void setJobInformation(const std::shared_ptr<Path>& path);
208
210 void setRealm(LogConfig::ELogRealm realm);
213
218 void setWriteSimSteps(const bool writeSimSteps) { m_writeSimSteps = writeSimSteps; }
220 bool getWriteSimSteps() const { return m_writeSimSteps; }
221
227 void printJobInformation() const;
228
230 void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
231
233 std::string getProfileModuleName() const { return m_profileModuleName; }
234
236 void setLogLevelOverride(int level) { m_logLevelOverride = level; }
237
240
242 void setStreamingObjects(const std::vector<std::string>& strobjs) { m_streamingObjects = strobjs; }
243
245 const std::vector<std::string>& getStreamingObjects() const { return m_streamingObjects; }
246
247 // ZMQ Options
249 bool getUseZMQ() const
250 {
251 return m_useZMQ;
252 }
253
255 void setUseZMQ(bool useZMQ)
256 {
257 m_useZMQ = useZMQ;
258 }
259
261 const std::string& getZMQSocketAddress() const
262 {
263 return m_zmqSocketAddress;
264 }
265
267 void setZMQSocketAddress(const std::string& zmqSocketAddress)
268 {
269 m_zmqSocketAddress = zmqSocketAddress;
270 }
271
273 unsigned int getZMQMaximalWaitingTime() const
274 {
276 }
277
279 void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
280 {
281 m_zmqMaximalWaitingTime = zmqMaximalWaitingTime;
282 }
283
285 unsigned int getZMQEventBufferSize() const
286 {
288 }
289
291 void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
292 {
293 m_zmqEventBufferSize = zmqEventBufferSize;
294 }
295
297 unsigned int getZMQWorkerTimeout() const
298 {
299 return m_zmqWorkerTimeout;
300 }
301
303 void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
304 {
305 m_zmqWorkerTimeout = zmqWorkerTimeout;
306 }
307
310 {
311 return m_zmqUseEventBackup;
312 }
313
315 void setZMQUseEventBackup(bool zmqUseEventBackup)
316 {
317 m_zmqUseEventBackup = zmqUseEventBackup;
318 }
319
322 {
324 }
325
327 void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
328 {
329 m_zmqRestartFailedWorkers = zmqRestartFailedWorkers;
330 }
331
334 {
336 }
337
339 void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
340 {
341 m_zmqFailOnFailedWorkers = zmqFailOnFailedWorkers;
342 }
343
344 // DAQ environment
347 {
348 return m_zmqDAQEnvironment;
349 }
350
352 void setZMQDAQEnvironment(bool zmqDAQ)
353 {
354 m_zmqDAQEnvironment = zmqDAQ;
355 }
356
359 {
361 }
362
365 {
367 }
368
371 {
373 }
374
377 {
379 }
380
382 bool isZMQDAQFirstEvent(int exp, int run)
383 {
384 if (exp == m_zmqDAQFirstEventExp && run == m_zmqDAQFirstEventRun)
385 return true;
386 else
387 return false;
388 }
389
390 private:
391
392 std::string m_externalsPath;
394 std::string m_steering;
396 std::vector<std::string> m_inputFilesOverride;
397 std::vector<std::string> m_secondaryInputFilesOverride;
398 std::vector<std::string>
406 bool m_dryRun;
407 std::string m_jobInfoOutput;
409 std::string m_picklePath;
410 std::vector<std::string> m_streamingObjects;
411 unsigned int m_mcEvents;
412 int m_run;
414 Const::ERunType m_runType = Const::c_Beam;
415 unsigned int m_skipNEvents;
418
419 // ZMQ specific settings
420 bool m_useZMQ = false;
421 std::string m_zmqSocketAddress = "";
422 unsigned int m_zmqMaximalWaitingTime = (3600 * 24) *
423 1000;
424 unsigned int m_zmqEventBufferSize = 1;
425 unsigned int m_zmqWorkerTimeout =
426 0;
430 bool m_zmqDAQEnvironment = false;
431 int m_zmqDAQFirstEventExp = std::numeric_limits<int>::max();
432 int m_zmqDAQFirstEventRun = std::numeric_limits<int>::max();
433
439 Environment();
440
444 Environment(const Environment&) = delete;
445
450
455
456 };
457
459} //end of namespace Belle2
ERunType
Enum for identifying run type (beam or cosmic)
Definition Const.h:64
Environment()
Set up environment from standard BELLE2_ environment variables.
const std::vector< std::string > & getStreamingObjects() const
Get list of streaming objects.
bool m_zmqDAQEnvironment
True in DAQ environment.
int m_zmqDAQFirstEventRun
Exp no.
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
std::string m_steering
The content of the steering file.
Environment & operator=(const Environment &)=delete
Disable/Hide the copy assignment operator.
bool getWriteSimSteps() const
Get the flag for writing the simulation steps into an output csv file.
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
void setOutputFileOverride(const std::string &name)
Override output file name for modules.
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overridden output file name, or "" if none was set.
std::string m_profileModuleName
Name of the module which should be profiled, empty if no profiling requested.
void setZMQDAQFirstEventExp(int exp)
set the exp number for DAQ first event
bool isZMQDAQFirstEvent(int exp, int run)
checks the exp/run is DAQ first event
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
bool m_noStats
Disable collection of statistics during event processing.
bool getDryRun() const
Read steering file, but do not start any actually start any event processing.
void setNumberProcesses(int number)
Sets the number of processes which should be used for the parallel processing.
const std::list< std::string > & getModuleSearchPaths() const
Returns a list of file paths searched for module libraries.
void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
If a worker dies, fail also.
unsigned int getNumberOfEvents() const
Return the number of events, from either input or EventInfoSetter, or -n command line override (if le...
Const::ERunType getRunType() const
Get the run type (beam or cosmic)
Definition Environment.h:98
void setProfileModuleName(const std::string &name)
Set the name of a module to be profiled.
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
void setSteering(const std::string &steering)
Sets the steering file content.
const std::string & getSteering() const
Returns the steering file content.
bool getZMQFailOnFailedWorkers() const
If a worker dies, fail also.
bool isMC() const
Do we have generated, not real data?
~Environment()
The Environment destructor.
bool isCosmicRun() const
Is the run for cosmics data?
std::string m_externalsPath
The path in which the externals are located.
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
void setNumberEventsOverride(unsigned int nevents)
Override the number of events in run 1 for EventInfoSetter module.
Definition Environment.h:65
void setRealm(LogConfig::ELogRealm realm)
Set the basf2 execution realm.
bool m_zmqRestartFailedWorkers
If a worker dies, restart it.
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Const::ERunType m_runType
Flag which tells if the run is beam (default: c_Beam) or cosmic (c_Cosmic).
void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
Maximal waiting time of any ZMQ module for any communication in ms.
unsigned int getSkipEventsOverride() const
Get skipNEvents override, or 0 if unset.
Definition Environment.h:90
void setRunType(Const::ERunType runType)
Set the run type (beam or cosmic).
Definition Environment.h:96
std::string m_outputFileOverride
Override name of output file for output module.
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
bool getZMQDAQEnvironment() const
obtain current environment (DAQ or not)
unsigned int m_mcEvents
counter for number of generated events.
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
void setRunExperimentOverride(int run, int experiment)
Override run and experiment for EventInfoSetter.
Definition Environment.h:80
std::vector< std::string > m_inputFilesOverride
Override input file names for input modules.
bool m_writeSimSteps
bool for writing out the simulation steps into a csv file.
int getExperimentOverride() const
Get experiment override, or -1 if unset.
Definition Environment.h:85
std::vector< std::string > getEntrySequencesOverride() const
Returns the number sequences (e.g.
Definition Environment.h:74
unsigned int getZMQMaximalWaitingTime() const
Maximal waiting time of any ZMQ module for any communication in ms.
void setExternalsPath(const std::string &externalsPath)
Sets the path which points to the externals directory of the framework.
Definition Environment.h:55
bool getNoStats() const
Disable collection of statistics during event processing.
std::vector< std::string > m_streamingObjects
objects to be streamed in Tx module (all if empty)
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
int m_zmqDAQFirstEventExp
Exp no.
bool getVisualizeDataFlow() const
Whether to generate DOT files with data store inputs/outputs of each module.
void setWriteSimSteps(const bool writeSimSteps)
Set the flag for writing the simulation steps into an output csv file.
const std::vector< std::string > & getInputFilesOverride() const
Return overridden input file names, or empty vector if none were set.
Environment(const Environment &)=delete
Disable/Hide the copy constructor.
void setNumberProcessesOverride(int nproc)
Override number of processes to run in parallel.
void setZMQSocketAddress(const std::string &zmqSocketAddress)
Socket address to use in ZMQ.
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
unsigned int m_numberEventsOverride
Override number of events in the first run.
bool isBeamRun() const
Is the run for beam data?
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
const std::string & getOutputFileOverrideModule() const
Return the name of the module which consumed the OutputFileOverride, "" if no output file override wa...
bool m_visualizeDataFlow
Whether to generate DOT files with data store inputs/outputs of each module.
int m_experiment
override experiment for EventInfoSetter.
const std::string & getOutputFileOverride() const
Return overridden output file name, or "" if none was set.
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
const std::string & getExternalsPath() const
Returns the path which points to the externals directory of the framework.
Definition Environment.h:62
int getRunOverride() const
Get run override, or -1 if unset.
Definition Environment.h:83
int m_logLevelOverride
Override global log level if != LogConfig::c_Default.
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
int getZMQDAQFirstEventExp() const
get the exp number for DAQ first event
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
void setEntrySequencesOverride(const std::vector< std::string > &sequences)
Override the number sequences (e.g.
Definition Environment.h:71
void setZMQDAQEnvironment(bool zmqDAQ)
Set DAQ environment.
bool getUseZMQ() const
Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
LogConfig::ELogRealm m_realm
The realm in which basf2 is executed.
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
static Environment & Instance()
Static method to get a reference to the Environment instance.
int getZMQDAQFirstEventRun() const
get run number for DAQ first event
std::string m_picklePath
Path to the file where the pickled path is stored.
void setSecondaryInputFilesOverride(const std::vector< std::string > &names)
Override secondary input file names for modules.
std::string m_zmqSocketAddress
Socket address to use in ZMQ.
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
std::vector< std::string > m_secondaryInputFilesOverride
Override secondary input file names for input modules.
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
void setPicklePath(const std::string &path)
Sets the path to the file where the pickled path is stored.
bool getZMQRestartFailedWorkers() const
If a worker dies, restart it.
void setZMQDAQFirstEventRun(int run)
set run number for DAQ first event
int getLogLevelOverride() const
Get log level override.
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
unsigned int getNumberEventsOverride() const
Returns number of events in run 1 for EventInfoSetter module, or 0 for no override.
Definition Environment.h:68
unsigned int m_skipNEvents
override skipNEvents for EventInfoSetter/RootInput.
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
void setSkipEventsOverride(unsigned int skipEvents)
Set skipNEvents override.
Definition Environment.h:88
void setVisualizeDataFlow(bool on)
Whether to generate DOT files with data store inputs/outputs of each module.
void setInputFilesOverride(const std::vector< std::string > &names)
Override input file names for modules.
const std::vector< std::string > & getSecondaryInputFilesOverride() const
Return overridden secondary input file names, or empty vector if none were set.
void setNoStats(bool noStats)
Disable collection of statistics during event processing.
void setDryRun(bool dryRun)
Read steering file, but do not start any actually start any event processing.
std::string getPicklePath() const
Returns the path to the file where the pickled path is stored.
void setNumberOfMCEvents(unsigned int n)
Set number of generated events (for EventInfoSetter).
LogConfig::ELogRealm getRealm() const
Get the basf2 execution realm.
int m_run
override run for EventInfoSetter.
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
ELogRealm
Definition of the supported execution realms.
Definition LogConfig.h:48
@ c_None
No specific realm.
Definition LogConfig.h:48
Implements a path consisting of Module and/or Path objects.
Definition Path.h:38
Abstract base class for different kinds of events.