Belle II Software  release-08-01-10
Environment Class Reference

This class stores all environment information required to run the framework, such as module or data filepaths, number of processes to be used in parallel processing etc. More...

#include <Environment.h>

Collaboration diagram for Environment:

Public Member Functions

const std::list< std::string > & getModuleSearchPaths () const
 Returns a list of file paths searched for module libraries.
 
void setExternalsPath (const std::string &externalsPath)
 Sets the path which points to the externals directory of the framework. More...
 
const std::string & getExternalsPath () const
 Returns the path which points to the externals directory of the framework. More...
 
void setNumberEventsOverride (unsigned int nevents)
 Override the number of events in run 1 for EventInfoSetter module.
 
unsigned int getNumberEventsOverride () const
 Returns number of events in run 1 for EventInfoSetter module, or 0 for no override.
 
void setEntrySequencesOverride (const std::vector< std::string > &sequences)
 Override the number sequences (e.g. More...
 
std::vector< std::string > getEntrySequencesOverride () const
 Returns the number sequences (e.g. More...
 
unsigned int getNumberOfEvents () const
 Return the number of events, from either input or EventInfoSetter, or -n command line override (if less).
 
void setRunExperimentOverride (int run, int experiment)
 Override run and experiment for EventInfoSetter.
 
int getRunOverride () const
 Get run override, or -1 if unset.
 
int getExperimentOverride () const
 Get experiment override, or -1 if unset.
 
void setSkipEventsOverride (unsigned int skipEvents)
 Set skipNEvents override.
 
unsigned int getSkipEventsOverride () const
 Get skipNEvents override, or 0 if unset.
 
bool isMC () const
 Do we have generated, not real data?
 
unsigned int getNumberOfMCEvents () const
 Number of generated events (from EventInfoSetter).
 
void setNumberOfMCEvents (unsigned int n)
 Set number of generated events (for EventInfoSetter).
 
void setInputFilesOverride (const std::vector< std::string > &names)
 Override input file names for modules.
 
const std::vector< std::string > & getInputFilesOverride () const
 Return overriden input file names, or empty vector if none were set.
 
void setSecondaryInputFilesOverride (const std::vector< std::string > &names)
 Override secondary input file names for modules.
 
const std::vector< std::string > & getSecondaryInputFilesOverride () const
 Return overriden secondary input file names, or empty vector if none were set.
 
void setOutputFileOverride (const std::string &name)
 Override output file name for modules.
 
const std::string & getOutputFileOverride () const
 Return overriden output file name, or "" if none was set.
 
std::string consumeOutputFileOverride (const std::string &moduleName)
 Return overriden output file name, or "" if none was set. More...
 
const std::string & getOutputFileOverrideModule () const
 Return the name of the module which consumed the OutputFileOverride, "" if no output file override was set or no other module consumed it.
 
void setNumberProcessesOverride (int nproc)
 Override number of processes to run in parallel. More...
 
void setNumberProcesses (int number)
 Sets the number of processes which should be used for the parallel processing. More...
 
int getNumberProcesses () const
 Returns the number of worker processes which should be used for the parallel processing.
 
void setPicklePath (const std::string &path)
 Sets the path to the file where the pickled path is stored. More...
 
std::string getPicklePath () const
 Returns the path to the file where the pickled path is stored. More...
 
void setSteering (const std::string &steering)
 Sets the steering file content.
 
const std::string & getSteering () const
 Returns the steering file content.
 
void setVisualizeDataFlow (bool on)
 Wether to generate DOT files with data store inputs/outputs of each module.
 
bool getVisualizeDataFlow () const
 Wether to generate DOT files with data store inputs/outputs of each module.
 
void setNoStats (bool noStats)
 Disable collection of statistics during event processing.
 
bool getNoStats () const
 Disable collection of statistics during event processing.
 
void setDryRun (bool dryRun)
 Read steering file, but do not start any actually start any event processing. More...
 
bool getDryRun () const
 Read steering file, but do not start any actually start any event processing. More...
 
void setJobInformation (const std::shared_ptr< Path > &path)
 Set info from path executed by the framework.
 
void setRealm (LogConfig::ELogRealm realm)
 Set the basf2 execution realm.
 
LogConfig::ELogRealm getRealm () const
 Get the basf2 execution realm.
 
void printJobInformation () const
 Print information on input/output files in current steering file, used by –dry-run. More...
 
void setProfileModuleName (const std::string &name)
 Set the name of a module to be profiled.
 
std::string getProfileModuleName () const
 Return the name of the module to be profiled, empty if no profiling was requested.
 
void setLogLevelOverride (int level)
 Override global log level if != LogConfig::c_Default.
 
int getLogLevelOverride () const
 Get log level override.
 
void setStreamingObjects (const std::vector< std::string > &strobjs)
 Set list of streaming objects.
 
const std::vector< std::string > & getStreamingObjects () const
 Get list of streaming objects.
 
bool getUseZMQ () const
 Flag if ZMQ should be used instead of the RingBuffer multiprocesing implementation.
 
void setUseZMQ (bool useZMQ)
 Set the flag if ZMQ should be used instead of the RingBuffer multiprocessing implementation.
 
const std::string & getZMQSocketAddress () const
 Socket address to use in ZMQ.
 
void setZMQSocketAddress (const std::string &zmqSocketAddress)
 Socket address to use in ZMQ.
 
unsigned int getZMQMaximalWaitingTime () const
 Maximal waiting time of any ZMQ module for any communication in ms.
 
void setZMQMaximalWaitingTime (unsigned int zmqMaximalWaitingTime)
 Maximal waiting time of any ZMQ module for any communication in ms.
 
unsigned int getZMQEventBufferSize () const
 Number of events to keep in flight for every worker.
 
void setZMQEventBufferSize (unsigned int zmqEventBufferSize)
 Number of events to keep in flight for every worker.
 
unsigned int getZMQWorkerTimeout () const
 How long should a worker maximally need to process all of his events in the queue. Set to 0 to disable the check.
 
void setZMQWorkerTimeout (unsigned int zmqWorkerTimeout)
 How long should a worker maximally need to process all of his events in the queue. Set to 0 to disable the check.
 
bool getZMQUseEventBackup () const
 If a worker dies, store its events in a backup.
 
void setZMQUseEventBackup (bool zmqUseEventBackup)
 If a worker dies, store its events in a backup.
 
bool getZMQRestartFailedWorkers () const
 If a worker dies, restart it.
 
void setZMQRestartFailedWorkers (bool zmqRestartFailedWorkers)
 If a worker dies, restart it.
 
bool getZMQFailOnFailedWorkers () const
 If a worker dies, fail also.
 
void setZMQFailOnFailedWorkers (bool zmqFailOnFailedWorkers)
 If a worker dies, fail also.
 
bool getZMQDAQEnvironment () const
 obtain current environment (DAQ or not)
 
void setZMQDAQEnvironment (bool zmqDAQ)
 Set DAQ environment.
 
int getZMQDAQFirstEventExp () const
 get the exp number for DAQ first event
 
void setZMQDAQFirstEventExp (int exp)
 set the exp number for DAQ first event
 
int getZMQDAQFirstEventRun () const
 get run number for DAQ first event
 
void setZMQDAQFirstEventRun (int run)
 set run number for DAQ first event
 
bool isZMQDAQFirstEvent (int exp, int run)
 checks the exp/run is DAQ first event
 

Static Public Member Functions

static EnvironmentInstance ()
 Static method to get a reference to the Environment instance. More...
 

Private Member Functions

 Environment ()
 Set up environment from standard BELLE2_ environment variables. More...
 
 Environment (const Environment &)=delete
 Disable/Hide the copy constructor.
 
Environmentoperator= (const Environment &)=delete
 Disable/Hide the copy assignment operator.
 
 ~Environment ()
 The Environment destructor.
 

Private Attributes

std::string m_externalsPath
 The path in which the externals are located.
 
int m_numberProcesses
 The number of worker processes that should be used for the parallel processing.
 
std::string m_steering
 The content of the steering file.
 
unsigned int m_numberEventsOverride
 Override number of events in the first run.
 
std::vector< std::string > m_inputFilesOverride
 Override input file names for input modules.
 
std::vector< std::string > m_secondaryInputFilesOverride
 Override secondary input file names for input modules.
 
std::vector< std::string > m_entrySequencesOverride
 A number sequence (e.g. More...
 
std::string m_outputFileOverride
 Override name of output file for output module.
 
std::string m_outputFileOverrideModule {""}
 Name of the module which consumed the output file Override if any was given.
 
int m_numberProcessesOverride
 Override m_numberProcesses if >= 0.
 
int m_logLevelOverride
 Override global log level if != LogConfig::c_Default.
 
bool m_visualizeDataFlow
 Wether to generate DOT files with data store inputs/outputs of each module.
 
bool m_noStats
 Disable collection of statistics during event processing. More...
 
bool m_dryRun
 Read steering file, but do not start any actually start any event processing. More...
 
std::string m_jobInfoOutput
 Output for printJobInformation(), generated by setJobInformation().
 
std::string m_profileModuleName
 Name of the module which should be profiled, empty if no profiling requested.
 
std::string m_picklePath
 Path to the file where the pickled path is stored.
 
std::vector< std::string > m_streamingObjects
 objects to be streamed in Tx module (all if empty)
 
unsigned int m_mcEvents
 counter for number of generated events.
 
int m_run
 override run for EventInfoSetter.
 
int m_experiment
 override experiment for EventInfoSetter.
 
unsigned int m_skipNEvents
 override skipNEvents for EventInfoSetter/RootInput.
 
LogConfig::ELogRealm m_realm = LogConfig::c_None
 The realm in which basf2 is executed.
 
bool m_useZMQ = false
 Set to true to use ZMQ instead of RingBuffer.
 
std::string m_zmqSocketAddress = ""
 Socket address to use in ZMQ. More...
 
unsigned int m_zmqMaximalWaitingTime
 Maximal waiting time of any ZMQ module for any communication in ms. More...
 
unsigned int m_zmqEventBufferSize = 1
 Number of events to keep in flight for every worker.
 
unsigned int m_zmqWorkerTimeout
 How long should a worker maximally need to process all of his events in the queue. More...
 
bool m_zmqUseEventBackup = true
 If a worker dies, store its events in a backup.
 
bool m_zmqRestartFailedWorkers = true
 If a worker dies, restart it.
 
bool m_zmqFailOnFailedWorkers = true
 If a worker dies, fail also. More...
 
bool m_zmqDAQEnvironment = false
 True in DAQ environment.
 
int m_zmqDAQFirstEventExp = 42
 Exp no. More...
 
int m_zmqDAQFirstEventRun = 8
 Exp no. More...
 

Detailed Description

This class stores all environment information required to run the framework, such as module or data filepaths, number of processes to be used in parallel processing etc.

Usually, this information is set by the steering file.

This class is designed as a singleton.

Definition at line 32 of file Environment.h.

Constructor & Destructor Documentation

◆ Environment()

Environment ( )
private

Set up environment from standard BELLE2_ environment variables.

Ends with B2FATAL if something goes wrong.

Definition at line 85 of file Environment.cc.

85  :
87  m_steering(""),
95  m_visualizeDataFlow(false),
96  m_noStats(false),
97  m_dryRun(false),
98  m_mcEvents(0),
99  m_run(-1),
100  m_experiment(-1),
101  m_skipNEvents(0)
102 {
103  // Check for environment variables set by setuprel
104  const char* envarReleaseDir = getenv("BELLE2_RELEASE_DIR");
105  const char* envarLocalDir = getenv("BELLE2_LOCAL_DIR");
106  const char* envarAnalysisDir = getenv("BELLE2_ANALYSIS_DIR");
107  if (!envarReleaseDir and !envarLocalDir) {
108  B2FATAL("The basf2 environment is not set up. Please execute the 'setuprel' script first.");
109  }
110 
111  //also set when just sourcing setup_belle2.sh (which is why we also check for local/release dir)
112  const char* envarSubDir = getenv("BELLE2_SUBDIR");
113  if (!envarSubDir) {
114  B2FATAL("The environment variable BELLE2_SUBDIR is not set. Please execute the 'setuprel' script first.");
115  }
116 
117  const char* envarExtDir = getenv("BELLE2_EXTERNALS_DIR");
118  if (!envarExtDir) {
119  B2FATAL("The environment variable BELLE2_EXTERNALS_DIR is not set. Please execute the 'setuprel' script first.");
120  }
121 
122  // add module directories for current build options, starting with the working directory on program startup
123  std::string added_dirs = fs::current_path().string();
125 
126  if (envarAnalysisDir) {
127  const string analysisModules = (fs::path(envarAnalysisDir) / "modules" / envarSubDir).string();
128  ModuleManager::Instance().addModuleSearchPath(analysisModules);
129  added_dirs += " " + analysisModules;
130  }
131 
132  if (envarLocalDir) {
133  const string localModules = (fs::path(envarLocalDir) / "modules" / envarSubDir).string();
135  added_dirs += " " + localModules;
136  }
137 
138  if (envarReleaseDir) {
139  const string centralModules = (fs::path(envarReleaseDir) / "modules" / envarSubDir).string();
141  added_dirs += " " + centralModules;
142  }
143 
144  if (ModuleManager::Instance().getAvailableModules().empty()) {
145  B2ERROR("No modules found! Did you forget to run 'scons'? Module paths added: " << added_dirs);
146  }
147 
148  //set path to external software
149  setExternalsPath(envarExtDir);
150 }
std::string m_steering
The content of the steering file.
Definition: Environment.h:373
std::vector< std::string > m_entrySequencesOverride
A number sequence (e.g.
Definition: Environment.h:378
int m_numberProcesses
The number of worker processes that should be used for the parallel processing.
Definition: Environment.h:372
bool m_noStats
Disable collection of statistics during event processing.
Definition: Environment.h:384
std::string m_outputFileOverride
Override name of output file for output module.
Definition: Environment.h:379
unsigned int m_mcEvents
counter for number of generated events.
Definition: Environment.h:390
std::vector< std::string > m_inputFilesOverride
Override input file names for input modules.
Definition: Environment.h:375
void setExternalsPath(const std::string &externalsPath)
Sets the path which points to the externals directory of the framework.
Definition: Environment.h:53
unsigned int m_numberEventsOverride
Override number of events in the first run.
Definition: Environment.h:374
bool m_visualizeDataFlow
Wether to generate DOT files with data store inputs/outputs of each module.
Definition: Environment.h:383
int m_experiment
override experiment for EventInfoSetter.
Definition: Environment.h:392
int m_logLevelOverride
Override global log level if != LogConfig::c_Default.
Definition: Environment.h:382
int m_numberProcessesOverride
Override m_numberProcesses if >= 0.
Definition: Environment.h:381
std::vector< std::string > m_secondaryInputFilesOverride
Override secondary input file names for input modules.
Definition: Environment.h:376
bool m_dryRun
Read steering file, but do not start any actually start any event processing.
Definition: Environment.h:385
unsigned int m_skipNEvents
override skipNEvents for EventInfoSetter/RootInput.
Definition: Environment.h:393
int m_run
override run for EventInfoSetter.
Definition: Environment.h:391
@ c_Default
Default: use globally configured log level.
Definition: LogConfig.h:32
static ModuleManager & Instance()
Exception is thrown if the requested module could not be created by the ModuleManager.
void addModuleSearchPath(const std::string &path)
Adds a new filepath to the list of filepaths which are searched for a requested module.

Member Function Documentation

◆ consumeOutputFileOverride()

std::string consumeOutputFileOverride ( const std::string &  moduleName)

Return overriden output file name, or "" if none was set.

Note that this will remove the current value to avoid reuse. (e.g. subsequent calls will always return "")

Definition at line 67 of file Environment.cc.

◆ getDryRun()

bool getDryRun ( ) const
inline

Read steering file, but do not start any actually start any event processing.

Prints information on input/output files and number of events that that would be used during normal execution.

Definition at line 191 of file Environment.h.

191 { return m_dryRun; }

◆ getEntrySequencesOverride()

std::vector<std::string> getEntrySequencesOverride ( ) const
inline

Returns the number sequences (e.g.

23:42,101) defining the entry which are processed for each filename given in inputFilesOverride

Definition at line 72 of file Environment.h.

◆ getExternalsPath()

const std::string& getExternalsPath ( ) const
inline

Returns the path which points to the externals directory of the framework.

Returns
externals path, without trailing slash

Definition at line 60 of file Environment.h.

◆ getPicklePath()

std::string getPicklePath ( ) const
inline

Returns the path to the file where the pickled path is stored.

Returns
The path to the file where the pickled path is stored.

Definition at line 165 of file Environment.h.

◆ Instance()

Environment & Instance ( )
static

Static method to get a reference to the Environment instance.

Returns
A reference to an instance of this class.

Definition at line 28 of file Environment.cc.

◆ printJobInformation()

void printJobInformation ( ) const

Print information on input/output files in current steering file, used by –dry-run.

Function only relies on information available during module construction, but requires that Framework::process() has been called to set a path.

Definition at line 179 of file Environment.cc.

◆ setDryRun()

void setDryRun ( bool  dryRun)
inline

Read steering file, but do not start any actually start any event processing.

Prints information on input/output files and number of events that that would be used during normal execution.

Definition at line 189 of file Environment.h.

◆ setEntrySequencesOverride()

void setEntrySequencesOverride ( const std::vector< std::string > &  sequences)
inline

Override the number sequences (e.g.

23:42,101) defining the entries which are processed for each filename given in inputFilesOverride

Definition at line 69 of file Environment.h.

◆ setExternalsPath()

void setExternalsPath ( const std::string &  externalsPath)
inline

Sets the path which points to the externals directory of the framework.

Parameters
externalsPathPath in which the externals of the framework are located.

Definition at line 53 of file Environment.h.

◆ setNumberProcesses()

void setNumberProcesses ( int  number)
inline

Sets the number of processes which should be used for the parallel processing.

If the value is set to 0, no parallel processing will be used in the event loop.

Parameters
numberThe number of processes used for the parallel processing.

Definition at line 140 of file Environment.h.

◆ setNumberProcessesOverride()

void setNumberProcessesOverride ( int  nproc)
inline

Override number of processes to run in parallel.

Only values >= 0 will change the result of getNumberProcesses().

Definition at line 132 of file Environment.h.

◆ setPicklePath()

void setPicklePath ( const std::string &  path)
inline

Sets the path to the file where the pickled path is stored.

Parameters
pathThe path to the file where the pickled path is stored.

Definition at line 158 of file Environment.h.

Member Data Documentation

◆ m_dryRun

bool m_dryRun
private

Read steering file, but do not start any actually start any event processing.

Prints information on input/output files that that would be used during normal execution.

Definition at line 385 of file Environment.h.

◆ m_entrySequencesOverride

std::vector<std::string> m_entrySequencesOverride
private

A number sequence (e.g.

23:42,101) defining the entries which are processed for each input file in m_inputFilesOverride.

Definition at line 378 of file Environment.h.

◆ m_noStats

bool m_noStats
private

Disable collection of statistics during event processing.

Useful for very high-rate applications.

Definition at line 384 of file Environment.h.

◆ m_zmqDAQFirstEventExp

int m_zmqDAQFirstEventExp = 42
private

Exp no.

for the special first event

Definition at line 408 of file Environment.h.

◆ m_zmqDAQFirstEventRun

int m_zmqDAQFirstEventRun = 8
private

Exp no.

for the special first event

Definition at line 409 of file Environment.h.

◆ m_zmqFailOnFailedWorkers

bool m_zmqFailOnFailedWorkers = true
private

If a worker dies, fail also.

Will not be used if restartFailedWorkers is true.

Definition at line 406 of file Environment.h.

◆ m_zmqMaximalWaitingTime

unsigned int m_zmqMaximalWaitingTime
private
Initial value:
= (3600 * 24) *
1000

Maximal waiting time of any ZMQ module for any communication in ms.

Definition at line 399 of file Environment.h.

◆ m_zmqSocketAddress

std::string m_zmqSocketAddress = ""
private

Socket address to use in ZMQ.

If not set, uses a random IPC connection.

Definition at line 398 of file Environment.h.

◆ m_zmqWorkerTimeout

unsigned int m_zmqWorkerTimeout
private
Initial value:
=
0

How long should a worker maximally need to process all of his events in the queue.

Set to 0 to disable the check.

Definition at line 402 of file Environment.h.


The documentation for this class was generated from the following files: