Belle II Software development
Configuration Class Reference

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

#include <Configuration.h>

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)
 prepend 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 getDefaultRemoteMetadataProviderServer ()
 Get the default server URL for the remote metadata provider.
 
std::string getDefaultLocalMetadataProviderPath ()
 Get the default local path for the local 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 timeout we try to lock a file in the download cache directory for downloading.
 
size_t getDownloadLockTimeout () const
 Get the timeout 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_defaultRemoteMetadataProviderServer {"http://belle2db.sdcc.bnl.gov/b2s/rest/"}
 default server URL for the remote metadata provider
 
std::string m_defaultLocalMetadataProviderPath {"/cvmfs/belle.cern.ch/conditions"}
 default local path for the local 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.

Constructor & Destructor Documentation

◆ Configuration()

Initialize default values.

Definition at line 97 of file Configuration.cc.

98 {
99 // Backwards compatibility with the existing BELLE2_CONDB_GLOBALTAG
100 // environment variable: If it is set disable replay
101 if (EnvironmentVariables::isSet("BELLE2_CONDB_GLOBALTAG")) {
102 fillFromEnv(m_globalTags, "BELLE2_CONDB_GLOBALTAG", "");
103 overrideGlobalTags();
104 }
105 const std::string serverList = EnvironmentVariables::get("BELLE2_CONDB_SERVERLIST", "");
106 // The list of the metadata providers we are going to query:
107 const std::string metatadaProviders = serverList + " " + // First, the list of servers provided via env. variable
108 m_defaultLocalMetadataProviderPath + "/database.sqlite" + " " + // Then the default local provider (CVMFS)
109 m_defaultRemoteMetadataProviderServer; // And finally, the default remote provider (BNL)
110 fillFromEnv(m_metadataProviders, "BELLE2_CONDB_METADATA", metatadaProviders);
111 fillFromEnv(m_payloadLocations, "BELLE2_CONDB_PAYLOADS", m_defaultLocalMetadataProviderPath);
112 }

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); }

◆ appendMetadataProvider()

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

Append a metadata provider to the list.

Definition at line 222 of file Configuration.h.

222{ ensureEditable(); m_metadataProviders.append(provider); }

◆ appendPayloadLocation()

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

Append a payload to the list of locations.

Definition at line 250 of file Configuration.h.

250{ ensureEditable(); m_payloadLocations.append(location); }

◆ appendTestingPayloadLocation()

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

Add a local text file with testing payloads.

Definition at line 194 of file Configuration.h.

194{ ensureEditable(); m_testingPayloadLocations.append(filename); }

◆ 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 {
154 overrideGlobalTags();
155 for (const auto& tag : getDefaultGlobalTags()) appendGlobalTag(tag);
156 }

◆ ensureEditable()

void ensureEditable ( ) const
inlineprivate

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

Definition at line 316 of file Configuration.h.

317 {
318 if (m_databaseInitialized)
319 throw std::runtime_error("Database already initialized, please reset before changing the configuration object");
320 }

◆ exposePythonAPI()

void exposePythonAPI ( )
static

expose this class to python

Definition at line 376 of file Configuration.cc.

