Belle II Software  release-08-01-10
StoreWrappedObjPtr< T > Class Template Reference

This class is for convenience access and registration of objects, that are stored inside the StoreWrapper on the DataStore. More...

#include <StoreWrappedObjPtr.h>

Inheritance diagram for StoreWrappedObjPtr< T >:
Collaboration diagram for StoreWrappedObjPtr< T >:

Public Member Functions

 StoreWrappedObjPtr (const std::string &name="", DataStore::EDurability durability=DataStore::c_Event)
 Constructor to access an object in the DataStore. More...
 
bool registerInDataStore (DataStore::EStoreFlags storeFlags=DataStore::c_DontWriteOut|DataStore::c_ErrorIfAlreadyRegistered)
 Register the object/array in the DataStore. More...
 
bool registerInDataStore (const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_DontWriteOut|DataStore::c_ErrorIfAlreadyRegistered)
 Register the object/array in the DataStore. More...
 
T & operator* () const
 Dereference to the wrapped object.
 
T * operator-> () const
 Forward pointer access to the wrapped object.
 
bool isValid () const
 Check whether the object was created. More...
 
bool construct (Args &&... params)
 Construct an object of type T in this StoreObjPtr, using the provided constructor arguments. More...
 
bool constructAndReplace (Args &&... params)
 Construct an object of type T in this StoreObjPtr, using the provided constructor arguments. More...
 
 operator bool () const
 Imitate pointer functionality.
 
bool isRequired (const std::string &name="")
 Ensure this array/object has been registered previously. More...
 
bool isOptional (const std::string &name="")
 Tell the DataStore about an optional input. More...
 
bool create (bool replace=false)
 Create a default object in the data store. More...
 
bool assign (TObject *object, bool replace=false)
 Assign 'object' to this accessor. More...
 
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. More...
 
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. More...
 
std::string readableName () const
 Convert this acessor into a readable string (for messages). 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...
 

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. More...
 

Detailed Description

template<class T>
class Belle2::TrackFindingCDC::StoreWrappedObjPtr< T >

This class is for convenience access and registration of objects, that are stored inside the StoreWrapper on the DataStore.

It limits the user to registrations of transient store objects only, since objects wrapped by the StoreWrapper are usually not intended for streaming.

Definition at line 30 of file StoreWrappedObjPtr.h.

Constructor & Destructor Documentation

◆ StoreWrappedObjPtr()

StoreWrappedObjPtr ( const std::string &  name = "",
DataStore::EDurability  durability = DataStore::c_Event 
)
inline

Constructor to access an object in the DataStore.

Parameters
nameName under which the object is stored in the DataStore. If an empty string is supplied, the type name will be used.
durabilityDecides durability map used for getting the accessed object.

Definition at line 39 of file StoreWrappedObjPtr.h.

39  :
40  StoreObjPtr<StoreWrapper<T> >(name, durability)
41  {}

Member Function Documentation

◆ assign()

bool assign ( TObject *  object,
bool  replace = false 
)
inherited

Assign 'object' to this accessor.

(takes ownership).

Parameters
objectThe object that should be put in the DataStore, should be of same type as the one used by this accessor.
replaceShould an existing object be replaced? (if existing and supplied object are equal, this has no effect)
Returns
True if the assignment succeeded. If false, assign() will delete 'object', do not use it afterwards.

Definition at line 33 of file StoreAccessorBase.cc.

◆ construct()

bool construct ( Args &&...  params)
inlineinherited

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.

Returns
True if the creation succeeded.

Definition at line 119 of file StoreObjPtr.h.

◆ constructAndReplace()

bool constructAndReplace ( Args &&...  params)
inlineinherited

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.

Returns
True if the creation succeeded.

Definition at line 131 of file StoreObjPtr.h.

◆ create()

bool create ( bool  replace = false)
inlineinherited

Create a default object in the data store.

This only works after registerInDataStore() has been called by this or another module.

Parameters
replaceShould an existing object be replaced?
Returns
True if the creation succeeded.

Definition at line 107 of file StoreAccessorBase.h.

◆ getAccessorParams()

AccessorParams getAccessorParams ( ) const
inlineinherited

Return pair of name and durability under which stored object is saved.


Definition at line 134 of file StoreAccessorBase.h.

◆ getObjectList()

static std::vector<std::string> getObjectList ( DataStore::EDurability  durability = DataStore::c_Event)
inlinestaticinherited

Return list of object names with matching type.


Definition at line 148 of file StoreObjPtr.h.

◆ isOptional()

bool isOptional ( const std::string &  name = "")
inlineinherited

Tell the DataStore about an optional input.

Mainly useful for creating diagrams of module inputs and outputs.

Parameters
nameIf 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().
Returns
True if the object/array exists.

Definition at line 93 of file StoreAccessorBase.h.

◆ isRequired()

bool isRequired ( const std::string &  name = "")
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.

Parameters
nameIf 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().
Returns
True if the object/array exists.

Definition at line 78 of file StoreAccessorBase.h.

◆ isValid()

bool isValid ( ) const
inlineinherited

Check whether the object was created.

Returns
True if the object exists.

Definition at line 111 of file StoreObjPtr.h.

◆ notWrittenOut()

bool notWrittenOut ( ) const
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.

◆ readableName()

std::string readableName ( ) const
inherited

Convert this acessor into a readable string (for messages).

e.g. "object EventMetaData (durability: event)"

Definition at line 18 of file StoreAccessorBase.cc.

◆ registerInDataStore() [1/2]

bool registerInDataStore ( const std::string &  name,
DataStore::EStoreFlags  storeFlags = DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered 
)
inline

Register the object/array in the DataStore.

This must be called in the initialization phase.

Parameters
nameIf 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().
storeFlagsORed combination of DataStore::EStoreFlag flags. Defaults to c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered.
Returns
True if the registration succeeded.

Definition at line 62 of file StoreWrappedObjPtr.h.

◆ registerInDataStore() [2/2]

bool registerInDataStore ( DataStore::EStoreFlags  storeFlags = DataStore::c_DontWriteOut | DataStore::c_ErrorIfAlreadyRegistered)
inline

Register the object/array in the DataStore.

This must be called in the initialization phase.

Parameters
storeFlagsORed combination of DataStore::EStoreFlag flags. Defaults to c_DontWriteOut | c_ErrorIfAlreadyRegistered.
Returns
True if the registration succeeded.

Definition at line 50 of file StoreWrappedObjPtr.h.

Member Data Documentation

◆ m_storeObjPtr

TObject** m_storeObjPtr
privateinherited

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.


The documentation for this class was generated from the following file: