Belle II Software  release-05-02-19
PyStoreObj.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2012 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Pulvermacher *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <framework/datastore/DataStore.h>
14 #include <framework/datastore/StoreAccessorBase.h>
15 
16 #include <string>
17 #include <vector>
18 
19 class TClass;
20 class TObject;
21 
22 namespace Belle2 {
69  class PyStoreObj {
70  public:
72  static std::vector<std::string> list(DataStore::EDurability durability = DataStore::EDurability::c_Event);
73 
75  static void printList(DataStore::EDurability durability = DataStore::EDurability::c_Event);
76 
81  explicit PyStoreObj(const std::string& name,
82  DataStore::EDurability durability = DataStore::EDurability::c_Event);
83 
88  explicit PyStoreObj(TClass* objClass,
89  DataStore::EDurability durability = DataStore::EDurability::c_Event);
90 
96  explicit PyStoreObj(TClass* objClass,
97  const std::string& name,
98  DataStore::EDurability durability = DataStore::EDurability::c_Event);
99 
107 
115  bool registerInDataStore(const std::string& name = "",
116  DataStore::EStoreFlags storeFlags = DataStore::EStoreFlags::c_WriteOut);
117 
125  bool isRequired(const std::string& name = "");
126 
135  bool isOptional(const std::string& name = "");
136 
138  bool hasValidClass() const;
139 
141  bool isValid() const;
142 
147  operator bool() const { return isValid(); }
148 
150  TObject* obj() const { ensureAttached(); return isValid() ? m_storeEntry->ptr : nullptr; }
151 
153  TObject* operator->() const { return obj(); }
154 
161  bool assign(TObject* object, bool replace = false);
162 
163  public:
169  bool create(bool replace = false);
170 
171  private:
173  void ensureAttached() const;
174 
176  void attach() const;
177 
178  private:
181 
183  mutable StoreEntry* m_storeEntry = nullptr;
184  };
186 }
Belle2::PyStoreObj::registerInDataStore
bool registerInDataStore(DataStore::EStoreFlags storeFlags)
Register the object in the DataStore.
Definition: PyStoreObj.cc:58
Belle2::PyStoreObj::obj
TObject * obj() const
Returns the attached DataStore object, or nullptr if no valid object exists.
Definition: PyStoreObj.h:150
Belle2::PyStoreObj::isValid
bool isValid() const
Check whether the object was registered and created.
Definition: PyStoreObj.cc:85
Belle2::PyStoreObj::PyStoreObj
PyStoreObj(const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event)
constructor.
Definition: PyStoreObj.cc:33
Belle2::PyStoreObj::list
static std::vector< std::string > list(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Return list of available objects for given durability.
Definition: PyStoreObj.cc:21
Belle2::DataStore::EStoreFlags
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:71
Belle2::StoreEntry
Wraps a stored array/object, stored under unique (name, durability) key.
Definition: StoreEntry.h:15
Belle2::PyStoreObj::printList
static void printList(DataStore::EDurability durability=DataStore::EDurability::c_Event)
Print list of available objects for given durability.
Definition: PyStoreObj.cc:26
Belle2::StoreAccessorBase
Base class for StoreObjPtr and StoreArray for easier common treatment.
Definition: StoreAccessorBase.h:29
Belle2::PyStoreObj
a (simplified) python wrapper for StoreObjPtr.
Definition: PyStoreObj.h:69
Belle2::PyStoreObj::m_storeEntry
StoreEntry * m_storeEntry
Pointer to the DataStore entry - serves as an internal cache omitting repeated look up from the DataS...
Definition: PyStoreObj.h:183
Belle2::PyStoreObj::operator->
TObject * operator->() const
Returns the attached DataStore object, or nullptr if no valid object exists.
Definition: PyStoreObj.h:153
Belle2::PyStoreObj::hasValidClass
bool hasValidClass() const
Check whether a TClass for the contained object could be determined.
Definition: PyStoreObj.cc:90
Belle2::PyStoreObj::ensureAttached
void ensureAttached() const
Ensure that contained TObject has been attached to a memory location on the DataStore.
Definition: PyStoreObj.cc:118
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PyStoreObj::isOptional
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
Definition: PyStoreObj.cc:80
Belle2::PyStoreObj::m_storeAccessor
StoreAccessorBase m_storeAccessor
Store accessor to retrieve the object.
Definition: PyStoreObj.h:180
Belle2::PyStoreObj::create
bool create(bool replace=false)
Create default constructed object in the DataStore.
Definition: PyStoreObj.cc:96
Belle2::StoreEntry::ptr
TObject * ptr
The pointer to the returned object, either equal to 'object' or null, depending on wether the object ...
Definition: StoreEntry.h:44
Belle2::PyStoreObj::isRequired
bool isRequired(const std::string &name="")
Ensure this object has been registered previously.
Definition: PyStoreObj.cc:75
Belle2::PyStoreObj::attach
void attach() const
Lookup the store entry and cache a pointer to it.
Definition: PyStoreObj.cc:128
Belle2::PyStoreObj::assign
bool assign(TObject *object, bool replace=false)
Assign 'object' to the accessor.
Definition: PyStoreObj.cc:133
Belle2::DataStore::EDurability
EDurability
Durability types.
Definition: DataStore.h:60