Belle II Software  release-05-02-19
RelationElement.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010-2011 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  **************************************************************************/
9 
10 #pragma once
11 
12 #include <TObject.h>
13 
14 #include <vector>
15 #include <utility>
16 
17 namespace Belle2 {
26  class RelationElement: public TObject {
27  public:
28 
30  typedef unsigned int index_type;
31 
33  typedef float weight_type;
34 
37 
38 
45  RelationElement(index_type from, index_type to, weight_type weight = 1.0):
46  TObject(), m_from(from), m_to(1, to), m_weights(1, weight) {}
47 
54  RelationElement(index_type from, const std::vector<index_type>& to, const std::vector<weight_type>& weights);
55 
64  template <class InputIterator> RelationElement(index_type from, const InputIterator& begin, const InputIterator& end):
65  TObject(), m_from(from)
66  {
67  setToIndices(begin, end);
68  }
69 
71  index_type getFromIndex() const { return m_from; }
72 
74  size_t getSize() const { return m_to.size(); }
75 
77  std::pair<index_type, weight_type> getTo(size_t n = 0) const { return std::make_pair(m_to[n], m_weights[n]); }
78 
80  index_type getToIndex(size_t n = 0) const { return m_to[n]; }
81 
83  weight_type getWeight(size_t n = 0) const { return m_weights[n]; }
84 
86  const std::vector<index_type>& getToIndices() const { return m_to; }
87 
89  const std::vector<weight_type>& getWeights() const { return m_weights; }
90 
92  void setFromIndex(index_type from) { m_from = from; }
93 
95  void setToIndex(index_type to, weight_type weight = 1.0)
96  {
97  m_to = std::vector<index_type>(1, to);
98  m_weights = std::vector<weight_type>(1, weight);
99  }
100 
108  template<class InputIterator> void setToIndices(InputIterator begin, const InputIterator& end)
109  {
110  for (; begin != end; ++begin) {
111  m_to.push_back(begin->first);
112  m_weights.push_back(begin->second);
113  }
114  }
115 
116  protected:
117 
120 
122  std::vector<index_type> m_to;
123 
125  std::vector<weight_type> m_weights;
126 
128  };
129 
131 }
Belle2::RelationElement::ClassDef
ClassDef(RelationElement, 1)
Class to store a single element of a relation.
Belle2::RelationElement::getToIndices
const std::vector< index_type > & getToIndices() const
Get vector of indices we point to.
Definition: RelationElement.h:93
Belle2::RelationElement::m_weights
std::vector< weight_type > m_weights
weights for to-indices.
Definition: RelationElement.h:132
Belle2::RelationElement::getWeights
const std::vector< weight_type > & getWeights() const
Get vector of weights we point to.
Definition: RelationElement.h:96
Belle2::RelationElement::getTo
std::pair< index_type, weight_type > getTo(size_t n=0) const
Get nth pair of index,weight we point to.
Definition: RelationElement.h:84
Belle2::RelationElement::RelationElement
RelationElement()
Empty constructor for ROOT.
Definition: RelationElement.cc:30
Belle2::RelationElement
Class to store a single element of a relation.
Definition: RelationElement.h:33
Belle2::RelationElement::setToIndices
void setToIndices(InputIterator begin, const InputIterator &end)
Set new indices and weights we point to.
Definition: RelationElement.h:115
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RelationElement::index_type
unsigned int index_type
type used for indices.
Definition: RelationElement.h:37
Belle2::RelationElement::m_to
std::vector< index_type > m_to
indices we point to.
Definition: RelationElement.h:129
Belle2::RelationElement::setFromIndex
void setFromIndex(index_type from)
Set index we point from.
Definition: RelationElement.h:99
Belle2::RelationElement::getSize
size_t getSize() const
Get number of indices we points to.
Definition: RelationElement.h:81
Belle2::RelationElement::getToIndex
index_type getToIndex(size_t n=0) const
Get nth index we point to.
Definition: RelationElement.h:87
Belle2::RelationElement::getFromIndex
index_type getFromIndex() const
Get index we point from.
Definition: RelationElement.h:78
Belle2::RelationElement::getWeight
weight_type getWeight(size_t n=0) const
Get nth weight we point to.
Definition: RelationElement.h:90
Belle2::RelationElement::weight_type
float weight_type
type used for weights.
Definition: RelationElement.h:40
Belle2::RelationElement::setToIndex
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.
Definition: RelationElement.h:102
Belle2::RelationElement::m_from
index_type m_from
index we point from.
Definition: RelationElement.h:126