Belle II Software light-2406-ragdoll
Configuration Class Reference

Class to enable configuration of the conditions database access in C++ and python. More...

#include <Configuration.h>

Collaboration diagram for Configuration:

Public Member Functions

 Configuration ()
 Initialize default values.
 
void reset ()
 Reset to default values.
 
void setInitialized (bool value)
 Set by the Database singleton upon initialization and cleanup.
 
Configuration of globaltags

These members are responsible to configure the list of user globaltags which will be used in addition or instead of the base globaltags.

void appendGlobalTag (const std::string &globalTag)
 Append a globaltag.
 
void prependGlobalTag (const std::string &globalTag)
 preprend a globaltag
 
void setGlobalTags (const std::vector< std::string > &list)
 Set the list of globaltags.
 
void setGlobalTagsPy (const boost::python::list &globalTags)
 Set the list of globaltags from python.
 
std::vector< std::string > getGlobalTags ()
 Get the list of user globaltags.
 
boost::python::list getGlobalTagsPy ()
 Get the list of user globaltags as python version.
 
std::vector< std::string > getDefaultGlobalTags () const
 Get the std::vector of default globaltags.
 
boost::python::tuple getDefaultGlobalTagsPy () const
 Get the tuple of default globaltags as python version.
 
void setInputGlobaltags (const std::vector< std::string > &inputTags)
 To be called by input modules with the tags to be added from input files.
 
void setInputMetadata (const std::vector< FileMetaData > &inputMetadata)
 To be called by input modules with the list of all input FileMetaData.
 
std::vector< std::string > getBaseTags () const
 Get the base globaltags to be used in addition to user globaltags.
 
void overrideGlobalTags ()
 Enable globaltag override: If this is called once than overrideEnabled() will return true and getFinalListOfTags() will just return getGlobalTags()
 
void overrideGlobalTagsPy (const boost::python::list &globalTags)
 Enable globaltag override and set the list of user globaltags in one go.
 
bool overrideEnabled () const
 Check if override is enabled by previous calls to overrideGlobalTags()
 
void disableGlobalTagReplay ()
 Disable global tag replay.
 
std::vector< std::string > getFinalListOfTags ()
 Get the final list of globaltags to be used for processing.
 
Testing Payload Configuration These members control where to look

for temporary testing payloads.

Each entry in the list of locations should be a filename of a textfile containing payload information. All payload files need to be in the same directory as the text file.

Entries are highest priority first: Payloads found by earlier entries will take precedence over later entries. Payloads found in these text files. take precedence over payloads from globaltags.

Warning
This causes non reproducible results and is only for testing purposes.
void appendTestingPayloadLocation (const std::string &filename)
 Add a local text file with testing payloads.
 
void prependTestingPayloadLocation (const std::string &filename)
 Prepend a local text file with testing payloads to the list.
 
void setTestingPayloadLocations (const std::vector< std::string > &list)
 Set the list of local text files to look for testing payloads.
 
void setTestingPayloadLocationsPy (const boost::python::list &list)
 Set the list of text files containing test payloads in python.
 
std::vector< std::string > getTestingPayloadLocations ()
 Get the list of testing payload locations.
 
boost::python::list getTestingPayloadLocationsPy ()
 Get the list of text files containing test payloads in python.
 
Configure Metadata providers

These members are used to configure metadata providers: Where to look for payload information given the list of globaltags.

  • Each entry in the list should be an URI or filename to a central REST server or a sqlite file containing a previously downloaded dump.
  • The first entry in the list is used unless there is a problem reaching the server/reading the file in which case we use the next entry in the list as failover.
void appendMetadataProvider (const std::string &provider)
 Append a metadata provider to the list.
 
void prependMetadataProvider (const std::string &provider)
 Prepend a metadata provider to the list.
 
void setMetadataProviders (const std::vector< std::string > &list)
 Set the list of metadata providers.
 
void setMetadataProvidersPy (const boost::python::list &list)
 Set the list of metadata providers in python.
 
std::vector< std::string > getMetadataProviders ()
 Get the list of metadata providers.
 
