Belle II Software  release-06-01-15
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 <boost/optional.hpp>
16 
17 #include <string>
18 #include <unordered_map>
19 #include <set>
20 
21 namespace Belle2 {
32  class DBStore {
33  public:
40  static DBStore& Instance();
41 
45  template<class T> static std::string objectName(const std::string& name) { return DataStore::objectName<T>(name); }
46 
47 
51  template<class T> static std::string arrayName(const std::string& name) { return DataStore::arrayName<T>(name); }
52 
54  ~DBStore();
55 
71  DBStoreEntry* getEntry(DBStoreEntry::EPayloadType payloadType, const std::string& name,
72  const TClass* objClass, bool array, bool required = true);
73 
87  DBStoreEntry* getEntry(const std::string& name, const TClass* objClass,
88  bool array, bool required = true)
89  {
90  return getEntry(DBStoreEntry::c_Object, name, objClass, array, required);
91  }
92 
97  void update();
98 
104  void update(const EventMetaData& event);
105 
110  void updateEvent();
111 
118  void updateEvent(const unsigned int eventNumber);
119 
127  void reset(bool keepEntries = false);
128 
141  void addConstantOverride(const std::string& name, TObject* obj, bool oneRun = false);
142 
143  private:
145  explicit DBStore() {};
146 
148  DBStore(const DBStore&);
149 
151  void performUpdate(const EventMetaData& event);
152 
157  void performUpdateEvent(const EventMetaData& event);
158 
160  std::unordered_map<std::string, DBStoreEntry> m_dbEntries;
161 
163  std::set<DBStoreEntry*> m_intraRunDependencies;
164 
169 
175  boost::optional<EventMetaData> m_manualEvent;
176  };
178 } // 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:32
StoreObjPtr< EventMetaData > m_storeEvent
StoreObjPtr for the EventMetaData to get the current experiment and run from the DataStore.
Definition: DBStore.h:168
boost::optional< EventMetaData > m_manualEvent
Optional EventMetaData variable.
Definition: DBStore.h:175
DBStore(const DBStore &)
same for copy constructor
std::set< DBStoreEntry * > m_intraRunDependencies
List of intra-run dependent conditions.
Definition: DBStore.h:163
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:87
static std::string objectName(const std::string &name)
Return the database name for an object of the given type and name.
Definition: DBStore.h:45
std::unordered_map< std::string, DBStoreEntry > m_dbEntries
Map names to DBEntry objects.
Definition: DBStore.h:160
static std::string arrayName(const std::string &name)
Return the database name for an object of the given type and name.
Definition: DBStore.h:51
DBStore()
Hidden constructor, as it is a singleton.
Definition: DBStore.h:145
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
void reset(bool keepEntries=false)
Invalidate all payloads.
Definition: DBStore.cc:175
~DBStore()
Destructor.
Definition: DBStore.cc:21
void performUpdateEvent(const EventMetaData &event)
The main code that does an updateEvent.
Definition: DBStore.cc:167
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:26
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:106
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:32
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:140
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:77
void addConstantOverride(const std::string &name, TObject *obj, bool oneRun=false)
Add constant override payload.
Definition: DBStore.cc:194
Abstract base class for different kinds of events.