Belle II Software light-2505-deimos
DBStoreEntry.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/database/IntervalOfValidity.h>
11#include <framework/database/IntraRunDependency.h>
12
13#include <string>
14#include <unordered_set>
15
16class TFile;
17
18namespace Belle2 {
23 class EventMetaData;
24 class DBAccessorBase;
25
48 public:
58
68 DBStoreEntry(EPayloadType type, const std::string& name, const TClass* objClass, bool isArray, bool isRequired):
70
80 static DBStoreEntry fromObject(const std::string& name, const TObject* obj, bool isRequired);
82 DBStoreEntry(const DBStoreEntry&) = delete;
92 const std::string& getName() const { return m_name; }
94 const std::string& getGlobaltag() const { return m_globaltag; }
97 unsigned int getRevision() const { return m_revision; }
99 IntervalOfValidity getIoV() const { return m_iov; }
101 const std::string& getFilename() const { return m_filename; }
104 const std::string& getChecksum() const { return m_checksum; }
107 const TObject* getObject() const { return m_object; }
109 const TFile* getTFile() const { return m_tfile; }
111 const TClass* getClass() const { return m_objClass; }
113 bool isArray() const { return m_isArray; }
115 bool isRequired() const { return m_isRequired; }
117 bool keepUntilExpired() const { return m_keep; }
119 bool isIntraRunDependent() const { return (bool)m_intraRunDependency; }
121 const std::vector<unsigned int> getIntraRunBoundaries() const { if (isIntraRunDependent()) return m_intraRunDependency->getBoundaries(); return std::vector<unsigned int> {}; }
123 void registerAccessor(DBAccessorBase* object) { m_accessors.insert(object); }
125 void removeAccessor(DBAccessorBase* object) { m_accessors.erase(object); }
126
127 private:
129 void resetPayload();
144 void updatePayload(unsigned int revision, const IntervalOfValidity& iov, const std::string& filename, const std::string& checksum,
145 const std::string& globaltag, const EventMetaData& event);
147 void loadPayload(const EventMetaData& event);
153 void updateObject(const EventMetaData& event);
159 void overrideObject(TObject* obj, const IntervalOfValidity& iov);
161 TObject* releaseObject() { TObject* obj{nullptr}; std::swap(obj, m_object); return obj; }
163 bool checkType(const TObject* object) const;
165 bool checkType(EPayloadType type, const TClass* objClass, bool array, bool inverse = false) const;
167 void notifyAccessors(bool onDestruction = false);
169 void require() { m_isRequired = true; }
173 const std::string m_name;
175 const TClass* const m_objClass;
177 const bool m_isArray;
180 bool m_isRequired{false};
183 bool m_keep{false};
185 std::string m_globaltag{""};
187 unsigned int m_revision{0};
191 std::string m_filename{""};
193 std::string m_checksum;
195 TFile* m_tfile{nullptr};
197 TObject* m_object{nullptr};
202 std::unordered_set<DBAccessorBase*> m_accessors;
204 friend class DBStore;
206 friend class Database;
207 };
208
209}
Base class for DBObjPtr and DBArray for easier common treatment.
Class to hold one entry from the ConditionsDB in the DBStore.
bool keepUntilExpired() const
check whether the payload should be kept until expired
void removeAccessor(DBAccessorBase *object)
Deregister an Accessor object and remove it from the list of registered objects.
const TClass * getClass() const
get the class of this payload
std::unordered_set< DBAccessorBase * > m_accessors
Vector of all the accessors registered with this entry.
const TFile * getTFile() const
get the ROOT TFile pointer for this payload.
EPayloadType
Possible Store entry types.
@ c_RawFile
Just a plain old file, we don't look at it just provide the filename.
@ c_ROOTFile
Normal ROOT file but no extraction of any specific object.
@ c_Object
A ROOT file containing a object with the name of the DBStoreEntry.
const std::string & getFilename() const
get the filename for this payload
const std::string & getName() const
get the name of the payload
bool isIntraRunDependent() const
return whether or not the payload might change even during the run
IntraRunDependency * m_intraRunDependency
If the payload has intra run dependency this will point to the whole payload and m_object will just p...
DBStoreEntry(const DBStoreEntry &)=delete
Don't copy the entries around.
IntervalOfValidity m_iov
validity of this payload
unsigned int m_revision
revision of this payload
void registerAccessor(DBAccessorBase *object)
Register an Accessor object to be notified on changes by calling DBAccessorBase::storeEntryChanged()
DBStoreEntry(EPayloadType type, const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Construct a new DBStoreEntry.
std::string m_checksum
checksum of the payload file
DBStoreEntry & operator=(const DBStoreEntry &)=delete
Also don't just assign them to each other.
friend class Database
Also allow the Database class to return TObject* pointers for now.
const std::string m_name
Name of this payload.
IntervalOfValidity getIoV() const
get the validity of the payload
TObject * releaseObject()
Return the pointer to the current object and release ownership: The caller is responsible to clean up...
void require()
Change status of this payload to required.
bool m_keep
if True this payload should not be updated unless it's really out of date.
unsigned int getRevision() const
get the revision of the payload, this is an arbitrary number which indicates the conditions version
bool isRequired() const
check whether this payload is required for operation
const EPayloadType m_payloadType
Type of this payload.
TFile * m_tfile
Pointer to the open ROOT TFile pointer for m_filename.
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
std::string m_filename
filename containing which contains the actual payload data
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 bool m_isArray
True if this payload is an array of objects.
const std::string & getChecksum() const
get the checksum of the payload.
std::string m_globaltag
globaltag name (or testing payloads path) from which this payload is picked.
bool isArray() const
get whether this payload is an array of objects or a single objects
const TClass *const m_objClass
Class of this payload.
friend class DBStore
Allow only the DBStore class to update the payload contents.
DBStoreEntry(DBStoreEntry &&)=default
But we're fine with moving them.
TObject * m_object
Pointer to the actual payload object.
bool m_isRequired
True if at least one user marked this payload as required, false if this payload is marked optional.
Store event, run, and experiment numbers.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Base class for handling changing conditions during a run.
void notifyAccessors(bool onDestruction=false)
Notify all the registered accessors.
void resetPayload()
reset the payload to nothing
bool checkType(const TObject *object) const
Check if a given TObject instance is compatible with the type of this entry.
void updateObject(const EventMetaData &event)
update the payload object according to the new event information.
~DBStoreEntry()
Clean up memory.
void overrideObject(TObject *obj, const IntervalOfValidity &iov)
Set an override object in case we want to use a different object then actually provided by the databa...
static DBStoreEntry fromObject(const std::string &name, const TObject *obj, bool isRequired)
Construct a new DBStoreEntry with a requested name and an object directly.
void loadPayload(const EventMetaData &event)
Actual load the payload from file after all info is set.
void updatePayload(unsigned int revision, const IntervalOfValidity &iov, const std::string &filename, const std::string &checksum, const std::string &globaltag, const EventMetaData &event)
Update the payload information for this entry and if appropriate open the new file and extract the ob...
Abstract base class for different kinds of events.