Belle II Software development
RelationElement.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <TObject.h>
12
13#include <vector>
14#include <utility>
15
16namespace Belle2 {
25 class RelationElement: public TObject {
26 public:
27
29 typedef unsigned int index_type;
30
32 typedef float weight_type;
33
36
37
45 TObject(), m_from(from), m_to(1, to), m_weights(1, weight) {}
46
53 RelationElement(index_type from, const std::vector<index_type>& to, const std::vector<weight_type>& weights);
54
63 template <class InputIterator> RelationElement(index_type from, const InputIterator& begin, const InputIterator& end):
64 TObject(), m_from(from)
65 {
66 setToIndices(begin, end);
67 }
68
70 index_type getFromIndex() const { return m_from; }
71
73 size_t getSize() const { return m_to.size(); }
74
76 std::pair<index_type, weight_type> getTo(size_t n = 0) const { return std::make_pair(m_to[n], m_weights[n]); }
77
79 index_type getToIndex(size_t n = 0) const { return m_to[n]; }
80
82 weight_type getWeight(size_t n = 0) const { return m_weights[n]; }
83
85 const std::vector<index_type>& getToIndices() const { return m_to; }
86
88 const std::vector<weight_type>& getWeights() const { return m_weights; }
89
91 void setFromIndex(index_type from) { m_from = from; }
92
94 void setToIndex(index_type to, weight_type weight = 1.0)
95 {
96 m_to = std::vector<index_type>(1, to);
97 m_weights = std::vector<weight_type>(1, weight);
98 }
99
107 template<class InputIterator> void setToIndices(InputIterator begin, const InputIterator& end)
108 {
109 for (; begin != end; ++begin) {
110 m_to.push_back(begin->first);
111 m_weights.push_back(begin->second);
112 }
113 }
114
115 protected:
116
119
121 std::vector<index_type> m_to;
122
124 std::vector<weight_type> m_weights;
125
127 };
128
130}
Class to store a single element of a relation.
index_type m_from
index we point from.
RelationElement()
Empty constructor for ROOT.
index_type getFromIndex() const
Get index we point from.
index_type getToIndex(size_t n=0) const
Get nth index we point to.
ClassDef(RelationElement, 1)
Class to store a single element of a relation.
unsigned int index_type
type used for indices.
const std::vector< index_type > & getToIndices() const
Get vector of indices we point to.
void setToIndex(index_type to, weight_type weight=1.0)
Set index we point to, converts relation to 1:1 and discards all existing to-indices.
float weight_type
type used for weights.
size_t getSize() const
Get number of indices we points to.
void setToIndices(InputIterator begin, const InputIterator &end)
Set new indices and weights we point to.
const std::vector< weight_type > & getWeights() const
Get vector of weights we point to.
void setFromIndex(index_type from)
Set index we point from.
weight_type getWeight(size_t n=0) const
Get nth weight we point to.
std::pair< index_type, weight_type > getTo(size_t n=0) const
Get nth pair of index,weight we point to.
RelationElement(index_type from, index_type to, weight_type weight=1.0)
Constructor for a 1:1 relation.
std::vector< weight_type > m_weights
weights for to-indices.
RelationElement(index_type from, const InputIterator &begin, const InputIterator &end)
Constructor for a 1:n relation.
std::vector< index_type > m_to
indices we point to.
Abstract base class for different kinds of events.