Belle II Software development
|
a (simplified) python wrapper for StoreObjPtr. More...
#include <PyStoreObj.h>
Public Member Functions | |
PyStoreObj (const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. | |
PyStoreObj (TClass *objClass, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. | |
PyStoreObj (TClass *objClass, const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. | |
bool | registerInDataStore (DataStore::EStoreFlags storeFlags) |
Register the object in the DataStore. | |
bool | registerInDataStore (const std::string &name="", DataStore::EStoreFlags storeFlags=DataStore::EStoreFlags::c_WriteOut) |
Register the object in the DataStore. | |
bool | isRequired (const std::string &name="") |
Ensure this object has been registered previously. | |
bool | isOptional (const std::string &name="") |
Tell the DataStore about an optional input. | |
bool | hasValidClass () const |
Check whether a TClass for the contained object could be determined. | |
bool | isValid () const |
Check whether the object was registered and created. | |
operator bool () const | |
Does this PyStoreObj contain a valid datastore object? | |
TObject * | obj () const |
Returns the attached DataStore object, or nullptr if no valid object exists. | |
TObject * | operator-> () const |
Returns the attached DataStore object, or nullptr if no valid object exists. | |
bool | assign (TObject *object, bool replace=false) |
Assign 'object' to the accessor. | |
bool | create (bool replace=false) |
Create default constructed object in the DataStore. | |
Static Public Member Functions | |
static std::vector< std::string > | list (DataStore::EDurability durability=DataStore::EDurability::c_Event) |
Return list of available objects for given durability. | |
static void | printList (DataStore::EDurability durability=DataStore::EDurability::c_Event) |
Print list of available objects for given durability. | |
Private Member Functions | |
void | ensureAttached () const |
Ensure that contained TObject has been attached to a memory location on the DataStore. | |
void | attach () const |
Lookup the store entry and cache a pointer to it. | |
Private Attributes | |
StoreAccessorBase | m_storeAccessor |
Store accessor to retrieve the object. | |
StoreEntry * | m_storeEntry = nullptr |
Pointer to the DataStore entry - serves as an internal cache omitting repeated look up from the DataStore. | |
a (simplified) python wrapper for StoreObjPtr.
Compared to StoreObjPtr, PyStoreObj returns only TObjects (since it doesn't use templates). Thanks to Python, you can still access all public functions and data members of the actual type.
You can check the runtime type information of the returned objects by using Python's built-in type() function.
Inside a Python module's event() function, you can access DataStore objects like this:
Most of the time you can just use the PyStoreObj
instance like an instance of the class it represents, i.e. call all the members. The only exceptions are if the class has members which are also present in PyStoreObj
(for example isValid() or isRequired()). In this case you need to use the obj() member to obtain a reference to the real object first as shown in the example.
You can also create new objects in your Python basf2 module, using registerInDataStore() and create(). Since you cannot specify the type directly, as with template arguments to StoreObjPtr, the class name is assumed to be identical to the 'name' argument given to the constructor, and to reside in the Belle2 namespace. Consequently, you can only create objects with their default names.
See display/examples/displaydata.py for a concrete example.
Definition at line 67 of file PyStoreObj.h.
|
explicit |
constructor.
name | Name of the entry to be accessed |
durability | 0: event, 1: persistent |
Definition at line 40 of file PyStoreObj.cc.
|
explicit |
constructor.
objClass | Class of the object to be accessed |
durability | 0: event, 1: persistent |
Definition at line 50 of file PyStoreObj.cc.
|
explicit |
constructor.
objClass | Class of the object to be accessed |
name | Name of the entry to be accessed |
durability | 0: event, 1: persistent |
Definition at line 56 of file PyStoreObj.cc.
bool assign | ( | TObject * | object, |
bool | replace = false |
||
) |
Assign 'object' to the 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 140 of file PyStoreObj.cc.
|
private |
Lookup the store entry and cache a pointer to it.
Definition at line 135 of file PyStoreObj.cc.
bool create | ( | bool | replace = false | ) |
Create default constructed object in the DataStore.
replace | Should an existing object be replaced? |
Definition at line 103 of file PyStoreObj.cc.
|
private |
Ensure that contained TObject has been attached to a memory location on the DataStore.
Definition at line 125 of file PyStoreObj.cc.
bool hasValidClass | ( | ) | const |
Check whether a TClass for the contained object could be determined.
Definition at line 97 of file PyStoreObj.cc.
bool isOptional | ( | const std::string & | name = "" | ) |
Tell the DataStore about an optional input.
Mainly useful for creating diagrams of module inputs and outputs. This must be called in the initialization phase.
name | If not empty, use non-default name for this object. |
Definition at line 87 of file PyStoreObj.cc.
bool isRequired | ( | const std::string & | name = "" | ) |
Ensure this 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, use non-default name for this object. |
Definition at line 82 of file PyStoreObj.cc.
bool isValid | ( | ) | const |
Check whether the object was registered and created.
Definition at line 92 of file PyStoreObj.cc.
|
static |
Return list of available objects for given durability.
Definition at line 28 of file PyStoreObj.cc.
|
inline |
Returns the attached DataStore object, or nullptr if no valid object exists.
Definition at line 148 of file PyStoreObj.h.
|
inline |
Does this PyStoreObj contain a valid datastore object?
Accessing the object's data is UNSAFE if this returns false.
Definition at line 145 of file PyStoreObj.h.
|
inline |
Returns the attached DataStore object, or nullptr if no valid object exists.
Definition at line 151 of file PyStoreObj.h.
|
static |
Print list of available objects for given durability.
Definition at line 33 of file PyStoreObj.cc.
bool registerInDataStore | ( | const std::string & | name = "" , |
DataStore::EStoreFlags | storeFlags = DataStore::EStoreFlags::c_WriteOut |
||
) |
Register the object in the DataStore.
This must be called in the initialization phase, and a TClass or name=class name must have been supplied during construction.
name | Name of the entry to be registered. Empty for default name. |
storeFlags | ORed combination of DataStore::EStoreFlags. (default: c_WriteOut) |
Definition at line 70 of file PyStoreObj.cc.
bool registerInDataStore | ( | DataStore::EStoreFlags | storeFlags | ) |
Register the object in the DataStore.
This must be called in the initialization phase.
storeFlags | ORed combination of DataStore::EStoreFlags. (default: c_WriteOut) |
Definition at line 65 of file PyStoreObj.cc.
|
private |
Store accessor to retrieve the object.
Definition at line 178 of file PyStoreObj.h.
|
mutableprivate |
Pointer to the DataStore entry - serves as an internal cache omitting repeated look up from the DataStore.
Definition at line 181 of file PyStoreObj.h.