 |
Belle II Software
release-05-02-19
|
13 #include <framework/datastore/RelationEntry.h>
14 #include <framework/utilities/ArrayIterator.h>
26 class RelationVectorBase {
32 RelationVectorBase(
const std::string& name,
int index,
const std::vector<Belle2::RelationEntry>& relations,
40 void apply(
int index,
const std::function<
void(std::vector<unsigned int>&, std::vector<float>&,
size_t)>& f);
69 template <
class T>
class RelationVector :
protected RelationVectorBase {
72 typedef ArrayIterator<RelationVector<T>, T>
iterator;
81 explicit RelationVector(
const RelationVectorBase& b): RelationVectorBase(b) {}
87 const std::vector<Belle2::RelationEntry>&
relations()
const {
return m_relations;}
90 size_t size()
const {
return m_relations.size();}
98 T*
object(
int index)
const {
return static_cast<T*
>(m_relations[index].object);}
112 float weight(
int index)
const {
return m_relations[index].weight;}
123 apply(index, [](std::vector<unsigned int>& indices, std::vector<float>& weights,
125 indices.erase(indices.begin() + elidx);
126 weights.erase(weights.begin() + elidx);
129 m_relations.erase(m_relations.begin() + index);
135 apply(index, [
weight](std::vector<unsigned int>&, std::vector<float>& weights,
size_t elidx) {
139 m_relations[index].weight =
weight;
size_t size() const
Get number of relations.
RelationVectorBase()
Construct empty set.
ArrayIterator< RelationVector< T >, T > iterator
STL-like iterator over the T objects (not T* ).
void add(const RelationVectorBase &other)
add another list of relations.
int m_index
index of object these relations belong to.
T * operator[](int index) const
Get object with index.
Generic iterator class for arrays, allowing use of STL algorithms, range-based for etc.
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.
std::vector< std::string > m_relationNames
Names of associated relations.
base class for RelationVector<T>
iterator begin()
Return iterator to first entry.
void remove(int index)
Remove relation at given index.
void setWeight(int index, float weight)
Set a new weight for the given relation.
Abstract base class for different kinds of events.
T * object(int index) const
Get object with index.
ArrayIterator< RelationVector< T >, const T > const_iterator
STL-like const_iterator over the T objects (not T* ).
std::string m_name
entry name of array containing object these relations belong to.
RelationVector(const RelationVectorBase &b)
Constructor.
float weight(int index) const
Get weight with index.
iterator end()
Return iterator to last entry +1.
const std::vector< Belle2::RelationEntry > & relations() const
Accessor for the relations vector.
std::vector< RelationEntry > m_relations
The vector of relation entries.
In the store you can park objects that have to be accessed by various modules.