![]() |
Belle II Software
release-05-02-19
|
Accessor to arrays stored in the data store. More...
#include <StoreArray.h>
Public Types | |
typedef ObjArrayIterator< TClonesArray, T > | iterator |
STL-like iterator over the T objects (not T* ). | |
typedef ObjArrayIterator< const TClonesArray, const T > | const_iterator |
STL-like const_iterator over the T objects (not T* ). | |
Public Member Functions | |
StoreArray (const std::string &name="", DataStore::EDurability durability=DataStore::c_Event) | |
Constructor to access an array in the DataStore. More... | |
template<class TO > | |
bool | registerRelationTo (const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const |
Register a relation to the given StoreArray. More... | |
template<class TO > | |
bool | requireRelationTo (const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const |
Produce error if no relation from this array to 'toArray' has been registered. More... | |
template<class TO > | |
bool | optionalRelationTo (const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const |
Tell the data store about a relation that we could make use of. More... | |
template<class TO > | |
bool | hasRelationTo (const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const |
Check for the existence of a relation to the given StoreArray. More... | |
template<class FROM > | |
bool | hasRelationFrom (const StoreArray< FROM > &fromArray, DataStore::EDurability durability=DataStore::c_Event, const std::string &namedRelation="") const |
Check for the existence of a relation from the given StoreArray. More... | |
void | clear () override |
Delete all entries in this array. More... | |
int | getEntries () const |
Get the number of objects in the array. | |
T * | operator[] (int i) const |
Access to the stored objects. More... | |
T * | appendNew () |
Construct a new T object at the end of the array. More... | |
template<class ... Args> | |
T * | appendNew (Args &&... params) |
Construct a new T object directly at the end of the array. More... | |
bool | isValid () const |
Check wether the array was registered. More... | |
operator bool () const | |
Check wether the array was registered. More... | |
TClonesArray * | getPtr () const |
Raw access to the underlying TClonesArray. More... | |
iterator | begin () |
Return iterator to first entry. | |
iterator | end () |
Return iterator to last entry +1. | |
const_iterator | begin () const |
Return const_iterator to first entry. | |
const_iterator | end () const |
Return const_iterator to last entry +1. | |
Static Public Member Functions | |
static std::vector< std::string > | getArrayList (DataStore::EDurability durability=DataStore::c_Event) |
Return list of array names with matching type. More... | |
Private Member Functions | |
bool | create (bool replace=false) |
Creating StoreArrays is unnecessary, only used internally. | |
T * | nextFreeAdress () |
Returns address of the next free position of the array. More... | |
void | ensureAttached () const |
Ensure that this object is attached. | |
void | ensureCreated () const |
Ensure that the array has been created. More... | |
bool | isCreated () const |
Check wether the array object was created. More... | |
Private Attributes | |
TClonesArray ** | m_storeArray |
Pointer that actually holds the TClonesArray. | |
Accessor to arrays stored in the data store.
StoreArrays (like StoreObjPtrs) are uniquely identified by their name and durability. In most cases, arrays are created with durability DataStore::c_Event and the default name corresponding to their type. (i.e. typename + 's') Thus, calling the constructor StoreArray<MyType>() will connect this StoreArray with the array called 'MyTypes' in the data store, with a lifetime of one event.
Stored objects can be accessed directly using their array index and operator[]. For example, the following code snippet loops over all entries in an array of CDCSimHits:
Objects linked together using relations can also be obtained by querying the objects themselves, since they should derive from RelationsObject (See class documentation for usage examples.)
Elements can be added to the array in a few ways. The easiest is to use something like:
appendNew() can also use non-default constructors, e.g. if there is a constructor that takes the arguments (int, float), you can use appendNew(int, float) instead.
Note that you have to register an array in the initialize method of a module first (using registerInDataStore()) before you can use it. This procedure is the same as for objects handled by StoreObjPtr.
To avoid some overhead involved in re-creating the StoreArray e.g. in each event() function call, you can also make StoreArray 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 StoreArray to the array with the given name.
Definition at line 33 of file ECLMatchingPerformanceExpertModule.h.
|
inlineexplicit |
Constructor to access an array in the DataStore.
name | Name under which the array 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 array. |
Definition at line 136 of file StoreArray.h.
|
inline |
Construct a new T object at the end of the array.
Appends a new object to the array, and returns a pointer so it can be filled with data. The default constructor is used for the object's creation.
Definition at line 256 of file StoreArray.h.
|
inline |
Construct a new T object directly at the end of the array.
This is done by forwarding all arguments to the constructor of the type T. If there is a constructor which takes the given combination of arguments then this call will succeed, otherwise it fails on compilation.
This method imposes no overhead as no temporary has to be constructed and should be the preferred solution for creating new objects.
It handles just like the (C++11) standard library's emplace..() functions:
Definition at line 278 of file StoreArray.h.
|
inlineoverride |
Delete all entries in this array.
Any relations to objects in this array are also removed.
Definition at line 217 of file StoreArray.h.
|
inlineprivate |
Ensure that the array has been created.
Called automatically by write operations.
Definition at line 362 of file StoreArray.h.
|
inlinestatic |
|
inline |
Raw access to the underlying TClonesArray.
Definition at line 321 of file StoreArray.h.
|
inline |
Check for the existence of a relation from the given StoreArray.
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 207 of file StoreArray.h.
|
inline |
Check for the existence of a relation to the given StoreArray.
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 195 of file StoreArray.h.
|
inlineprivate |
|
inline |
Check wether the array was registered.
Definition at line 298 of file StoreArray.h.
|
inlineprivate |
Returns address of the next free position of the array.
Definition at line 345 of file StoreArray.h.
|
inline |
Check wether the array was registered.
Definition at line 311 of file StoreArray.h.
|
inline |
Access to the stored objects.
Out-of-bounds accesses throw an std::out_of_range exception
Note that using iterators (or range-based for) avoids the range-check internally, and thus might be slightly faster.
i | Array index, should be in 0..getEntries()-1 |
Definition at line 238 of file StoreArray.h.
|
inline |
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.
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 182 of file StoreArray.h.
|
inline |
Register a relation to the given StoreArray.
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 StoreArray) |
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 150 of file StoreArray.h.
|
inline |
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 StoreArray) |
durability | Durability of the relation. |
namedRelation | Additional name for the relation, or "" for the default naming |
Definition at line 165 of file StoreArray.h.