boost::python::list getMetadataProvidersPy ()
 Get the list of metadata providers in python.
 
std::string getDefaultMetadataProviderUrl ()
 Get the default URL where to look for the metadata provider.
 
Payload Location Configuration

Configure where to look for payload files.

This should be a list of directories and or http(s) urls where the files containing the payload content can be found. Each location will be tried in turn and if the payload is not found in any of them we try to download it from the official server.

void appendPayloadLocation (const std::string &location)
 Append a payload to the list of locations.
 
void prependPayloadLocation (const std::string &location)
 Prepend a payload to the list of locations.
 
void setPayloadLocations (const std::vector< std::string > &list)
 Set the list of payload locations.
 
void setPayloadLocationsPy (const boost::python::list &list)
 Set the list of payload locations in python.
 
std::vector< std::string > getPayloadLocations ()
 Get the list of payload locations.
 
boost::python::list getPayloadLocationsPy ()
 Get the list og payload locations in python.
 
Expert Settings

These members are for changing some expert settings which should not be necessary for most users.

These functions are exported to python using one exper_settings() function so no separate signatures for python are necessary.

void setNewPayloadLocation (const std::string &filename)
 Set the file where to save newly created payload information.
 
std::string getNewPayloadLocation () const
 Get the filename where to save newly created payload information.
 
void setDownloadCacheDirectory (const std::string &directory)
 Set the directory where to place downloaded payloads.
 
std::string getDownloadCacheDirectory () const
 Get the directory where to place downloaded payloads.
 
void setDownloadLockTimeout (size_t timeout)
 Set the timout we try to lock a file in the download cache directory for downloading.
 
size_t getDownloadLockTimeout () const
 Get the timout we try to lock a file in the download cache directory for downloading.
 
void setUsableTagStates (const std::set< std::string > &states)
 Set the set of usable globaltag states to be allowed for processing.
 
const std::set< std::string > & getUsableTagStates () const
 Get the set of usable globaltag states allowed to be used for processing.
 
void setGlobaltagCallbackPy (const boost::python::object &obj)
 Set a callback function from python which will be called when processing starts and should return the final list of globaltags to be used.
 

Static Public Member Functions

static ConfigurationgetInstance ()
 Get a reference to the instance which will be used when the Database is initialized.
 
static void exposePythonAPI ()
 expose this class to python
 

Private Member Functions

void ensureEditable () const
 Check whether the configuration object can be edited or if the database has been initialized already.
 

Static Private Member Functions

template<class T >
static void fillFromEnv (T &target, const std::string &envName, const std::string &defaultValue)
 Fill a target object from a list of environment variables.
 

Private Attributes

bool m_overrideEnabled {false}
 is the globaltag override enabled?
 
std::optional< std::vector< std::string > > m_inputGlobaltags
 the list of globaltags from all the input files to be used in addition to the user globaltags
 
std::vector< FileMetaDatam_inputMetadata
 the file metadata of all input files if globaltag replay is requested by input module
 
CppOrPyList m_globalTags
 the list with all user globaltags
 
CppOrPyList m_testingPayloadLocations
 the files with testing payloads to use during processing
 
CppOrPyList m_metadataProviders
 the list with all the metadata providers
 
CppOrPyList m_payloadLocations
 the list with all the payload locations
 
std::string m_defaultMetadataProviderUrl {"http://belle2db.sdcc.bnl.gov/b2s/rest/"}
 default URL where to look for the metadata provider
 
std::string m_newPayloadFile {"localdb/database.txt"}
 the file to put the newly created payload information
 
std::string m_downloadCacheDirectory {""}
 the directory to put newly downloaded payloads
 
size_t m_downloadLockTimeout {120}
 the timeout when trying to lock files in the download directory
 
std::set< std::string > m_usableTagStates {"TESTING", "VALIDATED", "PUBLISHED", "RUNNING"}
 the tag states accepted for processing
 
std::optional< boost::python::object > m_callback
 the callback function to determine the final final list of globaltags
 
bool m_databaseInitialized {false}
 bool indicating whether the database has been initialized, in which case any changes to the configuration object would not be reflected by the database setup so we refuse them
 