377 {
378 //don't show c++ signature in python doc to keep it simple
379 py::docstring_options options(true, false, false);
380
381 void (Configuration::*overrideGTFlag)() = &Configuration::overrideGlobalTags;
382 void (Configuration::*overrideGTList)(const py::list&) = &Configuration::overrideGlobalTagsPy;
383 py::object expert = raw_function(expertSettings);
384 py::class_<Configuration>("ConditionsConfiguration", R"DOC(
385This class contains all configurations for the conditions database service
386
387* which globaltags to use
388* where to look for payload information
389* where to find the actual payload files
390* which temporary testing payloads to use
391
392But for most users the only thing they should need to care about is to set the
393list of additional `globaltags` to use.
394)DOC")
395 .add_property("override_enabled", &Configuration::overrideEnabled, R"DOC(
396Indicator whether or not the override of globaltags is enabled. If true then
397globaltags present in input files will be ignored and only the ones given in
398`globaltags` will be considered.
399)DOC")
400 .def("reset", &Configuration::reset, R"DOC(reset()
401
402Reset the conditions database configuration to its original state.
403)DOC")
404 .add_property("default_globaltags", &Configuration::getDefaultGlobalTagsPy, R"DOC(
405A tuple containing the default globaltags to be used if events are generated without an input file.
406)DOC")
407 .add_property("globaltags", &Configuration::getGlobalTagsPy, &Configuration::setGlobalTagsPy, R"DOC(
408List of globaltags to be used. These globaltags will be the ones with highest
409priority but by default the globaltags used to create the input files or the
410default globaltag will also be used.
411
412The priority of the globaltags in this list is highest first. So the first in
413the list will be checked first and all other globaltags will only be checked for
414payloads not found so far.
415
416Warning:
417 By default this list contains the globaltags to be used **in addition** to
418 the ones from the input file or the default one if no input file is present.
419 If this is not desirable you need to call `override_globaltags()` to disable
420 any addition or modification of this list.
421)DOC")
422 .def("append_globaltag", &Configuration::appendGlobalTag, py::args("name"), R"DOC(append_globaltag(name)
423
424Append a globaltag to the end of the `globaltags` list. That means it will be
425the lowest priority of all tags in the list.
426)DOC")
427 .def("prepend_globaltag", &Configuration::prependGlobalTag, py::args("name"), R"DOC(prepend_globaltag(name)
428
429Add a globaltag to the beginning of the `globaltags` list. That means it will be
430the highest priority of all tags in the list.
431)DOC")
432 .def("override_globaltags", overrideGTFlag)
433 .def("override_globaltags", overrideGTList, py::args("globaltags"), R"DOC(override_globaltags(list=None)
434
435Enable globaltag override. This disables all modification of the globaltag list at the beginning of processing:
436
437* the default globaltag or the input file globaltags will be ignored.
438* any callback set with `set_globaltag_callback` will be ignored.
439* the list of `globaltags` will be used exactly as it is.
440
441Parameters:
442 list (list(str) or None) if given this list will replace the current content of `globaltags`
443
444Warning:
445 it's still possible to modify `globaltags` after this call.
446)DOC")
447 .def("disable_globaltag_replay", &Configuration::disableGlobalTagReplay, R"DOC(disable_globaltag_replay()
448
449Disable global tag replay and revert to the old behavior that the default
450globaltag will be used if no other globaltags are specified.
451
452This is a shortcut to just calling
453
454 >>> conditions.override_globaltags()
455 >>> conditions.globaltags += list(conditions.default_globaltags)
456
457)DOC")
458 .def("append_testing_payloads", &Configuration::appendTestingPayloadLocation, py::args("filename"), R"DOC(append_testing_payloads(filename)
459
460Append a text file containing local test payloads to the end of the list of
461`testing_payloads`. This will mean they will have lower priority than payloads
462in previously defined text files but still higher priority than globaltags.
463
464Parameters:
465 filename (str): file containing a local definition of payloads and their
466 intervals of validity for testing
467
468Warning:
469 This functionality is strictly for testing purposes. Using local payloads
470 leads to results which cannot be reproduced by anyone else and thus cannot
471 be published.
472)DOC")
473 .def("prepend_testing_payloads", &Configuration::prependTestingPayloadLocation, py::args("filename"), R"DOC(prepend_testing_payloads(filename)
474
475Insert a text file containing local test payloads in the beginning of the list
476of `testing_payloads`. This will mean they will have higher priority than payloads in
477previously defined text files as well as higher priority than globaltags.
478
479Parameters:
480 filename (str): file containing a local definition of payloads and their
481 intervals of validity for testing
482
483Warning:
484 This functionality is strictly for testing purposes. Using local payloads
485 leads to results which cannot be reproduced by anyone else and thus cannot
486 be published.
487)DOC")
488 .add_property("testing_payloads", &Configuration::getTestingPayloadLocationsPy, &Configuration::setTestingPayloadLocationsPy, R"DOC(
489List of text files to look for local testing payloads. Each entry should be a
490text file containing local payloads and their intervals of validity to be used
491for testing.
492
493Payloads found in these files and valid for the current run will have a higher
494priority than any of the `globaltags`. If a valid payload is present in multiple
495files the first one in the list will have higher priority.
496
497Warning:
498 This functionality is strictly for testing purposes. Using local payloads
499 leads to results which cannot be reproduced by anyone else and thus cannot
500 be published.
501)DOC")
502 .add_property("metadata_providers", &Configuration::getMetadataProvidersPy, &Configuration::setMetadataProvidersPy, R"DOC(
503List of metadata providers to use when looking for payload metadata. There are currently two supported providers:
504
5051. Central metadata provider to look for payloads in the central conditions database.
506 This provider is used for any entry in this list which starts with ``http(s)://``.
507 The URL should point to the top level of the REST api endpoints on the server
508
5092. Local metadata provider to look for payloads in a local SQLite snapshot taken
510 from the central server. This provider will be assumed for any entry in this
511 list not starting with a protocol specifier or if the protocol is given as ``file://``
512
513This list should rarely need to be changed. The only exception is for users who
514want to be able to use the software without internet connection after they
515downloaded a snapshot of the necessary globaltags with ``b2conditionsdb download``
516to point to this location.
517)DOC")
518 .add_property("default_metadata_provider_server", &Configuration::getDefaultRemoteMetadataProviderServer, R"DOC(
519URL of the default central metadata provider to look for payloads in the
520conditions database.
521)DOC")
522 .add_property("payload_locations", &Configuration::getPayloadLocationsPy, &Configuration::setPayloadLocationsPy, R"DOC(
523List of payload locations to search for payloads which have been found by any of
524the configured `metadata_providers`. This can be a local directory or a
525``http(s)://`` url pointing to the payload directory on a server.
526
527For remote locations starting with ``http(s)://`` we assume that the layout of
528the payloads on the server is the same as on the main payload server:
529The combination of given location and the relative url in the payload metadata
530field ``payloadUrl`` should point to the correct payload on the server.
531
532For local directories, two layouts are supported and will be auto detected:
533
534flat
535 All payloads are in the same directory without any substructure with the name
536 ``dbstore_{name}_rev_{revision}.root``
537hashed
538 All payloads are stored in subdirectories in the form ``AB/{name}_r{revision}.root``
539 where ``A`` and ``B`` are the first two characters of the md5 checksum of the
540 payload file.
541
542Example:
543 Given ``payload_locations = ["payload_dir/", "http://server.com/payloads"]``
544 the framework would look for a payload with name ``BeamParameters`` in revision
545 ``45`` (and checksum ``a34ce5...``) in the following places
546
547
548 1. ``payload_dir/a3/BeamParameters_r45.root``
549 2. ``payload_dir/dbstore_BeamParameters_rev_45.root``
550 3. ``http://server.com/payloads/dbstore/BeamParameters/dbstore_BeamParameters_rev_45.root``
551 given the usual pattern of the ``payloadUrl`` metadata. But this could be
552 changed on the central servers so mirrors should not depend on this convention
553 but copy the actual structure of the central server.
554
555If the payload cannot be found in any of the given locations the framework will
556always attempt to download it directly from the central server and put it in a
557local cache directory.
558)DOC")
559 .def("expert_settings", expert, R"DOC(expert_settings(**kwargs)
560
561Set some additional settings for the conditions database.
562
563You can supply any combination of keyword-only arguments defined below. The
564function will return a dictionary containing all current settings.
565
566 >>> conditions.expert_settings(connection_timeout=5, max_retries=1)
567 {'save_payloads': 'localdb/database.txt',
568 'download_cache_location': '',
569 'download_lock_timeout': 120,
570 'usable_globaltag_states': {'PUBLISHED', 'RUNNING', 'TESTING', 'VALIDATED'},
571 'connection_timeout': 5,
572 'stalled_timeout': 60,
573 'max_retries': 1,
574 'backoff_factor': 5}

◆ fillFromEnv()

template<class T>
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 310 of file Configuration.h.

311 {
312 const auto values = EnvironmentVariables::getOrCreateList(envName, defaultValue);
313 for (const std::string& v : values) target.append(v);
314 }

◆ 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 or 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.

Definition at line 214 of file Configuration.cc.

215 {
216 // return the list of base tags to be used: Either the default tag
217 // or the list of globaltags from the input files
218 if (not m_inputGlobaltags) return getDefaultGlobalTags();
219 return *m_inputGlobaltags;
220 }

◆ getDefaultGlobalTags()

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

Get the std::vector of default globaltags.

Definition at line 122 of file Configuration.cc.

123 {
124 // currently the default globaltag can be overwritten by environment variable
125 // so keep that
126 return EnvironmentVariables::getOrCreateList("BELLE2_CONDB_GLOBALTAG", CURRENT_DEFAULT_TAG);
127 }

◆ getDefaultGlobalTagsPy()

py::tuple getDefaultGlobalTagsPy ( ) const

Get the tuple of default globaltags as python version.

Definition at line 129 of file Configuration.cc.

130 {
131 // same as above but as a python tuple ...
132 py::list list;
133 fillFromEnv(list, "BELLE2_CONDB_GLOBALTAG", CURRENT_DEFAULT_TAG);
134 return py::tuple(list);
135 }

◆ getDefaultLocalMetadataProviderPath()

std::string getDefaultLocalMetadataProviderPath ( )
inline

Get the default local path for the local metadata provider.

Definition at line 236 of file Configuration.h.

236{ return m_defaultLocalMetadataProviderPath; }

◆ getDefaultRemoteMetadataProviderServer()

std::string getDefaultRemoteMetadataProviderServer ( )
inline

Get the default server URL for the remote metadata provider.

Definition at line 234 of file Configuration.h.

234{ return m_defaultRemoteMetadataProviderServer; }

◆ 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 284 of file Configuration.h.

284{ return m_downloadCacheDirectory; }

◆ getDownloadLockTimeout()

size_t getDownloadLockTimeout ( ) const
inline

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

Definition at line 289 of file Configuration.h.

289{ return m_downloadLockTimeout; }

◆ 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.

Definition at line 222 of file Configuration.cc.

223 {
224 if (m_overrideEnabled) {
225 B2INFO("Global tag override is in effect: input globaltags and default globaltag will be ignored");
226 return m_globalTags.ensureCpp();
227 }
228
229 auto baseList = getBaseTags();
230 if (m_callback) {
231 // Create a dictionary of keyword arguments for the callback
232 py::dict arguments;
233 // we want a python list of the base tags
234 {
235 py::list baseListPy;
236 for (const auto& tag : baseList) baseListPy.append(tag);
237 arguments["base_tags"] = baseListPy;
238 }
239 // and set the user tags from our list.
240 arguments["user_tags"] = m_globalTags.ensurePy();
241 // and prepare list of metadata. It's None when no replay has been
242 // requested which should mean that we generate events
243 arguments["metadata"] = py::object();
244 // otherwise it's a list of file metadata instances
245 if (m_inputGlobaltags) {
246 py::list metaDataList;
247 for (const auto& m : m_inputMetadata) metaDataList.append(createROOTObjectPyCopy(m));
248 arguments["metadata"] = metaDataList;
249 }
250 // arguments ready, call callback function, python will handle the exceptions
251 py::object retval = (*m_callback)(*py::tuple(), **arguments);
252 // If the return value is not None it should be an iterable
253 // containing the final tag list
254 if (retval != py::object()) {
255 return extractStringList(retval);
256 }
257 // callback returned None so fall back to default
258 }
259 // Default tag replay ... bail if list of globaltags is empty
260 if (baseList.empty()) {
261 if (m_inputGlobaltags) {
262 B2FATAL(R"(No baseline globaltags available.
263 The input files you selected don't have compatible globaltags or an empty
264 globaltag setting. As such globaltag configuration cannot be determined
265 automatically.
266
267 If you really sure that it is a good idea to process these files together
268 you have to manually override the list of globaltags:
269
270 >>> basf2.conditions.override_globaltags()
271)");
272 }else{
273 B2FATAL(R"(No default globaltags available.
274 There is no default globaltag available for processing. This usually means
275 you set the environment variable BELLE2_CONDB_GLOBALTAG to an empty value.
276
277 As this is unlikely to work for even the most basic functionality this is not
278 directly supported anymore. If you really want to disable any access to the
279 conditions database please configure this explicitly
280
281 >>> basf2.conditions.metadata_providers = []
282 >>> basf2.conditions.override_globaltags([])
283)");
284 }
285 }
286 // We have base tags and possibly user tags, so return both
287 std::vector finalList = m_globalTags.ensureCpp();
288 for (const auto& tag : baseList) { finalList.emplace_back(tag); }
289 return finalList;
290 }
boost::python::object createROOTObjectPyCopy(const T &instance)
Create a python wrapped copy from a class instance which has a ROOT dictionary.

◆ 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(); }

◆ 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(); }

