Belle II Software development
Database Class Reference

Singleton base class for the low-level interface to the database. More...

#include <Database.h>

Classes

struct  DBImportQuery
 Struct for bulk write queries. More...
 

Public Types

enum  EDatabaseState {
  c_PreInit = 0 ,
  c_InitGlobaltagList = 1 ,
  c_Ready = 2
}
 State of the database. More...
 
using DBQuery = Conditions::PayloadMetadata
 Struct for bulk read queries.
 

Public Member Functions

std::pair< TObject *, IntervalOfValiditygetData (const EventMetaData &event, const std::string &name)
 Request an object from the database.
 
bool getData (const EventMetaData &event, DBQuery &query)
 Request an object from the database.
 
bool getData (const EventMetaData &event, std::vector< DBQuery > &query)
 Request multiple objects from the database.
 
const TObject * getData (const std::string &name, int experiment, int run)
 Convenience function to get an object for an arbitrary experiment and run.
 
std::set< std::string > getAllDataNames ()
 Return the names of all the payloads stored in the database at the time of this function is called.
 
bool storeData (const std::string &name, TObject *object, const IntervalOfValidity &iov)
 Store an object in the database.
 
bool storeData (TClonesArray *array, const IntervalOfValidity &iov)
 Store an ClonesArray in the database with the default name.
 
template<class T >
bool storeData (T *object, const IntervalOfValidity &iov)
 Store an object in the database with the default name.
 
bool storeData (std::list< DBImportQuery > &query)
 Store multiple objects in the database.
 
bool addPayload (const std::string &name, const std::string &fileName, const IntervalOfValidity &iov)
 Add a payload file to the database.
 
std::string getGlobalTags ()
 Return the global tags used by the database.
 
ScopeGuard createScopedUpdateSession ()
 Make sure we have efficient http pipelinging during initialize/beginRun but don't keep session alive for full processing time.
 
void initialize (const EDatabaseState target=c_Ready)
 Initialize the database connection settings on first use.
 

Static Public Member Functions

static DatabaseInstance ()
 Instance of a singleton Database.
 
static void reset (bool keepConfig=false)
 Reset the database instance.
 
static void exposePythonAPI ()
 Exposes setGlobalTag function of the Database class to Python.
 

Protected Member Functions

 Database ()=default
 Hidden constructor, as it is a singleton.
 
 Database (const Database &)=delete
 No copy constructor, as it is a singleton.
 
 ~Database ()
 Hidden destructor, as it is a singleton.
 
void nextMetadataProvider ()
 Enable the next metadataprovider in the list.
 

Protected Attributes

