![]() |
Belle II Software development
|
Low-level class to create/modify relations between StoreArrays. More...
#include <RelationArray.h>
Classes | |
struct | Identity |
Struct for identity transformation on indices. More... | |
class | ReplaceMap |
Struct to replace indices based on a map-like container. More... | |
class | ReplaceVec |
Struct to replace indices based on a sequential container. More... | |
Public Types | |
enum | EConsolidationAction { c_doNothing , c_negativeWeight , c_zeroWeight , c_deleteElement } |
Modification actions for the consolidate member. More... | |
typedef ObjArrayIterator< const TClonesArray, const RelationElement > | const_iterator |
STL-like const_iterator over the T objects (not T* ). | |
typedef RelationElement::index_type | index_type |
Typedef to simplify use of correct index_type. | |
typedef RelationElement::weight_type | weight_type |
Typedef to simplify use of correct weight_type. | |
typedef std::pair< index_type, bool > | consolidation_type |
Typedef declaring the return value of any consolidation mapping. | |
Public Member Functions | |
bool | create (bool replace=false) |
Create an empty relation array in the data store. | |
template<class FROM , class TO > | |
RelationArray (const StoreArray< FROM > &from, const StoreArray< TO > &to, const std::string &name="", DataStore::EDurability durability=DataStore::c_Event) | |
Constructor which takes both store arrays and performs some sanity checks on the relation. | |
RelationArray (const AccessorParams &fromAccessor, const AccessorParams &toAccessor, DataStore::EDurability durability=DataStore::c_Event) | |
Constructor with AccessorParams for from- and to-side. | |
RelationArray (const std::string &name, DataStore::EDurability durability=DataStore::c_Event) | |
Constructor which only accepts name and durability of the relation. | |
~RelationArray () | |
Empty destructor. | |
bool | isValid () const |
Check whether the object was created. | |
operator bool () const | |
Check whether the object was created. | |
const RelationElement & | operator[] (int i) const |
Imitate array functionality. | |
int | getEntries () const |
Get the number of elements. | |
const AccessorParams & | getFromAccessorParams () const |
Return the AccessorParams the attached relation points from. | |
const AccessorParams & | getToAccessorParams () const |
Return the AccessorParams the attached relation points to. | |
bool | getModified () const |
Get modified flag of underlying container. | |
void | setModified (bool modified) |
Set modified flag of underlying container. | |
void | clear () override |
Clear all elements from the relation. | |
void | add (index_type from, index_type to, weight_type weight=1.0) |
Add a new element to the relation. | |
void | add (index_type from, const std::vector< index_type > &to, weight_type weight=1.0) |
Add a new element to the relation. | |
void | add (index_type from, const std::vector< index_type > &to, const std::vector< weight_type > &weights) |
Add a new element to the relation. | |
template<class InputIterator > | |
void | add (index_type from, const InputIterator &begin, const InputIterator &end) |
Add a new element to the relation. | |
void | consolidate () |
Consolidate Relation Elements. | |
template<class FunctionFrom , class FunctionTo > | |
void | consolidate (const FunctionFrom &replaceFrom=FunctionFrom(), const FunctionTo &replaceTo=FunctionTo(), EConsolidationAction action=c_doNothing) |
Consolidate RelationElements. | |
const_iterator | begin () const |
Return const_iterator to first entry. | |
const_iterator | end () const |
Return const_iterator to last entry +1. | |
bool | registerInDataStore (DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut) |
Register the object/array in the DataStore. | |
bool | registerInDataStore (const std::string &name, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut) |
Register the object/array in the DataStore. | |
bool | isRequired (const std::string &name="") |
Ensure this array/object has been registered previously. | |
bool | isOptional (const std::string &name="") |
Tell the DataStore about an optional input. | |
bool | assign (TObject *object, bool replace=false) |
Assign 'object' to this accessor. | |
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. | |
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. | |
std::string | readableName () const |
Convert this acessor into a readable string (for messages). | |
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 | |
RelationArray (const AccessorParams ¶ms) | |
Constructor which accepts the AccessorParams of the relation. | |
RelationElement * | next () |
Return address where the next RelationElement should be created. | |
void | checkRelation (const std::string &direction, const AccessorParams &array, const AccessorParams &rel) const |
Check that the AccessorParams stored in the relation and the one given to the constructor are the same. | |
void | ensureAttached () const |
Attach to relation, if necessary. | |
void | assertValid () const |
check that pointer exits, otherwise bail out. | |
void | assertCreated () |
Create relation, if necessary. | |
Private Attributes | |
AccessorParams | m_accessorFrom |
Accessor params for from array. | |
AccessorParams | m_accessorTo |
Accessor params for to array. | |
RelationContainer ** | m_relations |
Pointer that actually holds the relations. | |
Friends | |
template<class FROM , class TO > | |
class | RelationIndex |
template<class FROM , class TO > | |
class | RelationIndexContainer |
Low-level class to create/modify relations between StoreArrays.
Relations connect objects stored in two StoreArrays with each other, with the possibility of n:n connections and individual weights.
Assuming you have two StoreArrays called 'particles' and 'cdcsimhits', you can use RelationArray to create relations between entries:
This example loops over the 'particles' array and might for example simulate the particles' interaction with the detector. New hits are added and also connected with the particles that created them.
As with other data store objects, you should register relations you want to store in your implementation of Module::initialize(), see StoreArray::registerRelationTo()
Definition at line 62 of file RelationArray.h.
typedef std::pair<index_type, bool> consolidation_type |
Typedef declaring the return value of any consolidation mapping.
It contains the new index of the element and a bool which is true if the old element has been re-attributed and false if there was just an reordering.
Definition at line 88 of file RelationArray.h.
typedef ObjArrayIterator<const TClonesArray, const RelationElement> const_iterator |
STL-like const_iterator over the T objects (not T* ).
Definition at line 65 of file RelationArray.h.
Typedef to simplify use of correct index_type.
Definition at line 68 of file RelationArray.h.
Typedef to simplify use of correct weight_type.
Definition at line 71 of file RelationArray.h.
enum EConsolidationAction |
Modification actions for the consolidate member.
Determines what is to be done with elements where the original element was re-attributed and not just reordered
Definition at line 77 of file RelationArray.h.
|
inline |
Constructor which takes both store arrays and performs some sanity checks on the relation.
If the relation already exists it will be checked that the relation really relates between the given StoreArrays
from | StoreArray the relation points from |
to | StoreArray the relation points to |
name | Name of the relation. Default is to use the default name based on the StoreArrays |
durability | Durability of the relation. If the durability is larger than the durability of the related StoreArrays, an error is raised. |
Definition at line 178 of file RelationArray.h.
|
inline |
Constructor with AccessorParams for from- and to-side.
fromAccessor | (name, durability) of from side array |
toAccessor | (name, durability) of to side array |
durability | Durability of the relation. If the durability is larger than the durability of the related StoreArrays, an error is raised. |
Definition at line 198 of file RelationArray.h.
|
inlineexplicit |
Constructor which only accepts name and durability of the relation.
This constructor will only assign existing relations and will not create new ones since it lacks the information on the StoreArrays to relate
name | Name of the (existing) Relation |
durability | Durability of the (existing) Relation |
Definition at line 218 of file RelationArray.h.
|
inline |
|
inlineexplicitprivate |
Constructor which accepts the AccessorParams of the relation.
This constructor will only assign existing relations and will not create new ones since it lacks the information on the StoreArrays to relate
params | AccessorParams for the (existing) Relation |
Definition at line 381 of file RelationArray.h.
|
inline |
Add a new element to the relation.
from | index to point from |
begin | iterator pointing to the begin of a sequence of std::pair<index_type,weight_type> or compatible |
end | iterator pointing to the end of a sequence of std::pair<index_type,weight_type> or compatible |
Definition at line 320 of file RelationArray.h.
|
inline |
Add a new element to the relation.
from | index to point from |
to | indices to point to |
weights | weights of the relations |
Definition at line 306 of file RelationArray.h.
|
inline |
Add a new element to the relation.
from | index to point from |
to | indices to point to |
weight | weight for all relations |
Definition at line 293 of file RelationArray.h.
|
inline |
Add a new element to the relation.
from | index to point from |
to | index to point to |
weight | weight of the relation |
Definition at line 281 of file RelationArray.h.
|
inlineprivate |
Create relation, if necessary.
After this function returns, the relation is guaranteed to be writeable.
Definition at line 442 of file RelationArray.h.
|
inlineprivate |
|
inherited |
Assign 'object' to this 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 33 of file StoreAccessorBase.cc.
|
inline |
Return const_iterator to first entry.
Definition at line 369 of file RelationArray.h.
|
inlineprivate |
Check that the AccessorParams stored in the relation and the one given to the constructor are the same.
Definition at line 399 of file RelationArray.h.
|
inlineoverridevirtual |
Clear all elements from the relation.
Reimplemented from StoreAccessorBase.
Definition at line 269 of file RelationArray.h.
|
inline |
Consolidate Relation Elements.
This function will loop over the relation and "compress" it by merging all elements with the same fromIndex.
Definition at line 331 of file RelationArray.h.
|
inline |
Create an empty relation array in the data store.
replace | Should an existing object be replaced? |
Definition at line 153 of file RelationArray.h.
|
inline |
Return const_iterator to last entry +1.
Definition at line 371 of file RelationArray.h.
|
inlineprivate |
Attach to relation, if necessary.
Definition at line 413 of file RelationArray.h.
|
inlineinherited |
Return pair of name and durability under which stored object is saved.
Definition at line 134 of file StoreAccessorBase.h.
|
inlineinherited |
The underlying object's type.
Definition at line 149 of file StoreAccessorBase.h.
|
inlineinherited |
Return durability with which the object is saved in the DataStore.
Definition at line 131 of file StoreAccessorBase.h.
|
inline |
|
inline |
Return the AccessorParams the attached relation points from.
Definition at line 245 of file RelationArray.h.
|
inline |
|
inlineinherited |
Return name under which the object is saved in the DataStore.
Definition at line 128 of file StoreAccessorBase.h.
|
inline |
Return the AccessorParams the attached relation points to.
Definition at line 254 of file RelationArray.h.
|
inlineinherited |
Is this an accessor for an array?
Definition at line 152 of file StoreAccessorBase.h.
|
inlineinherited |
Tell the DataStore about an optional input.
Mainly useful for creating diagrams of module inputs and outputs.
name | If 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(). |
Definition at line 93 of file StoreAccessorBase.h.
|
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.
name | If 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(). |
Definition at line 78 of file StoreAccessorBase.h.
|
inline |
Check whether the object was created.
Definition at line 234 of file RelationArray.h.
|
inlineprivate |
Return address where the next RelationElement should be created.
Definition at line 392 of file RelationArray.h.
|
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.
|
inline |
|
inlinevirtualinherited |
Check if two store accessors point to a different object/array.
Definition at line 143 of file StoreAccessorBase.h.
|
inlinevirtualinherited |
Check if two store accessors point to the same object/array.
Definition at line 137 of file StoreAccessorBase.h.
|
inline |
|
inherited |
Convert this acessor into a readable string (for messages).
e.g. "object EventMetaData (durability: event)"
Definition at line 18 of file StoreAccessorBase.cc.
|
inlineinherited |
Register the object/array in the DataStore.
This must be called in the initialization phase.
name | If 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(). |
storeFlags | ORed combination of DataStore::EStoreFlags. |
Definition at line 64 of file StoreAccessorBase.h.
|
inlineinherited |
Register the object/array in the DataStore.
This must be called in the initialization phase.
storeFlags | ORed combination of DataStore::EStoreFlags. |
Definition at line 52 of file StoreAccessorBase.h.
|
inline |
Set modified flag of underlying container.
Definition at line 266 of file RelationArray.h.
|
friend |
Definition at line 460 of file RelationArray.h.
|
friend |
Definition at line 461 of file RelationArray.h.
|
private |
Accessor params for from array.
Definition at line 452 of file RelationArray.h.
|
private |
Accessor params for to array.
Definition at line 455 of file RelationArray.h.
|
protectedinherited |
The underlying object's type.
Definition at line 172 of file StoreAccessorBase.h.
|
protectedinherited |
Store durability under which the object/array is saved.
Definition at line 169 of file StoreAccessorBase.h.
|
protectedinherited |
Is this an accessor for an array?
Definition at line 175 of file StoreAccessorBase.h.
|
protectedinherited |
Store name under which this object/array is saved.
Definition at line 166 of file StoreAccessorBase.h.
|
private |
Pointer that actually holds the relations.
Definition at line 458 of file RelationArray.h.