Detailed Description

Class to enable configuration of the conditions database access in C++ and python.

This class contains all settings relevant for the usage of the conditions database.

Mostly this class is just a container for user settings without much intelligence. The only thing it does is construct the final list of globaltags to be used from input data and user settings, maybe via a user callback, in getFinalListOfTags().

the exposePythonAPI() function contains detailed documentation to most of the members in this class for the python interface and details all of the settings.

Definition at line 61 of file Configuration.h.

Member Function Documentation

◆ appendGlobalTag()

void appendGlobalTag ( const std::string &  globalTag)
inline

Append a globaltag.

Definition at line 78 of file Configuration.h.

78{ ensureEditable(); m_globalTags.append(globalTag); }
CppOrPyList m_globalTags
the list with all user globaltags
void ensureEditable() const
Check whether the configuration object can be edited or if the database has been initialized already.
void append(const std::string &element)
Append an element to whatever representation we currently have.

◆ appendMetadataProvider()

void appendMetadataProvider ( const std::string &  provider)
inline

Append a metadata provider to the list.

Definition at line 222 of file Configuration.h.

CppOrPyList m_metadataProviders
the list with all the metadata providers

◆ appendPayloadLocation()

void appendPayloadLocation ( const std::string &  location)
inline

Append a payload to the list of locations.

Definition at line 248 of file Configuration.h.

CppOrPyList m_payloadLocations
the list with all the payload locations

◆ appendTestingPayloadLocation()

void appendTestingPayloadLocation ( const std::string &  filename)
inline

Add a local text file with testing payloads.

Definition at line 194 of file Configuration.h.

CppOrPyList m_testingPayloadLocations
the files with testing payloads to use during processing

◆ disableGlobalTagReplay()

void disableGlobalTagReplay ( )
inline

Disable global tag replay.

This restores the previous behavior of just using the default globaltag and is just a shortcut for calling overrideGlobalTags() and appending each tag in getDefaultGlobalTags() tho the list of globaltags using appendGlobalTag()

Definition at line 152 of file Configuration.h.

153 {
155 for (const auto& tag : getDefaultGlobalTags()) appendGlobalTag(tag);
156 }
void appendGlobalTag(const std::string &globalTag)
Append a globaltag.
Definition: Configuration.h:78
void overrideGlobalTags()
Enable globaltag override: If this is called once than overrideEnabled() will return true and getFina...
std::vector< std::string > getDefaultGlobalTags() const
Get the std::vector of default globaltags.

◆ ensureEditable()

void ensureEditable ( ) const
inlineprivate

Check whether the configuration object can be edited or if the database has been initialized already.

Definition at line 314 of file Configuration.h.

315 {
317 throw std::runtime_error("Database already initialized, please reset before changing the configuration object");
318 }
bool m_databaseInitialized
bool indicating whether the database has been initialized, in which case any changes to the configura...

◆ fillFromEnv()

static void fillFromEnv ( T &  target,
const std::string &  envName,
const std::string &  defaultValue 
)
inlinestaticprivate

Fill a target object from a list of environment variables.

Definition at line 308 of file Configuration.h.

309 {
310 const auto values = EnvironmentVariables::getOrCreateList(envName, defaultValue);
311 for (const std::string& v : values) target.append(v);
312 }
static std::vector< std::string > getOrCreateList(const std::string &name, const std::string &fallback, const std::string &separators=" \t\n\r")
Get a list of values from an environment variable or the given fallback string if the variable is not...

◆ getBaseTags()

std::vector< std::string > getBaseTags ( ) const

Get the base globaltags to be used in addition to user globaltags.

  • If no input file is present, the result of getBaseTags() is identical to the list returned by getDefaultGlobalTags()
  • If one ore more input files are present, the input module is responsible to call setInputGlobalTags(). If setInputGlobalTags() has been called then getBaseTags() returns the list of globaltags by splitting the value passed from the input modules at the commas.

◆ getDefaultMetadataProviderUrl()

std::string getDefaultMetadataProviderUrl ( )
inline

