Belle II Software
release-08-01-10
|
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. More... | |
PyStoreArray (TClass *objClass, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. More... | |
PyStoreArray (TClass *objClass, const std::string &name, DataStore::EDurability durability=DataStore::EDurability::c_Event) | |
constructor. More... | |
bool | registerInDataStore (DataStore::EStoreFlags storeFlags) |
Register the array in the data store. More... | |
bool | registerInDataStore (const std::string &name="", DataStore::EStoreFlags storeFlags=DataStore::EStoreFlags::c_WriteOut) |
Register the array in the data store. More... | |
bool | isRequired (const std::string &name="") |
Ensure this array has been registered previously. More... | |
bool | isOptional (const std::string &name="") |
Tell the DataStore about an optional input. More... | |
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. More... | |
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. More... | |
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. More... | |
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) More... | |
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) More... | |
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. More... | |
TClonesArray * | getPtr () |
Raw access to the underlying TClonesArray. More... | |
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. More... | |
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.
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 |
Create constructed TClonesArray in the DataStore.
replace | Should an existing object be replaced? |
Definition at line 200 of file PyStoreArray.cc.
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 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 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.
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.