![]() |
Belle II Software
release-05-01-25
|
Type-safe access to single objects in the data store. More...
#include <StoreObjPtr.h>
Public Member Functions | |
StoreObjPtr (const std::string &name="", DataStore::EDurability durability=DataStore::c_Event) | |
Constructor to access an object in the DataStore. More... | |
bool | isValid () const |
Check whether the object was created. More... | |
template<class ... Args> | |
bool | construct (Args &&... params) |
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments. More... | |
template<class ... Args> | |
bool | constructAndReplace (Args &&... params) |
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments. More... | |
Static Public Member Functions | |
static std::vector< std::string > | getObjectList (DataStore::EDurability durability=DataStore::c_Event) |
Return list of object names with matching type. More... | |
Private Member Functions | |
void | ensureAttached () const |
Ensure that this object is attached. | |
void | ensureValid () const |
if accesses to this object would crash, throw an std::runtime_error | |
Private Attributes | |
TObject ** | m_storeObjPtr |
Store of actual pointer. More... | |
Type-safe access to single objects in the data store.
This class provides access to single (i.e. non-array) objects in the data store, identified by their name and durability.
This example creates a new StoreObjPtr for the EventMetaData object, using the default name (EventMetaData) and default durability (event). If no object 'EventMetaData' is found in the data store, the store object pointer is invalid (accesses to it will cause an exception).
First, objects have to be registered in the data store during the initialization phase, meaning in the initialize method of a module:
Before objects can be accessed they have to be created (in each event if the durability is c_Event):
To put an existing object in the data store, use the assign method:
Note that the datastore takes ownership of the object!
To avoid some overhead involved in re-creating the StoreObjPtr e.g. in each event() function call, you can also make StoreObjPtr a member variable of your class. If it is of non-event durability, you'll need to add the appropriate constructor call to the initializer list, e.g. (here with default name):
In initialize(), you should also use registerInDataStore() or isOptional()/isRequired() to specify wether it is an input or output. For non-default names (which you might not know in the constructor, e.g. in the case of module parameters), set the 'name' argument of any of these three functions to permanently bind the StoreObjPtr to the array with the given name.
Definition at line 33 of file ParticleList.h.
|
inlineexplicit |
Constructor to access an object in the DataStore.
name | Name under which the object is stored in the DataStore. If an empty string is supplied, the type name will be used. |
durability | Decides durability map used for getting the accessed object. |
Definition at line 113 of file StoreObjPtr.h.
|
inline |
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
If this StoreObjPtr already contains an object, this function will fail.
Definition at line 128 of file StoreObjPtr.h.
|
inline |
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments.
If this StoreObjPtr already contains an object, it will be replaced.
Definition at line 140 of file StoreObjPtr.h.
|
inlinestatic |
|
inline |
Check whether the object was created.
Definition at line 120 of file StoreObjPtr.h.
|
private |
Store of actual pointer.
Don't make this a T** as this might cause problems with multiple inheritance objects
Definition at line 175 of file StoreObjPtr.h.