10#include <framework/database/DBStore.h>
11#include <framework/logging/Logger.h>
74 inline operator bool()
const {
return isValid();}
85 return !(*
this == other);
105 void addCallback(std::function<
void(
const std::string&)> callback,
bool onDestruction =
false)
118 void addCallback(std::function<
void()> callback,
bool onDestruction =
false)
120 addCallback([callback](
const std::string&) ->
void { callback(); }, onDestruction);
130 template<
class T>
void addCallback(T*
object,
void(T::*callback)())
132 addCallback([ = ](
const std::string&) {(*
object.*callback)();});
174 B2DEBUG(32,
"DBAccessor " <<
m_name <<
" lost connection, reattaching");
189 if (destructed)
m_entry =
nullptr;
194 if (destructed == cb.second) cb.first(
m_name);
213 std::vector<std::pair<std::function<void(
const std::string&)>,
bool>>
m_callbacks;
Base class for DBObjPtr and DBArray for easier common treatment.
bool m_changed
Internal flag whether the object has changed since we last checked.
virtual bool operator!=(const DBAccessorBase &other) const
Check if two store accessors point to a different object/array.
const TClass * m_objClass
Class of the payload if type is c_Object.
DBAccessorBase(DBStoreEntry::EPayloadType type, const std::string &name, bool isRequired)
Constructor to access an object in the DBStore which is not a ROOT Object.
virtual ~DBAccessorBase()
Destructor.
const std::string & getFilename() const
Get the filename this object is loaded from.
const std::string & getName() const
Return name under which the object is saved in the DBStore.
bool isIntraRunDependent() const
Check wether this conditions object has some intra-run dependencies.
std::vector< std::pair< std::function< void(const std::string &)>, bool > > m_callbacks
List of all registered callback functions.
DBAccessorBase(const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Constructor to access an object in the DBStore.
void addCallback(std::function< void(const std::string &)> callback, bool onDestruction=false)
Add a callback method.
bool isValid() const
Check whether a valid object was obtained from the database.
const std::string m_name
Name of the payload in the database.
IntervalOfValidity getIoV() const
Return current IoV of the object.
DBStoreEntry * m_entry
Pointer to the entry in the DBStore.
bool hasChanged()
Check whether the object has changed since the last call to hasChanged of the accessor).
unsigned int getRevision() const
Return current revision of the object.
bool ensureAttached() const
Make sure we are attached to the the DBStore.
bool isRequired() const
Check whether this conditions object is required (at least one user declared it as required)
void addCallback(std::function< void()> callback, bool onDestruction=false)
Add a callback method.
void storeEntryChanged(bool destructed)
Callback function which gets called by the DBStoreEntry object if it changes.
const std::vector< unsigned int > getIntraRunBoundaries() const
Get the intra-run boundaries, if any.
const T * getObject() const
Return a pointer to the Object already cast to the correct type.
const std::string & getGlobaltag() const
Return the globaltag name (or testing payloads path) this object is loaded from.
const bool m_isArray
True if the payload is an array of objects.
const std::string & getChecksum() const
Get current checksum.
void addCallback(T *object, void(T::*callback)())
Add a callback method of an object.
const DBStoreEntry::EPayloadType m_type
Type of the payload.
virtual bool operator==(const DBAccessorBase &other) const
Check if two store accessors point to the same object/array.
const bool m_isRequired
True if the payload is required, otherwise no errors will be raised if it cannot be found.
Class to hold one entry from the ConditionsDB in the DBStore.
void removeAccessor(DBAccessorBase *object)
Deregister an Accessor object and remove it from the list of registered objects.
EPayloadType
Possible Store entry types.
const std::string & getFilename() const
get the filename for this payload
bool isIntraRunDependent() const
return whether or not the payload might change even during the run
void registerAccessor(DBAccessorBase *object)
Register an Accessor object to be notified on changes by calling DBAccessorBase::storeEntryChanged()
IntervalOfValidity getIoV() const
get the validity of the payload
unsigned int getRevision() const
get the revision of the payload, this is an abitrary number which indicates the conditions version
bool isRequired() const
check whether this payload is required for operation
const TObject * getObject() const
get the object for this payload, can be nullptr if the payload is not loaded or not of type c_Object
const std::vector< unsigned int > getIntraRunBoundaries() const
return the boundaries of the intra-run changes of the payload, if any
const std::string & getGlobaltag() const
get the globaltag name (or testing payloads path) from which the payload is picked.
const std::string & getChecksum() const
get the checksum of the payload.
Singleton class to cache database objects.
A class that describes the interval of experiments/runs for which an object in the database is valid.
static DBStore & Instance()
Instance of a singleton DBStore.
DBStoreEntry * getEntry(DBStoreEntry::EPayloadType payloadType, const std::string &name, const TClass *objClass, bool array, bool required=true)
Returns the entry with the requested name in the DBStore.
Abstract base class for different kinds of events.