Belle II Software development
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;
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();
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
This class stores all environment information required to run the framework, such as module or data f...
Definition: Environment.h:34
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:245
bool m_zmqDAQEnvironment
True in DAQ environment.
Definition: Environment.h:430
int m_zmqDAQFirstEventRun
Exp no.
Definition: Environment.h:432
unsigned int getZMQWorkerTimeout() const
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:297
std::string m_steering
The content of the steering file.
Definition: Environment.h:394
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:220
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:399
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:393
void setOutputFileOverride(const std::string &name)
Override output file name for modules.
Definition: Environment.h:125
std::string consumeOutputFileOverride(const std::string &moduleName)
Return overridden 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:408
void setZMQDAQFirstEventExp(int exp)
set the exp number for DAQ first event
Definition: Environment.h:364
bool isZMQDAQFirstEvent(int exp, int run)
checks the exp/run is DAQ first event
Definition: Environment.h:382
unsigned int getZMQEventBufferSize() const
Number of events to keep in flight for every worker.
Definition: Environment.h:285
void setZMQRestartFailedWorkers(bool zmqRestartFailedWorkers)
If a worker dies, restart it.
Definition: Environment.h:327
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:405
bool getDryRun() const
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:204
void setNumberProcesses(int number)
Sets the number of processes which should be used for the parallel processing.
Definition: Environment.h:153
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:339
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:98
void setProfileModuleName(const std::string &name)
Set the name of a module to be profiled.
Definition: Environment.h:230
const std::string & getZMQSocketAddress() const
Socket address to use in ZMQ.
Definition: Environment.h:261
void setSteering(const std::string &steering)
Sets the steering file content.
Definition: Environment.h:183
const std::string & getSteering() const
Returns the steering file content.
Definition: Environment.h:188
bool getZMQFailOnFailedWorkers() const
If a worker dies, fail also.
Definition: Environment.h:333
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:101
std::string m_externalsPath
The path in which the externals are located.
Definition: Environment.h:392
std::string m_jobInfoOutput
Output for printJobInformation(), generated by setJobInformation().
Definition: Environment.h:407
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.
Definition: Environment.cc:61
bool m_zmqRestartFailedWorkers
If a worker dies, restart it.
Definition: Environment.h:428
bool m_useZMQ
Set to true to use ZMQ instead of RingBuffer.
Definition: Environment.h:420
void setJobInformation(const std::shared_ptr< Path > &path)
Set info from path executed by the framework.
Definition: Environment.cc:157
unsigned int m_zmqMaximalWaitingTime
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:422
Const::ERunType m_runType
Flag which tells if the run is beam (default: c_Beam) or cosmic (c_Cosmic).
Definition: Environment.h:414
void setZMQMaximalWaitingTime(unsigned int zmqMaximalWaitingTime)
Maximal waiting time of any ZMQ module for any communication in ms.
Definition: Environment.h:279
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.
Definition: Environment.h:400
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
Definition: Environment.h:158
bool getZMQDAQEnvironment() const
obtain current environment (DAQ or not)
Definition: Environment.h:346
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:411
void setZMQEventBufferSize(unsigned int zmqEventBufferSize)
Number of events to keep in flight for every worker.
Definition: Environment.h:291
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.
Definition: Environment.h:396
bool m_writeSimSteps
bool for writing out the simulation steps into a csv file.
Definition: Environment.h:417
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.
Definition: Environment.h:273
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.
Definition: Environment.h:200
std::vector< std::string > m_streamingObjects
objects to be streamed in Tx module (all if empty)
Definition: Environment.h:410
void setZMQUseEventBackup(bool zmqUseEventBackup)
If a worker dies, store its events in a backup.
Definition: Environment.h:315
void setStreamingObjects(const std::vector< std::string > &strobjs)
Set list of streaming objects.
Definition: Environment.h:242
int m_zmqDAQFirstEventExp
Exp no.
Definition: Environment.h:431
bool getVisualizeDataFlow() const
Whether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:194
void setWriteSimSteps(const bool writeSimSteps)
Set the flag for writing the simulation steps into an output csv file.
Definition: Environment.h:218
const std::vector< std::string > & getInputFilesOverride() const
Return overridden input file names, or empty vector if none were set.
Definition: Environment.h:116
Environment(const Environment &)=delete
Disable/Hide the copy constructor.
void setNumberProcessesOverride(int nproc)
Override number of processes to run in parallel.
Definition: Environment.h:145
void setZMQSocketAddress(const std::string &zmqSocketAddress)
Socket address to use in ZMQ.
Definition: Environment.h:267
unsigned int getNumberOfMCEvents() const
Number of generated events (from EventInfoSetter).
Definition: Environment.h:107
unsigned int m_numberEventsOverride
Override number of events in the first run.
Definition: Environment.h:395
bool isBeamRun() const
Is the run for beam data?
Definition: Environment.h:104
std::string m_outputFileOverrideModule
Name of the module which consumed the output file Override if any was given.
Definition: Environment.h:401
const std::string & getOutputFileOverrideModule() const
Return the name of the module which consumed the OutputFileOverride, "" if no output file override wa...
Definition: Environment.h:139
bool m_visualizeDataFlow
Whether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:404
int m_experiment
override experiment for EventInfoSetter.
Definition: Environment.h:413
const std::string & getOutputFileOverride() const
Return overridden output file name, or "" if none was set.
Definition: Environment.h:128
unsigned int m_zmqWorkerTimeout
How long should a worker maximally need to process all of his events in the queue.
Definition: Environment.h:425
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.
Definition: Environment.h:403
void setLogLevelOverride(int level)
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:236
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:402
int getZMQDAQFirstEventExp() const
get the exp number for DAQ first event
Definition: Environment.h:358
void printJobInformation() const
Print information on input/output files in current steering file, used by –dry-run.
Definition: Environment.cc:177
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.
Definition: Environment.h:352
bool getUseZMQ() const
Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
Definition: Environment.h:249
LogConfig::ELogRealm m_realm
The realm in which basf2 is executed.
Definition: Environment.h:416
void setZMQWorkerTimeout(unsigned int zmqWorkerTimeout)
How long should a worker maximally need to process all of his events in the queue....
Definition: Environment.h:303
bool getZMQUseEventBackup() const
If a worker dies, store its events in a backup.
Definition: Environment.h:309
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:370
std::string m_picklePath
Path to the file where the pickled path is stored.
Definition: Environment.h:409
void setSecondaryInputFilesOverride(const std::vector< std::string > &names)
Override secondary input file names for modules.
Definition: Environment.h:119
std::string m_zmqSocketAddress
Socket address to use in ZMQ.
Definition: Environment.h:421
void setUseZMQ(bool useZMQ)
Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
Definition: Environment.h:255
std::vector< std::string > m_secondaryInputFilesOverride
Override secondary input file names for input modules.
Definition: Environment.h:397
bool m_zmqUseEventBackup
If a worker dies, store its events in a backup.
Definition: Environment.h:427
void setPicklePath(const std::string &path)
Sets the path to the file where the pickled path is stored.
Definition: Environment.h:171
bool getZMQRestartFailedWorkers() const
If a worker dies, restart it.
Definition: Environment.h:321
void setZMQDAQFirstEventRun(int run)
set run number for DAQ first event
Definition: Environment.h:376
int getLogLevelOverride() const
Get log level override.
Definition: Environment.h:239
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:406
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.
Definition: Environment.h:415
bool m_zmqFailOnFailedWorkers
If a worker dies, fail also.
Definition: Environment.h:429
std::string getProfileModuleName() const
Return the name of the module to be profiled, empty if no profiling was requested.
Definition: Environment.h:233
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.
Definition: Environment.h:191
void setInputFilesOverride(const std::vector< std::string > &names)
Override input file names for modules.
Definition: Environment.h:113
const std::vector< std::string > & getSecondaryInputFilesOverride() const
Return overridden secondary input file names, or empty vector if none were set.
Definition: Environment.h:122
void setNoStats(bool noStats)
Disable collection of statistics during event processing.
Definition: Environment.h:197
void setDryRun(bool dryRun)
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:202
std::string getPicklePath() const
Returns the path to the file where the pickled path is stored.
Definition: Environment.h:178
void setNumberOfMCEvents(unsigned int n)
Set number of generated events (for EventInfoSetter).
Definition: Environment.h:110
LogConfig::ELogRealm getRealm() const
Get the basf2 execution realm.
Definition: Environment.h:212
int m_run
override run for EventInfoSetter.
Definition: Environment.h:412
unsigned int m_zmqEventBufferSize
Number of events to keep in flight for every worker.
Definition: Environment.h:424
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.