Get the default URL where to look for the metadata provider.

Definition at line 234 of file Configuration.h.

std::string m_defaultMetadataProviderUrl
default URL where to look for the metadata provider

◆ getDownloadCacheDirectory()

std::string getDownloadCacheDirectory ( ) const
inline

Get the directory where to place downloaded payloads.

Empty string is shorthand to put them in a folder basf2-conditions in the temp dir

Definition at line 282 of file Configuration.h.

282{ return m_downloadCacheDirectory; }
std::string m_downloadCacheDirectory
the directory to put newly downloaded payloads

◆ getDownloadLockTimeout()

size_t getDownloadLockTimeout ( ) const
inline

Get the timout we try to lock a file in the download cache directory for downloading.

Definition at line 287 of file Configuration.h.

287{ return m_downloadLockTimeout; }
size_t m_downloadLockTimeout
the timeout when trying to lock files in the download directory

◆ getFinalListOfTags()

std::vector< std::string > getFinalListOfTags ( )

Get the final list of globaltags to be used for processing.

See also
setGlobaltagCallbackPy() to set a callback function from python to further customize this behavior
Warning
This function is only to be called by the conditions database service when processing starts. Calling this function from user code might abort processing if called at the wrong time or without properly initializing the settings.

◆ getGlobalTags()

std::vector< std::string > getGlobalTags ( )
inline

Get the list of user globaltags.

Definition at line 86 of file Configuration.h.

86{ return m_globalTags.ensureCpp(); }
std::vector< std::string > & ensureCpp()
Return the C++ vector version.

◆ getGlobalTagsPy()

boost::python::list getGlobalTagsPy ( )
inline

Get the list of user globaltags as python version.

Definition at line 88 of file Configuration.h.

88{ return m_globalTags.ensurePy(); }
boost::python::list & ensurePy()
Return the python list version.

◆ getMetadataProviders()

std::vector< std::string > getMetadataProviders ( )
inline

Get the list of metadata providers.

Definition at line 230 of file Configuration.h.

230{ return m_metadataProviders.ensureCpp(); }

◆ getMetadataProvidersPy()

boost::python::list getMetadataProvidersPy ( )
inline

Get the list of metadata providers in python.

Definition at line 232 of file Configuration.h.

232{ return m_metadataProviders.ensurePy(); }

◆ getNewPayloadLocation()

std::string getNewPayloadLocation ( ) const
inline

Get the filename where to save newly created payload information.

Definition at line 275 of file Configuration.h.

275{ return m_newPayloadFile; }
std::string m_newPayloadFile
the file to put the newly created payload information

◆ getPayloadLocations()

std::vector< std::string > getPayloadLocations ( )
inline

Get the list of payload locations.

Definition at line 256 of file Configuration.h.

256{ return m_payloadLocations.ensureCpp(); }

◆ getPayloadLocationsPy()

boost::python::list getPayloadLocationsPy ( )
inline

Get the list og payload locations in python.

Definition at line 258 of file Configuration.h.

258{ return m_payloadLocations.ensurePy(); }

◆ getTestingPayloadLocations()

std::vector< std::string > getTestingPayloadLocations ( )
inline

Get the list of testing payload locations.

Definition at line 202 of file Configuration.h.

◆ getTestingPayloadLocationsPy()

boost::python::list getTestingPayloadLocationsPy ( )
inline

Get the list of text files containing test payloads in python.

Definition at line 204 of file Configuration.h.

◆ getUsableTagStates()

const std::set< std::string > & getUsableTagStates ( ) const
inline

Get the set of usable globaltag states allowed to be used for processing.

Definition at line 293 of file Configuration.h.

293{ return m_usableTagStates; }
std::set< std::string > m_usableTagStates
the tag states accepted for processing

◆ overrideEnabled()

bool overrideEnabled ( ) const
inline

Check if override is enabled by previous calls to overrideGlobalTags()

Definition at line 143 of file Configuration.h.

143{ return m_overrideEnabled; }
bool m_overrideEnabled
is the globaltag override enabled?

◆ overrideGlobalTags()