◆ getInstance()

Configuration & getInstance ( )
static

Get a reference to the instance which will be used when the Database is initialized.

Definition at line 91 of file Configuration.cc.

92 {
93 static Configuration instance;
94 return instance;
95 }

◆ 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 277 of file Configuration.h.

277{ return m_newPayloadFile; }

◆ getPayloadLocations()

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

Get the list of payload locations.

Definition at line 258 of file Configuration.h.

258{ return m_payloadLocations.ensureCpp(); }

◆ getPayloadLocationsPy()

boost::python::list getPayloadLocationsPy ( )
inline

Get the list og payload locations in python.

Definition at line 260 of file Configuration.h.

260{ 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.

202{ return m_testingPayloadLocations.ensureCpp(); }

◆ 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.

204{ return m_testingPayloadLocations.ensurePy(); }

◆ 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 295 of file Configuration.h.

295{ return m_usableTagStates; }

◆ 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; }

◆ 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.

139{ ensureEditable(); m_overrideEnabled = true; }

◆ overrideGlobalTagsPy()

void overrideGlobalTagsPy ( const boost::python::list & globalTags)

Enable globaltag override and set the list of user globaltags in one go.

Definition at line 370 of file Configuration.cc.

371 {
372 setGlobalTagsPy(globalTags);
373 m_overrideEnabled = true;
374 }

