Belle II Software light-2406-ragdoll
|
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. | |
bool | isValid () const |
Check whether the object was created. | |
template<class ... Args> | |
bool | construct (Args &&... params) |
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments. | |
template<class ... Args> | |
bool | constructAndReplace (Args &&... params) |
Construct an object of type T in this StoreObjPtr, using the provided constructor arguments. | |
T & | operator* () const |
Imitate pointer functionality. | |
T * | operator-> () const |
Imitate pointer functionality. | |
operator bool () const | |
Imitate pointer functionality. | |
bool | registerInDataStore (DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut) |
Register the object/array in the DataStore. | |
bool | registerInDataStore (const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut) |
Register the object/array in the DataStore. | |
bool | isRequired (const std::string &name="") |
Ensure this array/object has been registered previously. | |
bool | isOptional (const std::string &name="") |
Tell the DataStore about an optional input. | |
bool | create (bool replace=false) |
Create a default object in the data store. | |
bool | assign (TObject *object, bool replace=false) |
Assign 'object' to this accessor. | |
virtual void | clear () |
Clear contents of this object. | |
const std::string & | getName () const |
Return name under which the object is saved in the DataStore. | |
DataStore::EDurability | getDurability () const |
Return durability with which the object is saved in the DataStore. | |
AccessorParams | getAccessorParams () const |
Return pair of name and durability under which stored object is saved. | |
virtual bool | operator== (const StoreAccessorBase &other) const |
Check if two store accessors point to the same object/array. | |
virtual bool | operator!= (const StoreAccessorBase &other) const |
Check if two store accessors point to a different object/array. | |
TClass * | getClass () const |
The underlying object's type. | |
bool | isArray () const |
Is this an accessor for an array? | |
bool | notWrittenOut () const |
Returns true if this object/array should not be saved by output modules. | |
std::string | readableName () const |
Convert this acessor into a readable string (for messages). | |
Static Public Member Functions | |
static std::vector< std::string > | getObjectList (DataStore::EDurability durability=DataStore::c_Event) |
Return list of object names with matching type. | |
Protected Attributes | |
std::string | m_name |
Store name under which this object/array is saved. | |
DataStore::EDurability | m_durability |
Store durability under which the object/array is saved. | |
TClass * | m_class |
The underlying object's type. | |
bool | m_isArray |
Is this an accessor for an array? | |
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. | |
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 96 of file StoreObjPtr.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 104 of file StoreObjPtr.h.
|
inherited |
Assign 'object' to this accessor.
(takes ownership).
object | The object that should be put in the DataStore, should be of same type as the one used by this accessor. |
replace | Should an existing object be replaced? (if existing and supplied object are equal, this has no effect) |
Definition at line 33 of file StoreAccessorBase.cc.
|
inlinevirtualinherited |
Clear contents of this object.
Reimplemented in RelationArray, StoreArray< T >, StoreArray< Particle >, StoreArray< Belle2::MCParticle >, StoreArray< Belle2::AWESOMESimHit >, StoreArray< Belle2::Particle >, StoreArray< Belle2::ECLCluster >, StoreArray< Belle2::KLMCluster >, StoreArray< Belle2::Track >, StoreArray< Belle2::TrackFitResult >, StoreArray< Belle2::V0 >, StoreArray< Belle2::BelleTrkExtra >, StoreArray< Belle2::PIDLikelihood >, StoreArray< Belle2::Btube >, StoreArray< Belle2::ContinuumSuppression >, StoreArray< Belle2::RestOfEvent >, StoreArray< Belle2::FlavorTaggerInfo >, StoreArray< Belle2::FlavorTaggerInfoMap >, StoreArray< Belle2::StringWrapper >, StoreArray< StoredClass >, StoreArray< TObject >, and StoreArray< Belle2::TagVertex >.
Definition at line 121 of file StoreAccessorBase.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 119 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 131 of file StoreObjPtr.h.
|
inlineinherited |
Create a default object in the data store.
This only works after registerInDataStore() has been called by this or another module.
replace | Should an existing object be replaced? |
Definition at line 107 of file StoreAccessorBase.h.
|
inlineprivate |
Ensure that this object is attached.
Definition at line 155 of file StoreObjPtr.h.
|
inlineprivate |
if accesses to this object would crash, throw an std::runtime_error
Definition at line 162 of file StoreObjPtr.h.
|
inlineinherited |
Return pair of name and durability under which stored object is saved.
Definition at line 134 of file StoreAccessorBase.h.
|
inlineinherited |
The underlying object's type.
Definition at line 149 of file StoreAccessorBase.h.
|
inlineinherited |
Return durability with which the object is saved in the DataStore.
Definition at line 131 of file StoreAccessorBase.h.
|
inlineinherited |
Return name under which the object is saved in the DataStore.
Definition at line 128 of file StoreAccessorBase.h.
|
inlinestatic |
Return list of object names with matching type.
Definition at line 148 of file StoreObjPtr.h.
|
inlineinherited |
Is this an accessor for an array?
Definition at line 152 of file StoreAccessorBase.h.
|
inlineinherited |
Tell the DataStore about an optional input.
Mainly useful for creating diagrams of module inputs and outputs.
name | If not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event(). |
Definition at line 93 of file StoreAccessorBase.h.
|
inlineinherited |
Ensure this array/object has been registered previously.
Will cause an ERROR if it does not exist. This must be called in the initialization phase.
name | If not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event(). |
Definition at line 78 of file StoreAccessorBase.h.
|
inline |
Check whether the object was created.
Definition at line 111 of file StoreObjPtr.h.
|
inherited |
Returns true if this object/array should not be saved by output modules.
See DataStore::c_DontWriteOut. Can be changed by re-registering it with/without the flag.
Definition at line 53 of file StoreAccessorBase.cc.
|
inline |
Imitate pointer functionality.
Definition at line 144 of file StoreObjPtr.h.
|
inlinevirtualinherited |
Check if two store accessors point to a different object/array.
Definition at line 143 of file StoreAccessorBase.h.
|
inline |
Imitate pointer functionality.
Definition at line 138 of file StoreObjPtr.h.
|
inline |
Imitate pointer functionality.
Definition at line 142 of file StoreObjPtr.h.
|
inlinevirtualinherited |
Check if two store accessors point to the same object/array.
Definition at line 137 of file StoreAccessorBase.h.
|
inherited |
Convert this acessor into a readable string (for messages).
e.g. "object EventMetaData (durability: event)"
Definition at line 18 of file StoreAccessorBase.cc.
|
inlineinherited |
Register the object/array in the DataStore.
This must be called in the initialization phase.
name | If not empty, set non-default name for this object/array. This is permanent, so that e.g. after using registerInDataStore("myName") in initialize(), this object will continue refer to 'myName' in event(). |
storeFlags | ORed combination of DataStore::EStoreFlags. |
Definition at line 64 of file StoreAccessorBase.h.
|
inlineinherited |
Register the object/array in the DataStore.
This must be called in the initialization phase.
storeFlags | ORed combination of DataStore::EStoreFlags. |
Definition at line 52 of file StoreAccessorBase.h.
|
protectedinherited |
The underlying object's type.
Definition at line 172 of file StoreAccessorBase.h.
|
protectedinherited |
Store durability under which the object/array is saved.
Definition at line 169 of file StoreAccessorBase.h.
|
protectedinherited |
Is this an accessor for an array?
Definition at line 175 of file StoreAccessorBase.h.
|
protectedinherited |
Store name under which this object/array is saved.
Definition at line 166 of file StoreAccessorBase.h.
|
private |
Store of actual pointer.
Don't make this a T** as this might cause problems with multiple inheritance objects
Definition at line 170 of file StoreObjPtr.h.