Belle II Software  release-08-01-10
RelationVector< T > Class Template Reference

Class for type safe access to objects that are referred to in relations. More...

#include <RelationVector.h>

Inheritance diagram for RelationVector< T >:
Collaboration diagram for RelationVector< T >:

Public Types

typedef ArrayIterator< RelationVector< T >, T > iterator
 STL-like iterator over the T objects (not T* ).
 
typedef ArrayIterator< RelationVector< T >, const T > const_iterator
 STL-like const_iterator over the T objects (not T* ).
 

Public Member Functions

 RelationVector (const RelationVectorBase &b)
 Constructor. More...
 
const std::vector< Belle2::RelationEntry > & relations () const
 Accessor for the relations vector. More...
 
size_t size () const
 Get number of relations. More...
 
T * object (int index) const
 Get object with index. More...
 
T * operator[] (int index) const
 Get object with index. More...
 
float weight (int index) const
 Get weight with index. More...
 
void remove (int index)
 Remove relation at given index. More...
 
void setWeight (int index, float weight)
 Set a new weight for the given relation.
 
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.
 

Protected Member Functions

void add (const RelationVectorBase &other)
 add another list of relations. More...
 
void apply (int index, const std::function< void(std::vector< unsigned int > &, std::vector< float > &, size_t)> &f)
 apply function to the relation associated with the RelationEntry at given index.
 

Protected Attributes

std::string m_name
 entry name of array containing object these relations belong to.
 
int m_index { -1}
 index of object these relations belong to.
 
std::vector< RelationEntrym_relations
 The vector of relation entries.
 
std::vector< std::string > m_relationNames
 Names of associated relations.
 

Detailed Description

template<class T>
class Belle2::RelationVector< T >

Class for type safe access to objects that are referred to in relations.

Objects of this class are returned by RelationsObject functinons to provide type safe access to the objects in a vector of relations returned by the data store.

Besides accessing objects/weights directly using operator[](int) and weight(int), you can also iterate over the objects directly:

const MCParticle* particle = particles[i];
for (const CDCSimHit& simhit : particle->getRelationsTo<CDCSimHit>()) {
//do things with simhit
}

If you want to modify the related objects in the loop body, you can use a non-const reference instead.

Use setWeight() to modify the weight of a single relation. Use remove() to delete a relation.

Definition at line 67 of file RelationVector.h.

Constructor & Destructor Documentation

◆ RelationVector()

RelationVector ( const RelationVectorBase b)
inlineexplicit

Constructor.

Parameters
bNot type-safe base class containing the data

Definition at line 79 of file RelationVector.h.

79 : RelationVectorBase(b) {}
RelationVectorBase()
Construct empty set.

Member Function Documentation

◆ add()

void add ( const RelationVectorBase other)
protectedinherited

add another list of relations.

(internal use)

Definition at line 59 of file RelationVector.cc.

60 {
61  if ((other.m_name != m_name) or (other.m_index != m_index))
62  B2FATAL("Trying to add RelationVectorBase for " << m_name << m_index << " and " << other.m_name << other.m_index << "!");
63 
64  m_relations.insert(m_relations.end(), other.m_relations.begin(), other.m_relations.end());
65  if (!other.m_relations.empty())
66  m_relationNames.insert(m_relationNames.end(), other.m_relationNames.begin(), other.m_relationNames.end());
67 }
std::vector< RelationEntry > m_relations
The vector of relation entries.
int m_index
index of object these relations belong to.
std::string m_name
entry name of array containing object these relations belong to.
std::vector< std::string > m_relationNames
Names of associated relations.

◆ object()

T* object ( int  index) const
inline

Get object with index.

Parameters
indexIndex of relation.
Returns
Object that the relation points to.

Definition at line 96 of file RelationVector.h.

◆ operator[]()

T* operator[] ( int  index) const
inline

Get object with index.

Parameters
indexIndex of relation.
Returns
Object that the relation points to.

Definition at line 103 of file RelationVector.h.

◆ relations()

const std::vector<Belle2::RelationEntry>& relations ( ) const
inline

Accessor for the relations vector.

Returns
Vector of RelationEntry objects.

Definition at line 85 of file RelationVector.h.

◆ remove()

void remove ( int  index)
inline

Remove relation at given index.

This will decrease size() by one. Iterators pointing beyond given index will be invalidated when calling this function.

Note
May be slow if done frequently.

Definition at line 119 of file RelationVector.h.

◆ size()

size_t size ( ) const
inline

Get number of relations.


Definition at line 88 of file RelationVector.h.

◆ weight()

float weight ( int  index) const
inline

Get weight with index.

Parameters
indexIndex of relation.
Returns
Weight that the relation has.

Definition at line 110 of file RelationVector.h.


The documentation for this class was generated from the following files: