Belle II Software light-2406-ragdoll
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:
57 };
68 DBStoreEntry(EPayloadType type, const std::string& name, const TClass* objClass, bool isArray, bool isRequired):
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 };
209}
Base class for DBObjPtr and DBArray for easier common treatment.
Class to hold one entry from the ConditionsDB in the DBStore.
Definition: DBStoreEntry.h:47
bool keepUntilExpired() const
check whether the payload should be kept until expired
Definition: DBStoreEntry.h:117
void removeAccessor(DBAccessorBase *object)
Deregister an Accessor object and remove it from the list of registered objects.
Definition: DBStoreEntry.h:125
const TClass * getClass() const
get the class of this payload
Definition: DBStoreEntry.h:111
std::unordered_set< DBAccessorBase * > m_accessors
Vector of all the accessors registered with this entry.
Definition: DBStoreEntry.h:202
const TFile * getTFile() const
get the ROOT TFile pointer for this payload.
Definition: DBStoreEntry.h:109
EPayloadType
Possible Store entry types.
Definition: DBStoreEntry.h:50
@ c_RawFile
Just a plain old file, we don't look at it just provide the filename.
Definition: DBStoreEntry.h:52
@ c_ROOTFile
Normal ROOT file but no extraction of any specific object.
Definition: DBStoreEntry.h:54
@ c_Object
A ROOT file containing a object with the name of the DBStoreEntry.
Definition: DBStoreEntry.h:56
const std::string & getFilename() const
get the filename for this payload
Definition: DBStoreEntry.h:101
const std::string & getName() const
get the name of the payload
Definition: DBStoreEntry.h:92
bool isIntraRunDependent() const
return whether or not the payload might change even during the run
Definition: DBStoreEntry.h:119
IntraRunDependency * m_intraRunDependency
If the payload has intra run dependency this will point to the whole payload and m_object will just p...
Definition: DBStoreEntry.h:200
DBStoreEntry(const DBStoreEntry &)=delete
Don't copy the entries around.
IntervalOfValidity m_iov
validity of this payload
Definition: DBStoreEntry.h:189
unsigned int m_revision
revision of this payload
Definition: DBStoreEntry.h:187
void registerAccessor(DBAccessorBase *object)
Register an Accessor object to be notified on changes by calling DBAccessorBase::storeEntryChanged()
Definition: DBStoreEntry.h:123
DBStoreEntry(EPayloadType type, const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Construct a new DBStoreEntry.
Definition: DBStoreEntry.h:68
std::string m_checksum
checksum of the payload file
Definition: DBStoreEntry.h:193
DBStoreEntry & operator=(const DBStoreEntry &)=delete
Also don't just assign them to each other.
const std::string m_name
Name of this payload.
Definition: DBStoreEntry.h:173
IntervalOfValidity getIoV() const
get the validity of the payload
Definition: DBStoreEntry.h:99
TObject * releaseObject()
Return the pointer to the current object and release ownership: The caller is responsible to clean up...
Definition: DBStoreEntry.h:161
void require()
Change status of this payload to required.
Definition: DBStoreEntry.h:169
bool m_keep
if True this payload should not be updated unless it's really out of date.
Definition: DBStoreEntry.h:183
unsigned int getRevision() const
get the revision of the payload, this is an abitrary number which indicates the conditions version
Definition: DBStoreEntry.h:97
bool isRequired() const
check whether this payload is required for operation
Definition: DBStoreEntry.h:115
const EPayloadType m_payloadType
Type of this payload.
Definition: DBStoreEntry.h:171
TFile * m_tfile
Pointer to the open ROOT TFile pointer for m_filename.
Definition: DBStoreEntry.h:195
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
Definition: DBStoreEntry.h:107
std::string m_filename
filename containing which contains the actual payload data
Definition: DBStoreEntry.h:191
const std::vector< unsigned int > getIntraRunBoundaries() const
return the boundaries of the intra-run changes of the payload, if any
Definition: DBStoreEntry.h:121
const std::string & getGlobaltag() const
get the globaltag name (or testing payloads path) from which the payload is picked.
Definition: DBStoreEntry.h:94
const bool m_isArray
True if this payload is an array of objects.
Definition: DBStoreEntry.h:177
const std::string & getChecksum() const
get the checksum of the payload.
Definition: DBStoreEntry.h:104
std::string m_globaltag
globaltag name (or testing payloads path) from which this payload is picked.
Definition: DBStoreEntry.h:185
bool isArray() const
get whether this payload is an array of objects or a single objects
Definition: DBStoreEntry.h:113
const TClass *const m_objClass
Class of this payload.
Definition: DBStoreEntry.h:175
DBStoreEntry(DBStoreEntry &&)=default
But we're fine with moving them.
TObject * m_object
Pointer to the actual payload object.
Definition: DBStoreEntry.h:197
bool m_isRequired
True if at least one user marked this payload as required, false if this payload is marked optional.
Definition: DBStoreEntry.h:180
Singleton class to cache database objects.
Definition: DBStore.h:31
Singleton base class for the low-level interface to the database.
Definition: Database.h:42
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
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.
virtual const std::vector< unsigned int > & getBoundaries() const =0
Get a vector with the intra-run boundaries.
void notifyAccessors(bool onDestruction=false)
Notify all the registered accessors.
void resetPayload()
reset the payload to nothing
Definition: DBStoreEntry.cc:68
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.
Definition: DBStoreEntry.cc:55
~DBStoreEntry()
Clean up memory.
Definition: DBStoreEntry.cc:45
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.
Definition: DBStoreEntry.cc:37
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...
Definition: DBStoreEntry.cc:83
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24