Belle II Software  release-08-01-10
DBStore.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/DBStoreEntry.h>
11 #include <framework/datastore/DataStore.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/dataobjects/EventMetaData.h>
14 
15 #include <optional>
16 #include <set>
17 #include <string>
18 #include <unordered_map>
19 
20 namespace Belle2 {
31  class DBStore {
32  public:
39  static DBStore& Instance();
40 
44  template<class T> static std::string objectName(const std::string& name) { return DataStore::objectName<T>(name); }
45 
46 
50  template<class T> static std::string arrayName(const std::string& name) { return DataStore::arrayName<T>(name); }
51 
53  ~DBStore();
54 
70  DBStoreEntry* getEntry(DBStoreEntry::EPayloadType payloadType, const std::string& name,
71  const TClass* objClass, bool array, bool required = true);
72 
86  DBStoreEntry* getEntry(const std::string& name, const TClass* objClass,
87  bool array, bool required = true)
88  {
89  return getEntry(DBStoreEntry::c_Object, name, objClass, array, required);
90  }
91 
96  void update();
97 
103  void update(const EventMetaData& event);
104 
109  void updateEvent();
110 
117  void updateEvent(const unsigned int eventNumber);
118 
126  void reset(bool keepEntries = false);
127 
133  std::set<std::string> getAllEntryNames();
134 
147  void addConstantOverride(const std::string& name, TObject* obj, bool oneRun = false);
148 
149  private:
151  explicit DBStore() {};
152 
154  DBStore(const DBStore&);
155 
157  void performUpdate(const EventMetaData& event);
158 
163  void performUpdateEvent(const EventMetaData& event);
164 
166  std::unordered_map<std::string, DBStoreEntry> m_dbEntries;
167 
169  std::set<DBStoreEntry*> m_intraRunDependencies;
170 
175 
181  std::optional<EventMetaData> m_manualEvent;
182  };
184 } // namespace Belle2
Class to hold one entry from the ConditionsDB in the DBStore.
Definition: DBStoreEntry.h:47
EPayloadType
Possible Store entry types.
Definition: DBStoreEntry.h:50
@ c_Object
A ROOT file containing a object with the name of the DBStoreEntry.
Definition: DBStoreEntry.h:56
Singleton class to cache database objects.
Definition: DBStore.h:31
StoreObjPtr< EventMetaData > m_storeEvent
StoreObjPtr for the EventMetaData to get the current experiment and run from the DataStore.
Definition: DBStore.h:174
DBStore(const DBStore &)
same for copy constructor
std::set< DBStoreEntry * > m_intraRunDependencies
List of intra-run dependent conditions.
Definition: DBStore.h:169
DBStoreEntry * getEntry(const std::string &name, const TClass *objClass, bool array, bool required=true)
Returns the entry with the requested name in the DBStore.
Definition: DBStore.h:86
std::optional< EventMetaData > m_manualEvent
Optional EventMetaData variable.
Definition: DBStore.h:181
static std::string objectName(const std::string &name)
Return the database name for an object of the given type and name.
Definition: DBStore.h:44
std::unordered_map< std::string, DBStoreEntry > m_dbEntries
Map names to DBEntry objects.
Definition: DBStore.h:166
static std::string arrayName(const std::string &name)
Return the database name for an object of the given type and name.
Definition: DBStore.h:50
DBStore()
Hidden constructor, as it is a singleton.
Definition: DBStore.h:151
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
void reset(bool keepEntries=false)
Invalidate all payloads.
Definition: DBStore.cc:177
~DBStore()
Destructor.
Definition: DBStore.cc:23
void performUpdateEvent(const EventMetaData &event)
The main code that does an updateEvent.
Definition: DBStore.cc:169
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:28
void performUpdate(const EventMetaData &event)
The main code that does an update, factored out so it can be used by both update and update(event).
Definition: DBStore.cc:108
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.
Definition: DBStore.cc:34
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:142
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:79
void addConstantOverride(const std::string &name, TObject *obj, bool oneRun=false)
Add constant override payload.
Definition: DBStore.cc:204
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
Abstract base class for different kinds of events.