void overrideGlobalTags ( )
inline

Enable globaltag override: If this is called once than overrideEnabled() will return true and getFinalListOfTags() will just return getGlobalTags()

Definition at line 139 of file Configuration.h.

◆ prependGlobalTag()

void prependGlobalTag ( const std::string &  globalTag)
inline

preprend a globaltag

Definition at line 80 of file Configuration.h.

80{ ensureEditable(); m_globalTags.prepend(globalTag); }
void prepend(const std::string &element)
Prepend an element to whatever representation we currently have.

◆ prependMetadataProvider()

void prependMetadataProvider ( const std::string &  provider)
inline

Prepend a metadata provider to the list.

Definition at line 224 of file Configuration.h.

◆ prependPayloadLocation()

void prependPayloadLocation ( const std::string &  location)
inline

Prepend a payload to the list of locations.

Definition at line 250 of file Configuration.h.

◆ prependTestingPayloadLocation()

void prependTestingPayloadLocation ( const std::string &  filename)
inline

Prepend a local text file with testing payloads to the list.

Definition at line 196 of file Configuration.h.

◆ setDownloadCacheDirectory()

void setDownloadCacheDirectory ( const std::string &  directory)
inline

Set the directory where to place downloaded payloads.

Empty string is shorthand to put them in a folder basf2-conditions in the temp dir

Definition at line 279 of file Configuration.h.

◆ setDownloadLockTimeout()

void setDownloadLockTimeout ( size_t  timeout)
inline

Set the timout we try to lock a file in the download cache directory for downloading.

Definition at line 285 of file Configuration.h.

◆ setGlobaltagCallbackPy()

void setGlobaltagCallbackPy ( const boost::python::object &  obj)
inline

Set a callback function from python which will be called when processing starts and should return the final list of globaltags to be used.

See the python documentation for more details

Definition at line 298 of file Configuration.h.

298{ ensureEditable(); m_callback = obj; }
std::optional< boost::python::object > m_callback
the callback function to determine the final final list of globaltags

◆ setGlobalTags()

void setGlobalTags ( const std::vector< std::string > &  list)
inline

Set the list of globaltags.

Definition at line 82 of file Configuration.h.

◆ setGlobalTagsPy()

void setGlobalTagsPy ( const boost::python::list &  globalTags)
inline

Set the list of globaltags from python.

Definition at line 84 of file Configuration.h.

84{ ensureEditable(); m_globalTags.shallowCopy(globalTags); }
void shallowCopy(const boost::python::object &source)
shallow copy all elements of the source object into the python representation.

◆ setInitialized()

void setInitialized ( bool  value)
inline

Set by the Database singleton upon initialization and cleanup.

Definition at line 303 of file Configuration.h.

303{ m_databaseInitialized = value; }

◆ setInputGlobaltags()

void setInputGlobaltags ( const std::vector< std::string > &  inputTags)
inline

To be called by input modules with the tags to be added from input files.

This method is to be called by input modules which know the list of globaltags to be used but cannot provide FileMetaData instances for these input files.

In case an empty list is put in this means global tag replay is not possible for these input files and the user will need to manually supply all tags and use the override flag to disable any attempt at tag replay.

See also
setInputMetadata()

Definition at line 108 of file Configuration.h.

109 {
111 m_inputGlobaltags = inputTags;
112 }
std::optional< std::vector< std::string > > m_inputGlobaltags
the list of globaltags from all the input files to be used in addition to the user globaltags

◆ setInputMetadata()

void setInputMetadata ( const std::vector< FileMetaData > &  inputMetadata)

To be called by input modules with the list of all input FileMetaData.

This method is to be called by input modules which have a full list of FileMetaData instances for all input files. It will then check if all instances have a compatible globaltag setting and call setInputGlobalTags accordingly.

See also
setInputGlobaltags()

◆ setMetadataProviders()

void setMetadataProviders ( const std::vector< std::string > &  list)
inline

Set the list of metadata providers.

Definition at line 226 of file Configuration.h.

◆ setMetadataProvidersPy()

