Belle II Software  release-05-02-19
DBStore.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2011-2018 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Thomas Kuhr, Marko Staric, Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <framework/database/DBStoreEntry.h>
13 #include <framework/datastore/DataStore.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/dataobjects/EventMetaData.h>
16 
17 #include <boost/optional.hpp>
18 
19 #include <string>
20 #include <unordered_map>
21 #include <set>
22 
23 namespace Belle2 {
34  class DBStore {
35  public:
36 
45  static bool s_DoCleanup;
46 
53  static DBStore& Instance();
54 
58  template<class T> static std::string objectName(const std::string& name) { return DataStore::objectName<T>(name); }
59 
60 
64  template<class T> static std::string arrayName(const std::string& name) { return DataStore::arrayName<T>(name); }
65 
67  ~DBStore();
68 
84  DBStoreEntry* getEntry(DBStoreEntry::EPayloadType payloadType, const std::string& name,
85  const TClass* objClass, bool array, bool required = true);
86 
100  DBStoreEntry* getEntry(const std::string& name, const TClass* objClass,
101  bool array, bool required = true)
102  {
103  return getEntry(DBStoreEntry::c_Object, name, objClass, array, required);
104  }
105 
110  void update();
111 
117  void update(const EventMetaData& event);
118 
123  void updateEvent();
124 
131  void updateEvent(const unsigned int eventNumber);
132 
140  void reset(bool keepEntries = false);
141 
154  void addConstantOverride(const std::string& name, TObject* obj, bool oneRun = false);
155 
156  private:
158  explicit DBStore() {};
159 
161  DBStore(const DBStore&);
162 
164  void performUpdate(const EventMetaData& event);
165 
170  void performUpdateEvent(const EventMetaData& event);
171 
173  std::unordered_map<std::string, DBStoreEntry> m_dbEntries;
174 
176  std::set<DBStoreEntry*> m_intraRunDependencies;
177 
182 
188  boost::optional<EventMetaData> m_manualEvent;
189  };
191 } // namespace Belle2
Belle2::DBStoreEntry::c_Object
@ c_Object
A ROOT file containing a object with the name of the DBStoreEntry.
Definition: DBStoreEntry.h:58
Belle2::DBStore::addConstantOverride
void addConstantOverride(const std::string &name, TObject *obj, bool oneRun=false)
Add constant override payload.
Definition: DBStore.cc:204
Belle2::DBStore::arrayName
static std::string arrayName(const std::string &name)
Return the database name for an object of the given type and name.
Definition: DBStore.h:72
Belle2::DBStore::reset
void reset(bool keepEntries=false)
Invalidate all payloads.
Definition: DBStore.cc:185
Belle2::DBStoreEntry::EPayloadType
EPayloadType
Possible Store entry types.
Definition: DBStoreEntry.h:52
Belle2::DBStore::getEntry
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:42
Belle2::DBStore::performUpdate
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:116
Belle2::DBStore::objectName
static std::string objectName(const std::string &name)
Return the database name for an object of the given type and name.
Definition: DBStore.h:66
Belle2::DBStore::m_storeEvent
StoreObjPtr< EventMetaData > m_storeEvent
StoreObjPtr for the EventMetaData to get the current experiment and run from the DataStore.
Definition: DBStore.h:189
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::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::DBStore::~DBStore
~DBStore()
Destructor.
Definition: DBStore.cc:31
Belle2::DBStore::Instance
static DBStore & Instance()
Instance of a singleton DBStore.
Definition: DBStore.cc:36
Belle2::DBStore::m_dbEntries
std::unordered_map< std::string, DBStoreEntry > m_dbEntries
Map names to DBEntry objects.
Definition: DBStore.h:181
Belle2::DBStore::updateEvent
void updateEvent()
Updates all intra-run dependent objects.
Definition: DBStore.cc:150
Belle2::DBStore::performUpdateEvent
void performUpdateEvent(const EventMetaData &event)
The main code that does an updateEvent.
Definition: DBStore.cc:177
Belle2::DBStore::m_manualEvent
boost::optional< EventMetaData > m_manualEvent
Optional EventMetaData variable.
Definition: DBStore.h:196
Belle2::DBStore::DBStore
DBStore()
Hidden constructor, as it is a singleton.
Definition: DBStore.h:166
Belle2::DBStore::m_intraRunDependencies
std::set< DBStoreEntry * > m_intraRunDependencies
List of intra-run dependent conditions.
Definition: DBStore.h:184
Belle2::DBStore::s_DoCleanup
static bool s_DoCleanup
Global flag to decide if we can do normal cleanup.
Definition: DBStore.h:53
Belle2::DBStore::update
void update()
Updates all objects that are outside their interval of validity.
Definition: DBStore.cc:87