Belle II Software light-2406-ragdoll
|
A (simplified) python wrapper for StoreArray. More...
#include <PyStoreArray.h>
Public Member Functions | |
PyStoreArray (const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. | |
PyStoreArray (TClass *objClass, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. | |
PyStoreArray (TClass *objClass, const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. | |
bool | registerInDataStore (DataStore::EStoreFlags storeFlags) |
Register the array in the data store. | |
bool | registerInDataStore (const std::string &name="", DataStore::EStoreFlags storeFlags=DataStore::EStoreFlags::c_WriteOut) |
Register the array in the data store. | |
bool | isRequired (const std::string &name="") |
Ensure this array has been registered previously. | |
bool | isOptional (const std::string &name="") |
Tell the DataStore about an optional input. | |
bool | registerRelationTo (const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::EDurability::c_Event, DataStore::EStoreFlags storeFlags=DataStore::EStoreFlags::c_WriteOut, std::string const &namedRelation="") const |
Register a relation to the given PyStoreArray. | |
bool | requireRelationTo (const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::c_Event, std::string const &namedRelation="") const |
Produce error if no relation from this array to 'toArray' has been registered. | |
bool | optionalRelationTo (const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::c_Event, std::string const &namedRelation="") const |
Tell the data store about a relation that we could make use of. | |
bool | hasRelationTo (const PyStoreArray &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const |
Check for the existence of a relation to the provided toArray (from this Pystorearray) | |
bool | hasRelationFrom (const PyStoreArray &fromArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const |
Check for the existence of a relation from the provided toArray (to this Pystorearray) | |
std::string | getName () const |
Return name under which the object is saved in the DataStore. | |
bool | hasValidClass () const |
Check whether a TClass of the objects in this PyStoreArray could be determined. | |
bool | isValid () const |
Check whether the array was registered and created. | |
operator bool () const | |
Does this PyStoreArray contain a valid datastore array? | |
TObject * | operator[] (int i) const |
returns object at index i, or null pointer if out of range (+error) | |
int | getEntries () const |
returns number of entries for current event. | |
int | __len__ () const |
Support for len(). | |
TIter | __iter__ () const |
Allow iteration using for in Python. | |
TObject * | appendNew () |
Construct a new object of the array's type at the end of the array. | |
TClonesArray * | getPtr () |
Raw access to the underlying TClonesArray. | |
Static Public Member Functions | |
static std::vector< std::string > | list (DataStore::EDurability durability=DataStore::EDurability::c_Event) |
Return list of available arrays for given durability. | |
static void | printList (DataStore::EDurability durability=DataStore::EDurability::c_Event) |
Print list of available arrays for given durability. | |
Private Member Functions | |
void | ensureCreated () |
Ensure that contained TClonesArray has been created on the DataStore. | |
bool | create (bool replace=false) |
Create constructed TClonesArray in the DataStore. | |
void | ensureAttached () const |
Ensure that contained TClonesArray 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 StoreArray.
Compared to StoreArray, PyStoreArray returns only TObject pointers (since it doesn't use templates). Thanks to Python, you can still access all public functions and data members of the actual type.
Relations can also be accessed using functions like RelationsObject::getRelationsTo() as long as the data objects are derived from RelationsObject. A full example for accessing simhits and some related objects can be found in framework/examples/cdcplotmodule.py Additional registration and filling of PyStoreArrays is demonstrated in framework/examples/register_pystorearray.py
Example:
You can check the runtime type information of the returned objects by using Python's built-in type() function.
In case you want to access a named relation (for example, from "Tracks" to "KLMClusters" with a named relation "Secondary"), you can follow the following example:
The synthax is: ‘getRelationsTo['ClassName’]('StoreArrayName', 'RelationName') where
StoreArrayName` can be omitted in case of default store arrays.
Definition at line 72 of file PyStoreArray.h.
|
explicit |
constructor.
name | Name of the entry to be accessed |
durability | 0: event, 1: persistent |
Definition at line 40 of file PyStoreArray.cc.
|
explicit |
constructor.
objClass | Class of the object to be accessed |
durability | 0: event, 1: persistent |
Definition at line 50 of file PyStoreArray.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 PyStoreArray.cc.
TIter __iter__ | ( | ) | const |
Allow iteration using for in Python.
Definition at line 171 of file PyStoreArray.cc.
|
inline |
Support for len().
Definition at line 222 of file PyStoreArray.h.
TObject * appendNew | ( | ) |
Construct a new object of the array's type at the end of the array.
Definition at line 178 of file PyStoreArray.cc.
|
private |
Lookup the store entry and cache a pointer to it.
Definition at line 232 of file PyStoreArray.cc.
|
private |
Create constructed TClonesArray in the DataStore.
replace | Should an existing object be replaced? |
Definition at line 200 of file PyStoreArray.cc.
|
private |
Ensure that contained TClonesArray has been attached to a memory location on the DataStore.
Definition at line 222 of file PyStoreArray.cc.
|
private |
Ensure that contained TClonesArray has been created on the DataStore.
Definition at line 195 of file PyStoreArray.cc.
int getEntries | ( | ) | const |
returns number of entries for current event.
Definition at line 165 of file PyStoreArray.cc.
|
inline |
Return name under which the object is saved in the DataStore.
Definition at line 203 of file PyStoreArray.h.
TClonesArray * getPtr | ( | ) |
Raw access to the underlying TClonesArray.
Definition at line 189 of file PyStoreArray.cc.
bool hasRelationFrom | ( | const PyStoreArray & | fromArray, |
DataStore::EDurability | durability = DataStore::c_Event , |
||
const std::string & | namedRelation = "" |
||
) | const |
Check for the existence of a relation from the provided toArray (to this Pystorearray)
fromArray | Array the relation should point to (from this StoreArray) |
durability | Durability of the relation. |
namedRelation | Additional name for the relation, or "" for the default naming |
Definition at line 134 of file PyStoreArray.cc.
bool hasRelationTo | ( | const PyStoreArray & | toArray, |
DataStore::EDurability | durability = DataStore::c_Event , |
||
const std::string & | namedRelation = "" |
||
) | const |
Check for the existence of a relation to the provided toArray (from this Pystorearray)
toArray | Array the relation should point to (from this StoreArray) |
durability | Durability of the relation. |
namedRelation | Additional name for the relation, or "" for the default naming |
Definition at line 124 of file PyStoreArray.cc.
bool hasValidClass | ( | ) | const |
Check whether a TClass of the objects in this PyStoreArray could be determined.
Definition at line 144 of file PyStoreArray.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 array. |
Definition at line 87 of file PyStoreArray.cc.
bool isRequired | ( | const std::string & | name = "" | ) |
Ensure this array 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 array. |
Definition at line 82 of file PyStoreArray.cc.
bool isValid | ( | ) | const |
Check whether the array was registered and created.
Definition at line 150 of file PyStoreArray.cc.
|
static |
Return list of available arrays for given durability.
Definition at line 28 of file PyStoreArray.cc.
|
inline |
Does this PyStoreArray contain a valid datastore array?
Definition at line 212 of file PyStoreArray.h.
TObject * operator[] | ( | int | i | ) | const |
returns object at index i, or null pointer if out of range (+error)
Definition at line 155 of file PyStoreArray.cc.
bool optionalRelationTo | ( | const PyStoreArray & | toArray, |
DataStore::EDurability | durability = DataStore::c_Event , |
||
std::string const & | namedRelation = "" |
||
) | const |
Tell the data store about a relation that we could make use of.
(aka. optional input)
Mainly useful for creating diagrams of module inputs and outputs. This must be called in the initialization phase.
toArray | Array the relation should point to (from this PyStoreArray) |
durability | Durability of the relation. |
namedRelation | Name of the relation in case it's not the default name |
Definition at line 114 of file PyStoreArray.cc.
|
static |
Print list of available arrays for given durability.
Definition at line 34 of file PyStoreArray.cc.
bool registerInDataStore | ( | const std::string & | name = "" , |
DataStore::EStoreFlags | storeFlags = DataStore::EStoreFlags::c_WriteOut |
||
) |
Register the array in the data store.
This must be called in the initialization phase.
name | Name of the entry to be registered. Empty for default name. |
storeFlags | ORed combination of DataStore::EStoreFlags. (default: c_WriteOut) |
Definition at line 69 of file PyStoreArray.cc.
bool registerInDataStore | ( | DataStore::EStoreFlags | storeFlags | ) |
Register the array in the data store.
This must be called in the initialization phase.
storeFlags | ORed combination of DataStore::EStoreFlags. |
Definition at line 64 of file PyStoreArray.cc.
bool registerRelationTo | ( | const PyStoreArray & | toArray, |
DataStore::EDurability | durability = DataStore::EDurability::c_Event , |
||
DataStore::EStoreFlags | storeFlags = DataStore::EStoreFlags::c_WriteOut , |
||
std::string const & | namedRelation = "" |
||
) | const |
Register a relation to the given PyStoreArray.
Use this if you want to create relate objects in this array to objects in 'toArray'. Must be called in the initialization phase.
toArray | Array the relation should point to (from this PyStoreArray) |
durability | Durability of the relation. |
storeFlags | ORed combination of DataStore::EStoreFlags |
namedRelation | Additional name for the relation, or "" for the default naming |
Definition at line 92 of file PyStoreArray.cc.
bool requireRelationTo | ( | const PyStoreArray & | toArray, |
DataStore::EDurability | durability = DataStore::c_Event , |
||
std::string const & | namedRelation = "" |
||
) | const |
Produce error if no relation from this array to 'toArray' has been registered.
Must be called in initialization phase, aborts job if it fails. (allowing you to catch problems early)
toArray | Array the relation should point to (from this PyStoreArray) |
durability | Durability of the relation. |
namedRelation | Name of the relation in case it's not the default name |
Definition at line 104 of file PyStoreArray.cc.
|
private |
Store accessor to retrieve the object.
Definition at line 262 of file PyStoreArray.h.
|
mutableprivate |
Pointer to the DataStore entry - serves as an internal cache omitting repeated look up from the DataStore.
Definition at line 265 of file PyStoreArray.h.