std::vector< std::string > m_metadataConfigurations
 List of available metadata providers (which haven't been tried yet)
 
std::string m_currentProvider
 Name of the currently used metadata provider.
 
std::vector< std::string > m_globalTags
 List of globaltags to be used.
 
std::set< std::string > m_usableTagStates
 Set of usable globaltag states to be handed to the metadata providers.
 
std::unique_ptr< Conditions::MetadataProviderm_metadataProvider
 Currently active metadata provider.
 
std::unique_ptr< Conditions::PayloadProviderm_payloadProvider
 The active payload provider.
 
std::unique_ptr< Conditions::TestingPayloadStoragem_payloadCreation
 testing payload storage to create new payloads
 
std::vector< Conditions::TestingPayloadStoragem_testingPayloads
 optional list of testing payload storages to look for existing payloads
 
EDatabaseState m_configState {c_PreInit}
 Current configuration state of the database.
 

Detailed Description

Singleton base class for the low-level interface to the database.

To be used by the DBStore. Currently the Database instance keeps the ownership of the objects, but this may change for the final backend.

Definition at line 42 of file Database.h.

Member Typedef Documentation

◆ DBQuery

Struct for bulk read queries.

Definition at line 72 of file Database.h.

Member Enumeration Documentation

◆ EDatabaseState

State of the database.

Enumerator
c_PreInit 

Before any initialization.

c_InitGlobaltagList 

Globaltag list has been finalized metadata providers not and globaltags are not checked for usability.

c_Ready 

Everything is ready.

Definition at line 45 of file Database.h.

45 {
47 c_PreInit = 0,
51 c_Ready = 2,
52 };
@ c_PreInit
Before any initialization.
Definition: Database.h:47
@ c_InitGlobaltagList
Globaltag list has been finalized metadata providers not and globaltags are not checked for usability...
Definition: Database.h:49
@ c_Ready
Everything is ready.
Definition: Database.h:51

Member Function Documentation

◆ addPayload()

bool addPayload ( const std::string &  name,
const std::string &  fileName,
const IntervalOfValidity iov 
)
inline

Add a payload file to the database.

Parameters
nameName that identifies the object in the database.
fileNameThe name of the payload file.
iovThe interval of validity of the the object.
Returns
True if the storage of the object succeeded.

Definition at line 192 of file Database.h.

193 {
195 return m_payloadCreation->storePayload(name, fileName, iov);
196 }
std::unique_ptr< Conditions::TestingPayloadStorage > m_payloadCreation
testing payload storage to create new payloads
Definition: Database.h:242
void initialize(const EDatabaseState target=c_Ready)
Initialize the database connection settings on first use.
Definition: Database.cc:197

◆ getAllDataNames()

std::set< std::string > getAllDataNames ( )
inline

Return the names of all the payloads stored in the database at the time of this function is called.

This is equivalent to getting all the payloads' names used by the current basf2 process.

Definition at line 146 of file Database.h.

146{ return DBStore::Instance().getAllEntryNames(); };
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
std::set< std::string > getAllEntryNames()
Return the names of all the payloads stored in the database at the time of this function is called.
Definition: DBStore.cc:196

◆ getData() [1/2]

bool getData ( const EventMetaData event,
DBQuery query 
)
inline

Request an object from the database.

Parameters
eventThe metadata of the event for which the object should be valid.
queryObject containing the necessary identification which will be filled with all information about the payload.
Returns
True if the payload could be found. False otherwise.

Definition at line 110 of file Database.h.

111 {
112 std::vector<DBQuery> container{query};
113 bool found = getData(event, container);
114 query = container[0];
115 return found;
116 }
std::pair< TObject *, IntervalOfValidity > getData(const EventMetaData &event, const std::string &name)
Request an object from the database.
Definition: Database.cc:72

◆ getData() [2/2]

const TObject * getData ( const std::string &  name,
int  experiment,
int  run 
)
inline

Convenience function to get an object for an arbitrary experiment and run.

Parameters
[in]nameThe name identifying the object.
[in]experimentThe experiment number.
[in]runThe run number.

Definition at line 135 of file Database.h.

136 {
137 EventMetaData eventMetaData(1, run, experiment);
138 return getData(eventMetaData, name).first;
139 }

◆ storeData() [1/2]

bool storeData ( T *  object,
const IntervalOfValidity iov 
)
inline

Store an object in the database with the default name.

Parameters
objectThe object that should be stored in the database.
iovThe interval of validity of the the object.
Returns
True if the storage of the object succeeded.

Definition at line 174 of file Database.h.

174{return storeData(DBStore::objectName<T>(""), object, iov);};
bool storeData(const std::string &name, TObject *object, const IntervalOfValidity &iov)
Store an object in the database.
Definition: Database.cc:141

◆ storeData() [2/2]

bool storeData ( TClonesArray *  array,
const IntervalOfValidity iov 
)
inline

Store an ClonesArray in the database with the default name.

Parameters
arrayThe object that should be stored in the database.
iovThe interval of validity of the the object.
Returns
True if the storage of the object succeeded.

Definition at line 165 of file Database.h.

165{return storeData(DataStore::defaultArrayName(array->ClassName()), array, iov);};
static std::string defaultArrayName()
Return the default storage name for an array of the given type.
Definition: DataStore.h:157

Member Data Documentation

◆ m_configState

EDatabaseState m_configState {c_PreInit}
protected

Current configuration state of the database.

Definition at line 246 of file Database.h.

◆ m_currentProvider

std::string m_currentProvider
protected

Name of the currently used metadata provider.

Definition at line 232 of file Database.h.

◆ m_globalTags

std::vector<std::string> m_globalTags
protected

List of globaltags to be used.

Definition at line 234 of file Database.h.

◆ m_metadataConfigurations

std::vector<std::string> m_metadataConfigurations
protected

List of available metadata providers (which haven't been tried yet)

Definition at line 230 of file Database.h.

◆ m_metadataProvider

std::unique_ptr<Conditions::MetadataProvider> m_metadataProvider
protected

Currently active metadata provider.

Definition at line 238 of file Database.h.

◆ m_payloadCreation

std::unique_ptr<Conditions::TestingPayloadStorage> m_payloadCreation
protected

testing payload storage to create new payloads

Definition at line 242 of file Database.h.

◆ m_payloadProvider

std::unique_ptr<Conditions::PayloadProvider> m_payloadProvider
protected

The active payload provider.

Definition at line 240 of file Database.h.

◆ m_testingPayloads

std::vector<Conditions::TestingPayloadStorage> m_testingPayloads
protected

optional list of testing payload storages to look for existing payloads

Definition at line 244 of file Database.h.

◆ m_usableTagStates

std::set<std::string> m_usableTagStates
protected

Set of usable globaltag states to be handed to the metadata providers.

Definition at line 236 of file Database.h.


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