void setMetadataProvidersPy ( const boost::python::list &  list)
inline

Set the list of metadata providers in python.

Definition at line 228 of file Configuration.h.

◆ setNewPayloadLocation()

void setNewPayloadLocation ( const std::string &  filename)
inline

Set the file where to save newly created payload information.

Definition at line 273 of file Configuration.h.

273{ ensureEditable(); m_newPayloadFile = filename; }

◆ setPayloadLocations()

void setPayloadLocations ( const std::vector< std::string > &  list)
inline

Set the list of payload locations.

Definition at line 252 of file Configuration.h.

◆ setPayloadLocationsPy()

void setPayloadLocationsPy ( const boost::python::list &  list)
inline

Set the list of payload locations in python.

Definition at line 254 of file Configuration.h.

◆ setTestingPayloadLocations()

void setTestingPayloadLocations ( const std::vector< std::string > &  list)
inline

Set the list of local text files to look for testing payloads.

Definition at line 198 of file Configuration.h.

◆ setTestingPayloadLocationsPy()

void setTestingPayloadLocationsPy ( const boost::python::list &  list)
inline

Set the list of text files containing test payloads in python.

Definition at line 200 of file Configuration.h.

◆ setUsableTagStates()

void setUsableTagStates ( const std::set< std::string > &  states)
inline

Set the set of usable globaltag states to be allowed for processing.

The state INVALID will always be ignored and not permitted

Definition at line 291 of file Configuration.h.

291{ ensureEditable(); m_usableTagStates = states; }

Member Data Documentation

◆ m_callback

std::optional<boost::python::object> m_callback
private

the callback function to determine the final final list of globaltags

Definition at line 345 of file Configuration.h.

◆ m_databaseInitialized

bool m_databaseInitialized {false}
private

bool indicating whether the database has been initialized, in which case any changes to the configuration object would not be reflected by the database setup so we refuse them

Definition at line 348 of file Configuration.h.

◆ m_defaultMetadataProviderUrl

std::string m_defaultMetadataProviderUrl {"http://belle2db.sdcc.bnl.gov/b2s/rest/"}
private

default URL where to look for the metadata provider

Definition at line 335 of file Configuration.h.

◆ m_downloadCacheDirectory

std::string m_downloadCacheDirectory {""}
private

the directory to put newly downloaded payloads

Definition at line 339 of file Configuration.h.

◆ m_downloadLockTimeout

size_t m_downloadLockTimeout {120}
private

the timeout when trying to lock files in the download directory

Definition at line 341 of file Configuration.h.

◆ m_globalTags

CppOrPyList m_globalTags
private

the list with all user globaltags

Definition at line 327 of file Configuration.h.

◆ m_inputGlobaltags

std::optional<std::vector<std::string> > m_inputGlobaltags
private

the list of globaltags from all the input files to be used in addition to the user globaltags

Definition at line 323 of file Configuration.h.

◆ m_inputMetadata

std::vector<FileMetaData> m_inputMetadata
private

the file metadata of all input files if globaltag replay is requested by input module

Definition at line 325 of file Configuration.h.

◆ m_metadataProviders

CppOrPyList m_metadataProviders
private

the list with all the metadata providers

Definition at line 331 of file Configuration.h.

◆ m_newPayloadFile

std::string m_newPayloadFile {"localdb/database.txt"}
private

the file to put the newly created payload information

Definition at line 337 of file Configuration.h.

◆ m_overrideEnabled

bool m_overrideEnabled {false}
private

is the globaltag override enabled?

Definition at line 320 of file Configuration.h.

◆ m_payloadLocations

CppOrPyList m_payloadLocations
private

the list with all the payload locations

Definition at line 333 of file Configuration.h.

◆ m_testingPayloadLocations

CppOrPyList m_testingPayloadLocations
private

the files with testing payloads to use during processing

Definition at line 329 of file Configuration.h.

◆ m_usableTagStates

std::set<std::string> m_usableTagStates {"TESTING", "VALIDATED", "PUBLISHED", "RUNNING"}
private

the tag states accepted for processing

Definition at line 343 of file Configuration.h.


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