Belle II Software light-2406-ragdoll
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 <list>
15#include <string>
16#include <vector>
17#include <memory>
18
19namespace Belle2 {
24 class Path;
25
34
35 public:
36
42 static Environment& Instance();
43
47 const std::list<std::string>& getModuleSearchPaths() const;
48
54 void setExternalsPath(const std::string& externalsPath) { m_externalsPath = externalsPath; };
55
61 const std::string& getExternalsPath() const { return m_externalsPath; };
62
64 void setNumberEventsOverride(unsigned int nevents) { m_numberEventsOverride = nevents; }
65
67 unsigned int getNumberEventsOverride() const { return m_numberEventsOverride; }
68
70 void setEntrySequencesOverride(const std::vector<std::string>& sequences) { m_entrySequencesOverride = sequences; }
71
73 std::vector<std::string> getEntrySequencesOverride() const { return m_entrySequencesOverride; }
74
76 unsigned int getNumberOfEvents() const;
77
79 void setRunExperimentOverride(int run, int experiment) { m_run = run; m_experiment = experiment; }
80
82 int getRunOverride() const { return m_run; }
84 int getExperimentOverride() const { return m_experiment; }
85
87 void setSkipEventsOverride(unsigned int skipEvents) { m_skipNEvents = skipEvents; }
89 unsigned int getSkipEventsOverride() const { return m_skipNEvents; }
90
92 bool isMC() const;
93
95 void setRunType(Const::ERunType runType) { m_runType = runType; }
98
100 bool isCosmicRun() const { return (m_runType == Const::c_Cosmic); }
101
103 bool isBeamRun() const { return (m_runType == Const::c_Beam); }
104
106 unsigned int getNumberOfMCEvents() const { return m_mcEvents; }
107
109 void setNumberOfMCEvents(unsigned int n) { m_mcEvents = n; }
110
112 void setInputFilesOverride(const std::vector<std::string>& names) { m_inputFilesOverride = names; }
113
115 const std::vector<std::string>& getInputFilesOverride() const { return m_inputFilesOverride; }
116
118 void setSecondaryInputFilesOverride(const std::vector<std::string>& names) { m_secondaryInputFilesOverride = names; }
119
121 const std::vector<std::string>& getSecondaryInputFilesOverride() const { return m_secondaryInputFilesOverride; }
122
124 void setOutputFileOverride(const std::string& name) { m_outputFileOverride = name; }
125
127 const std::string& getOutputFileOverride() const { return m_outputFileOverride; }
128
134 std::string consumeOutputFileOverride(const std::string& moduleName);
135
138 const std::string& getOutputFileOverrideModule() const { return m_outputFileOverrideModule; }
139
145
152 void setNumberProcesses(int number) { m_numberProcesses = number; }
153
158 {
161 else
162 return m_numberProcesses;
163 }
164
170 void setPicklePath(const std::string& path) { m_picklePath = path; }
171
177 std::string getPicklePath() const { return m_picklePath; }
178
182 void setSteering(const std::string& steering) { m_steering = steering; };
183
187 const std::string& getSteering() const { return m_steering; };
188
191
194
196 void setNoStats(bool noStats) { m_noStats = noStats; }
197
199 bool getNoStats() const { return m_noStats; }
201 void setDryRun(bool dryRun) { m_dryRun = dryRun; }
203 bool getDryRun() const { return m_dryRun; }
204
206 void setJobInformation(const std::shared_ptr<Path>& path);
207
209 void setRealm(LogConfig::ELogRealm realm);
212
217 void setWriteSimSteps(const bool writeSimSteps) { m_writeSimSteps = writeSimSteps; }
219 bool getWriteSimSteps() const { return m_writeSimSteps; }
220
226 void printJobInformation() const;
227
229 void setProfileModuleName(const std::string& name) { m_profileModuleName = name; }
230
232 std::string getProfileModuleName() const { return m_profileModuleName; }
233
235 void setLogLevelOverride(int level) { m_logLevelOverride = level; }
236
239
241 void setStreamingObjects(const std::vector<std::string>& strobjs) { m_streamingObjects = strobjs; }
242
244 const std::vector<std::string>& getStreamingObjects() const { return m_streamingObjects; }
245
246 // ZMQ Options
248 bool getUseZMQ() const
249 {
250 return m_useZMQ;
251 }
252
254 void setUseZMQ(bool useZMQ)
255 {
256 m_useZMQ = useZMQ;
257 }
258
260 const std::string& getZMQSocketAddress() const
261 {
262 return m_zmqSocketAddress;
263 }
264
266 void setZMQSocketAddress(const std::string& zmqSocketAddress)
267 {
268 m_zmqSocketAddress = zmqSocketAddress;
269 }
270
272 unsigned int getZMQMaximalWaitingTime() const
273 {
275 }
276
278 void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
279 {
280 m_zmqMaximalWaitingTime = zmqMaximalWaitingTime;
281 }
282
284 unsigned int getZMQEventBufferSize() const
285 {
287 }
288
290 void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
291 {
292 m_zmqEventBufferSize = zmqEventBufferSize;
293 }
294
296 unsigned int getZMQWorkerTimeout() const
297 {
298 return m_zmqWorkerTimeout;
299 }
300
302 void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
303 {
304 m_zmqWorkerTimeout = zmqWorkerTimeout;
305 }
306
309 {
310 return m_zmqUseEventBackup;
311 }
312
314 void setZMQUseEventBackup(bool zmqUseEventBackup)
315 {
316 m_zmqUseEventBackup = zmqUseEventBackup;
317 }
318
321 {
323 }
324
326 void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
327 {
328 m_zmqRestartFailedWorkers = zmqRestartFailedWorkers;
329 }
330
333 {
335 }
336
338 void setZMQFailOnFailedWorkers(bool zmqFailOnFailedWorkers)
339 {
340 m_zmqFailOnFailedWorkers = zmqFailOnFailedWorkers;
341 }
342
343 // DAQ environment
346 {
347 return m_zmqDAQEnvironment;
348 }
349
351 void setZMQDAQEnvironment(bool zmqDAQ)
352 {
353 m_zmqDAQEnvironment = zmqDAQ;
354 }
355
358 {
360 }
361
364 {
366 }
367
370 {
372 }
373
376 {
378 }
379
381 bool isZMQDAQFirstEvent(int exp, int run)
382 {
383 if (exp == m_zmqDAQFirstEventExp && run == m_zmqDAQFirstEventRun)
384 return true;
385 else
386 return false;
387 }
388
389 private:
390
391 std::string m_externalsPath;
393 std::string m_steering;
395 std::vector<std::string> m_inputFilesOverride;
396 std::vector<std::string> m_secondaryInputFilesOverride;
397 std::vector<std::string>
405 bool m_dryRun;
406 std::string m_jobInfoOutput;
408 std::string m_picklePath;
409 std::vector<std::string> m_streamingObjects;
410 unsigned int m_mcEvents;
411 int m_run;
413 Const::ERunType m_runType = Const::c_Beam;
414 unsigned int m_skipNEvents;
418 // ZMQ specific settings
419 bool m_useZMQ = false;
420 std::string m_zmqSocketAddress = "";
421 unsigned int m_zmqMaximalWaitingTime = (3600 * 24) *
422 1000;
423 unsigned int m_zmqEventBufferSize = 1;
424 unsigned int m_zmqWorkerTimeout =
425 0;
429 bool m_zmqDAQEnvironment = false;
438 Environment();
439
443 Environment(const Environment&) = delete;
444
449
454
455 };
456
458} //end of namespace Belle2
ERunType
Enum for identifying run type (beam or cosmic)
Definition: Const.h:64
This class stores all environment information required to run the framework, such as module or data f...
Definition: Environment.h:33
Environment()
Set up environment from standard BELLE2_ environment variables.
Definition: Environment.cc:85
const std::vector< std::string > & getStreamingObjects() const
Get list of streaming objects.
Definition: Environment.h:244
bool m_zmqDAQEnvironment
True in DAQ environment.
Definition: Environment.h:429
int m_zmqDAQFirstEventRun
Exp no.
Definition: Environment.h:431
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:296
std::string m_steering
The content of the steering file.
Definition: Environment.h:393
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.
Definition: Environment.h:219
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:398
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:392
void setOutputFileOverride(const std::string &name)
Override output file name for modules.
Definition: Environment.h:124
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:407
void setZMQDAQFirstEventExp(int exp)
set the exp number for DAQ first event
Definition: Environment.h:363
bool isZMQDAQFirstEvent(int exp, int run)
checks the exp/run is DAQ first event
Definition: Environment.h:381
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
Definition: Environment.h:284
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
Definition: Environment.h:326
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:404
bool getDryRun() const
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:203
void setNumberProcesses(int number)
Sets the number of processes which should be used for the parallel processing.
Definition: Environment.h:152
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:338
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
Const::ERunType getRunType() const
Get the run type (beam or cosmic)
Definition: Environment.h:97
void setProfileModuleName(const std::string &name)
Set the name of a module to be profiled.
Definition: Environment.h:229
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
Definition: Environment.h:260
void setSteering(const std::string &steering)
Sets the steering file content.
Definition: Environment.h:182
const std::string & getSteering() const
Returns the steering file content.
Definition: Environment.h:187
bool getZMQFailOnFailedWorkers() const
If a worker dies, fail also.
Definition: Environment.h:332
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:54
~Environment()
The Environment destructor.
bool isCosmicRun() const
Is the run for cosmics data?
Definition: Environment.h:100
std::string m_externalsPath
The path in which the externals are located.
Definition: Environment.h:391
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
Definition: Environment.h:406
void setNumberEventsOverride(unsigned int nevents)
Override the number of events in run 1 for EventInfoSetter module.
Definition: Environment.h:64
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:427
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
Definition: Environment.h:419
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
Definition: Environment.cc:161
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:421
Const::ERunType m_runType
Flag which tells if the run is beam (default: c_Beam) or cosmic (c_Cosmic).
Definition: Environment.h:413
void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:278
unsigned int getSkipEventsOverride() const
Get skipNEvents override, or 0 if unset.
Definition: Environment.h:89
void setRunType(Const::ERunType runType)
Set the run type (beam or cosmic).
Definition: Environment.h:95
std::string m_outputFileOverride
Override name of output file for output module.
Definition: Environment.h:399
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
Definition: Environment.h:157
bool getZMQDAQEnvironment() const
obtain current environment (DAQ or not)
Definition: Environment.h:345
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:410
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
Definition: Environment.h:290
void setRunExperimentOverride(int run, int experiment)
Override run and experiment for EventInfoSetter.
Definition: Environment.h:79
std::vector< std::string > m_inputFilesOverride
Override input file names for input modules.
Definition: Environment.h:395
bool m_writeSimSteps
bool for writing out the simulation steps into a csv file.
Definition: Environment.h:416
int getExperimentOverride() const
Get experiment override, or -1 if unset.
Definition: Environment.h:84
std::vector< std::string > getEntrySequencesOverride() const
Returns the number sequences (e.g.
Definition: Environment.h:73
unsigned int getZMQMaximalWaitingTime() const
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:272
void setExternalsPath(const std::string &externalsPath)
Sets the path which points to the externals directory of the framework.
Definition: Environment.h:54
bool getNoStats() const
Disable collection of statistics during event processing.
Definition: Environment.h:199
std::vector< std::string > m_streamingObjects
objects to be streamed in Tx module (all if empty)
Definition: Environment.h:409
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
Definition: Environment.h:314
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
Definition: Environment.h:241
int m_zmqDAQFirstEventExp
Exp no.
Definition: Environment.h:430
bool getVisualizeDataFlow() const
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:193
void setWriteSimSteps(const bool writeSimSteps)
Set the flag for writing the simulation steps into an output csv file.
Definition: Environment.h:217
const std::vector< std::string > & getInputFilesOverride() const
Return overriden input file names, or empty vector if none were set.
Definition: Environment.h:115
Environment(const Environment &)=delete
Disable/Hide the copy constructor.
void setNumberProcessesOverride(int nproc)
Override number of processes to run in parallel.
Definition: Environment.h:144
void setZMQSocketAddress(const std::string &zmqSocketAddress)
Socket address to use in ZMQ.
Definition: Environment.h:266
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
Definition: Environment.h:106
unsigned int m_numberEventsOverride
Override number of events in the first run.
Definition: Environment.h:394
bool isBeamRun() const
Is the run for beam data?
Definition: Environment.h:103
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
Definition: Environment.h:400
const std::string & getOutputFileOverrideModule() const
Return the name of the module which consumed the OutputFileOverride, "" if no output file override wa...
Definition: Environment.h:138
bool m_visualizeDataFlow
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:403
int m_experiment
override experiment for EventInfoSetter.
Definition: Environment.h:412
const std::string & getOutputFileOverride() const
Return overriden output file name, or "" if none was set.
Definition: Environment.h:127
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
Definition: Environment.h:424
const std::string & getExternalsPath() const
Returns the path which points to the externals directory of the framework.
Definition: Environment.h:61
int getRunOverride() const
Get run override, or -1 if unset.
Definition: Environment.h:82
int m_logLevelOverride
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:402
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:235
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:401
int getZMQDAQFirstEventExp() const
get the exp number for DAQ first event
Definition: Environment.h:357
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
Definition: Environment.cc:181
void setEntrySequencesOverride(const std::vector< std::string > &sequences)
Override the number sequences (e.g.
Definition: Environment.h:70
void setZMQDAQEnvironment(bool zmqDAQ)
Set DAQ environment.
Definition: Environment.h:351
bool getUseZMQ() const
Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
Definition: Environment.h:248
LogConfig::ELogRealm m_realm
The realm in which basf2 is executed.
Definition: Environment.h:415
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:302
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
Definition: Environment.h:308
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:369
std::string m_picklePath
Path to the file where the pickled path is stored.
Definition: Environment.h:408
void setSecondaryInputFilesOverride(const std::vector< std::string > &names)
Override secondary input file names for modules.
Definition: Environment.h:118
std::string m_zmqSocketAddress
Socket address to use in ZMQ.
Definition: Environment.h:420
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
Definition: Environment.h:254
std::vector< std::string > m_secondaryInputFilesOverride
Override secondary input file names for input modules.
Definition: Environment.h:396
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
Definition: Environment.h:426
void setPicklePath(const std::string &path)
Sets the path to the file where the pickled path is stored.
Definition: Environment.h:170
bool getZMQRestartFailedWorkers() const
If a worker dies, restart it.
Definition: Environment.h:320
void setZMQDAQFirstEventRun(int run)
set run number for DAQ first event
Definition: Environment.h:375
int getLogLevelOverride() const
Get log level override.
Definition: Environment.h:238
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:405
unsigned int getNumberEventsOverride() const
Returns number of events in run 1 for EventInfoSetter module, or 0 for no override.
Definition: Environment.h:67
unsigned int m_skipNEvents
override skipNEvents for EventInfoSetter/RootInput.
Definition: Environment.h:414
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
Definition: Environment.h:428
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
Definition: Environment.h:232
void setSkipEventsOverride(unsigned int skipEvents)
Set skipNEvents override.
Definition: Environment.h:87
void setVisualizeDataFlow(bool on)
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:190
void setInputFilesOverride(const std::vector< std::string > &names)
Override input file names for modules.
Definition: Environment.h:112
const std::vector< std::string > & getSecondaryInputFilesOverride() const
Return overriden secondary input file names, or empty vector if none were set.
Definition: Environment.h:121
void setNoStats(bool noStats)
Disable collection of statistics during event processing.
Definition: Environment.h:196
void setDryRun(bool dryRun)
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:201
std::string getPicklePath() const
Returns the path to the file where the pickled path is stored.
Definition: Environment.h:177
void setNumberOfMCEvents(unsigned int n)
Set number of generated events (for EventInfoSetter).
Definition: Environment.h:109
LogConfig::ELogRealm getRealm() const
Get the basf2 execution realm.
Definition: Environment.h:211
int m_run
override run for EventInfoSetter.
Definition: Environment.h:411
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
Definition: Environment.h:423
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