◆ prependGlobalTag()

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

prepend a globaltag

Definition at line 80 of file Configuration.h.

80{ ensureEditable(); m_globalTags.prepend(globalTag); }

◆ prependMetadataProvider()

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

Prepend a metadata provider to the list.

Definition at line 224 of file Configuration.h.

224{ ensureEditable(); m_metadataProviders.prepend(provider); }

◆ prependPayloadLocation()

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

Prepend a payload to the list of locations.

Definition at line 252 of file Configuration.h.

252{ ensureEditable(); m_payloadLocations.prepend(location); }

◆ 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.

196{ ensureEditable(); m_testingPayloadLocations.prepend(filename); }

◆ reset()

void reset ( )

Reset to default values.

Definition at line 114 of file Configuration.cc.

115 {
116 if (m_databaseInitialized) {
117 Database::Instance().reset(true);
118 }
119 *this = Configuration();
120 }

◆ 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 281 of file Configuration.h.

281{ ensureEditable(); m_downloadCacheDirectory = directory; }

◆ setDownloadLockTimeout()

void setDownloadLockTimeout ( size_t timeout)
inline

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

Definition at line 287 of file Configuration.h.

287{ ensureEditable(); m_downloadLockTimeout = timeout; }

◆ 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 300 of file Configuration.h.

