Belle II Software  release-05-02-19
DBStoreEntry.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015-2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/database/IntervalOfValidity.h>
13 
14 #include <string>
15 #include <unordered_set>
16 
17 class TFile;
18 
19 namespace Belle2 {
24  class EventMetaData;
25  class IntraRunDependency;
26  class DBAccessorBase;
27 
49  class DBStoreEntry {
50  public:
52  enum EPayloadType {
59  };
68  DBStoreEntry(EPayloadType type, const std::string& name, const TClass* objClass, bool isArray, bool isRequired):
79  static DBStoreEntry fromObject(const std::string& name, const TObject* obj, bool isRequired);
81  DBStoreEntry(const DBStoreEntry&) = delete;
83  DBStoreEntry& operator=(const DBStoreEntry&) = delete;
85  DBStoreEntry(DBStoreEntry&&) = default;
89  ~DBStoreEntry();
91  const std::string& getName() const { return m_name; }
94  unsigned int getRevision() const { return m_revision; }
96  IntervalOfValidity getIoV() const { return m_iov; }
98  const std::string& getFilename() const { return m_filename; }
101  const std::string& getChecksum() const { return m_checksum; }
104  const TObject* getObject() const { return m_object; }
106  const TFile* getTFile() const { return m_tfile; }
108  const TClass* getClass() const { return m_objClass; }
110  bool isArray() const { return m_isArray; }
112  bool isRequired() const { return m_isRequired; }
114  bool keepUntilExpired() const { return m_keep; }
116  bool isIntraRunDependent() const { return (bool)m_intraRunDependency; }
118  void registerAccessor(DBAccessorBase* object) { m_accessors.insert(object); }
120  void removeAccessor(DBAccessorBase* object) { m_accessors.erase(object); }
121 
122  private:
124  void resetPayload();
136  void updatePayload(unsigned int revision, const IntervalOfValidity& iov, const std::string& filename, const std::string& checksum,
137  const EventMetaData& event);
139  void loadPayload(const EventMetaData& event);
145  void updateObject(const EventMetaData& event);
151  void overrideObject(TObject* obj, const IntervalOfValidity& iov);
153  TObject* releaseObject() { TObject* obj{nullptr}; std::swap(obj, m_object); return obj; }
155  bool checkType(const TObject* object) const;
157  bool checkType(EPayloadType type, const TClass* objClass, bool array, bool inverse = false) const;
159  void notifyAccessors(bool onDestruction = false);
161  void require() { m_isRequired = true; }
165  const std::string m_name;
167  const TClass* const m_objClass;
169  const bool m_isArray;
172  bool m_isRequired{false};
175  bool m_keep{false};
177  unsigned int m_revision{0};
181  std::string m_filename{""};
183  std::string m_checksum;
185  TFile* m_tfile{nullptr};
187  TObject* m_object{nullptr};
192  std::unordered_set<DBAccessorBase*> m_accessors;
194  friend class DBStore;
196  friend class Database;
197  };
199 }
200 
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2::DBStoreEntry::m_object
TObject * m_object
Pointer to the actual payload object.
Definition: DBStoreEntry.h:187
Belle2::DBStoreEntry::getFilename
const std::string & getFilename() const
get the filename for this payload
Definition: DBStoreEntry.h:98
Belle2::DBStoreEntry::getChecksum
const std::string & getChecksum() const
get the checksum of the payload.
Definition: DBStoreEntry.h:101
Belle2::DBStoreEntry::m_checksum
std::string m_checksum
checksum of the payload file
Definition: DBStoreEntry.h:183
Belle2::DBStoreEntry::c_Object
@ c_Object
A ROOT file containing a object with the name of the DBStoreEntry.
Definition: DBStoreEntry.h:58
Belle2::DBStoreEntry::isRequired
bool isRequired() const
check whether this payload is required for operation
Definition: DBStoreEntry.h:112
Belle2::DBStoreEntry::require
void require()
Change status of this payload to required.
Definition: DBStoreEntry.h:161
Belle2::DBStoreEntry::m_iov
IntervalOfValidity m_iov
validity of this payload
Definition: DBStoreEntry.h:179
Belle2::DBStoreEntry::getObject
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:104
Belle2::DBStoreEntry
Class to hold one entry from the ConditionsDB in the DBStore.
Definition: DBStoreEntry.h:49
Belle2::DBStoreEntry::m_revision
unsigned int m_revision
revision of this payload
Definition: DBStoreEntry.h:177
Belle2::DBStoreEntry::~DBStoreEntry
~DBStoreEntry()
Clean up memory.
Definition: DBStoreEntry.cc:47
Belle2::DBStoreEntry::removeAccessor
void removeAccessor(DBAccessorBase *object)
Deregister an Accessor object and remove it from the list of registered objects.
Definition: DBStoreEntry.h:120
Belle2::DBStoreEntry::m_isRequired
bool m_isRequired
True if at least one user marked this payload as required, false if this payload is marked optional.
Definition: DBStoreEntry.h:172
Belle2::DBStoreEntry::isArray
bool isArray() const
get whether this payload is an array of objects or a single objects
Definition: DBStoreEntry.h:110
Belle2::DBStoreEntry::m_filename
std::string m_filename
filename containing which contains the actual payload data
Definition: DBStoreEntry.h:181
Belle2::DBStoreEntry::overrideObject
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...
Definition: DBStoreEntry.cc:158
Belle2::DBAccessorBase
Base class for DBObjPtr and DBArray for easier common treatment.
Definition: DBAccessorBase.h:28
Belle2::DBStoreEntry::m_keep
bool m_keep
if True this payload should not be updated unless it's really out of date.
Definition: DBStoreEntry.h:175
Belle2::DBStoreEntry::DBStoreEntry
DBStoreEntry(EPayloadType type, const std::string &name, const TClass *objClass, bool isArray, bool isRequired)
Construct a new DBStoreEntry.
Definition: DBStoreEntry.h:68
Belle2::DBStoreEntry::EPayloadType
EPayloadType
Possible Store entry types.
Definition: DBStoreEntry.h:52
Belle2::DBStoreEntry::m_accessors
std::unordered_set< DBAccessorBase * > m_accessors
Vector of all the accessors registered with this entry.
Definition: DBStoreEntry.h:192
Belle2::DBStoreEntry::m_intraRunDependency
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:190
Belle2::DBStoreEntry::notifyAccessors
void notifyAccessors(bool onDestruction=false)
Notify all the registered accessors.
Definition: DBStoreEntry.cc:188
Belle2::DBStoreEntry::loadPayload
void loadPayload(const EventMetaData &event)
Actual load the payload from file after all info is set.
Definition: DBStoreEntry.cc:114
Belle2::DBStoreEntry::checkType
bool checkType(const TObject *object) const
Check if a given TObject instance is compatible with the type of this entry.
Definition: DBStoreEntry.cc:226
Belle2::DBStoreEntry::updatePayload
void updatePayload(unsigned int revision, const IntervalOfValidity &iov, const std::string &filename, const std::string &checksum, const EventMetaData &event)
Update the payload information for this entry and if appropriate open the new file and extract the ob...
Definition: DBStoreEntry.cc:84
Belle2::DBStoreEntry::operator=
DBStoreEntry & operator=(const DBStoreEntry &)=delete
Also don't just assign them to each other.
Belle2::DBStoreEntry::fromObject
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:40
Belle2::DBStoreEntry::m_isArray
const bool m_isArray
True if this payload is an array of objects.
Definition: DBStoreEntry.h:169
Belle2::DBStore
Singleton class to cache database objects.
Definition: DBStore.h:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DBStoreEntry::m_objClass
const TClass *const m_objClass
Class of this payload.
Definition: DBStoreEntry.h:167
Belle2::DBStoreEntry::getIoV
IntervalOfValidity getIoV() const
get the validity of the payload
Definition: DBStoreEntry.h:96
Belle2::DBStoreEntry::releaseObject
TObject * releaseObject()
Return the pointer to the current object and release ownership: The caller is responsible to clean up...
Definition: DBStoreEntry.h:153
Belle2::DBStoreEntry::getClass
const TClass * getClass() const
get the class of this payload
Definition: DBStoreEntry.h:108
Belle2::IntraRunDependency
Base class for handling changing conditions during a run.
Definition: IntraRunDependency.h:36
Belle2::DBStoreEntry::m_name
const std::string m_name
Name of this payload.
Definition: DBStoreEntry.h:165
Belle2::DBStoreEntry::getTFile
const TFile * getTFile() const
get the ROOT TFile pointer for this payload.
Definition: DBStoreEntry.h:106
Belle2::DBStoreEntry::getName
const std::string & getName() const
get the name of the payload
Definition: DBStoreEntry.h:91
Belle2::Database
Singleton base class for the low-level interface to the database.
Definition: Database.h:44
Belle2::DBStoreEntry::m_payloadType
const EPayloadType m_payloadType
Type of this payload.
Definition: DBStoreEntry.h:163
Belle2::EventMetaData
Store event, run, and experiment numbers.
Definition: EventMetaData.h:43
Belle2::DBStoreEntry::updateObject
void updateObject(const EventMetaData &event)
update the payload object according to the new event information.
Definition: DBStoreEntry.cc:57
Belle2::DBStoreEntry::registerAccessor
void registerAccessor(DBAccessorBase *object)
Register an Accessor object to be notified on changes by calling DBAccessorBase::storeEntryChanged()
Definition: DBStoreEntry.h:118
Belle2::DBStoreEntry::isIntraRunDependent
bool isIntraRunDependent() const
return whether or not the payload might change even during the run
Definition: DBStoreEntry.h:116
Belle2::DBStoreEntry::m_tfile
TFile * m_tfile
Pointer to the open ROOT TFile pointer for m_filename.
Definition: DBStoreEntry.h:185
Belle2::DBStoreEntry::getRevision
unsigned int getRevision() const
get the revision of the payload, this is an abitrary number which indicates the conditions version
Definition: DBStoreEntry.h:94
Belle2::DBStoreEntry::c_RawFile
@ c_RawFile
Just a plain old file, we don't look at it just provide the filename.
Definition: DBStoreEntry.h:54
Belle2::DBStoreEntry::c_ROOTFile
@ c_ROOTFile
Normal ROOT file but no extraction of any specific object.
Definition: DBStoreEntry.h:56
Belle2::DBStoreEntry::keepUntilExpired
bool keepUntilExpired() const
check whether the payload should be kept until expired
Definition: DBStoreEntry.h:114
Belle2::DBStoreEntry::resetPayload
void resetPayload()
reset the payload to nothing
Definition: DBStoreEntry.cc:70