300{ ensureEditable(); m_callback = obj; }

◆ setGlobalTags()

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

Set the list of globaltags.

Definition at line 82 of file Configuration.h.

82{ ensureEditable(); m_globalTags.ensureCpp() = list; }

◆ 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); }

◆ setInitialized()

void setInitialized ( bool value)
inline

Set by the Database singleton upon initialization and cleanup.

Definition at line 305 of file Configuration.h.

305{ 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 {
110 ensureEditable();
111 m_inputGlobaltags = inputTags;
112 }

◆ 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()

Definition at line 137 of file Configuration.cc.

138 {
139 ensureEditable();
140 m_inputMetadata = inputMetadata;
141 // make sure the list of globaltags to be used is created but empty
142 m_inputGlobaltags.emplace();
143 // now check for compatibility: make sure all metadata have the same globaltag
144 // setting. Unless we don't have metadata ...
145 if (inputMetadata.empty()) return;
146
147 std::optional<std::string> inputGlobaltags;
148 for (const auto& metadata : inputMetadata) {
149 if (!inputGlobaltags) {
150 inputGlobaltags = metadata.getDatabaseGlobalTag();
151 } else {
152 if (inputGlobaltags != metadata.getDatabaseGlobalTag()) {
153 B2WARNING("Input files metadata contain incompatible globaltag settings, globaltag replay not possible");
154 // no need to set anything
155 return;
156 }
157 }
158 }
159 // if it's still set and empty we have an empty input list ... warn specifically.
160 if (inputGlobaltags and inputGlobaltags->empty()) {
161 B2WARNING("Input files metadata all have empty globaltag setting, globaltag replay not possible");
162 return;
163 }
164 // set the list of globaltags from the string containing the globaltags
165 boost::split(*m_inputGlobaltags, *inputGlobaltags, boost::is_any_of(","));
166
167 // HACK: So, we successfully set the input globaltags from the input file,
168 // however we also decided that we want to add new payloads for
169 // boost, invariant mass, beam spot, collision axis in CMS.
170 // So if the release is older than when these features were introduced
171 // or if files were produced before specific date, extra GTs are appended.
172 // The appended GTs contain only the possible missing info and are added
173 // with lowest priority.
174 // If the files actually had all payloads these legacy payloads will never
175 // be used as they have lowest priority.
176 // Otherwise this should enable running over old files.
177 //
178 // TODO: Once we're sure all files being used contain all payloads remove this.
179
180 std::optional<std::string> relMin, dateMin;
181
182 for (const auto& metadata : inputMetadata) {
183 // get oldest release
184 std::string rel = metadata.getRelease().substr(0, 10);
185 if (std::regex_match(rel, std::regex("release-[0-9][0-9]"))) {
186 if (!relMin) relMin = rel;
187 relMin = min(*relMin, rel);
188 }
189
190 // get oldest production date
191 std::string date = metadata.getDate().substr(0, 10);
192 if (std::regex_match(date, std::regex("[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]"))) {
193 if (!dateMin) dateMin = date;
194 dateMin = min(*dateMin, date);
195 }
196 }
197
198 // add IP GT if rel older than rel04 or for old files
199 if ((relMin && relMin < "release-04") ||
200 (!relMin && (!dateMin || dateMin < "2019-12-31"))) {
201 B2DEBUG(30, "Enabling legacy IP information globaltag in tag replay");
202 m_inputGlobaltags->emplace_back("Legacy_IP_Information");
203 }
204
205 // add CollisionAxisCMS GT if rel older than rel08 or for old files
206 if ((relMin && relMin < "release-08") ||
207 (!relMin && (!dateMin || dateMin < "2023-08-31"))) {
208 B2DEBUG(30, "Enabling legacy CollsionAxisCMS globaltag in tag replay");
209 m_inputGlobaltags->emplace_back("Legacy_CollisionAxisCMS");
210 }
211 // END TODO/HACK
212 }

◆ setMetadataProviders()

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

Set the list of metadata providers.

Definition at line 226 of file Configuration.h.

226{ ensureEditable(); m_metadataProviders.ensureCpp() = list; }

◆ 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.

228{ ensureEditable(); m_metadataProviders.shallowCopy(list); }

◆ setNewPayloadLocation()

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

Set the file where to save newly created payload information.

Definition at line 275 of file Configuration.h.

275{ ensureEditable(); m_newPayloadFile = filename; }

◆ setPayloadLocations()

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

Set the list of payload locations.

Definition at line 254 of file Configuration.h.

254{ ensureEditable(); m_payloadLocations.ensureCpp() = list; }

◆ setPayloadLocationsPy()

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

Set the list of payload locations in python.

Definition at line 256 of file Configuration.h.

256{ ensureEditable(); m_payloadLocations.shallowCopy(list); }

◆ 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.

198{ ensureEditable(); m_testingPayloadLocations.ensureCpp() = list;}

◆ 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.

200{ ensureEditable(); m_testingPayloadLocations.shallowCopy(list); }

◆ 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 293 of file Configuration.h.

293{ 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 349 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 352 of file Configuration.h.

352{false};

◆ m_defaultLocalMetadataProviderPath

std::string m_defaultLocalMetadataProviderPath {"/cvmfs/belle.cern.ch/conditions"}
private

default local path for the local metadata provider

Definition at line 339 of file Configuration.h.

339{"/cvmfs/belle.cern.ch/conditions"};

◆ m_defaultRemoteMetadataProviderServer

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

default server URL for the remote metadata provider

Definition at line 337 of file Configuration.h.

337{"http://belle2db.sdcc.bnl.gov/b2s/rest/"};

◆ m_downloadCacheDirectory

std::string m_downloadCacheDirectory {""}
private

the directory to put newly downloaded payloads

Definition at line 343 of file Configuration.h.

343{""};

◆ m_downloadLockTimeout

size_t m_downloadLockTimeout {120}
private

the timeout when trying to lock files in the download directory

Definition at line 345 of file Configuration.h.

345{120};

◆ m_globalTags

CppOrPyList m_globalTags
private

the list with all user globaltags

Definition at line 329 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 325 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 327 of file Configuration.h.

◆ m_metadataProviders

CppOrPyList m_metadataProviders
private

the list with all the metadata providers

Definition at line 333 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 341 of file Configuration.h.

341{"localdb/database.txt"};

◆ m_overrideEnabled

bool m_overrideEnabled {false}
private

is the globaltag override enabled?

Definition at line 322 of file Configuration.h.

322{false};

◆ m_payloadLocations

CppOrPyList m_payloadLocations
private

the list with all the payload locations

Definition at line 335 of file Configuration.h.

◆ m_testingPayloadLocations

CppOrPyList m_testingPayloadLocations
private

the files with testing payloads to use during processing

Definition at line 331 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 347 of file Configuration.h.

347{"TESTING", "VALIDATED", "PUBLISHED", "RUNNING"};

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