Belle II Software light-2406-ragdoll
RelationElement Class Reference

Class to store a single element of a relation. More...

#include <RelationElement.h>

Inheritance diagram for RelationElement:
Collaboration diagram for RelationElement:

Public Types

typedef unsigned int index_type
 type used for indices.
 
typedef float weight_type
 type used for weights.
 

Public Member Functions

 RelationElement ()
 Empty constructor for ROOT.
 
 RelationElement (index_type from, index_type to, weight_type weight=1.0)
 Constructor for a 1:1 relation.
 
 RelationElement (index_type from, const std::vector< index_type > &to, const std::vector< weight_type > &weights)
 Constructor for a 1:n relation.
 
template<class InputIterator >
 RelationElement (index_type from, const InputIterator &begin, const InputIterator &end)
 Constructor for a 1:n relation.
 
index_type getFromIndex () const
 Get index we point from.
 
size_t getSize () const
 Get number of indices we points to.
 
std::pair< index_type, weight_typegetTo (size_t n=0) const
 Get nth pair of index,weight we point to.
 
index_type getToIndex (size_t n=0) const
 Get nth index we point to.
 
weight_type getWeight (size_t n=0) const
 Get nth weight we point to.
 
const std::vector< index_type > & getToIndices () const
 Get vector of indices 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.
 
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.
 
template<class InputIterator >
void setToIndices (InputIterator begin, const InputIterator &end)
 Set new indices and weights we point to.
 

Protected Member Functions

 ClassDef (RelationElement, 1)
 Class to store a single element of a relation.
 

Protected Attributes

index_type m_from
 index we point from.
 
std::vector< index_typem_to
 indices we point to.
 
std::vector< weight_typem_weights
 weights for to-indices.
 

Detailed Description

Class to store a single element of a relation.

Supports 1:n relations with individual weights.

Definition at line 25 of file RelationElement.h.

Member Typedef Documentation

◆ index_type

typedef unsigned int index_type

type used for indices.

Definition at line 29 of file RelationElement.h.

◆ weight_type

typedef float weight_type

type used for weights.

Definition at line 32 of file RelationElement.h.

Constructor & Destructor Documentation

◆ RelationElement() [1/4]

Empty constructor for ROOT.

Definition at line 28 of file RelationElement.cc.

28 :
29 TObject(), m_from(UINT_MAX), m_to(), m_weights()
30{
31
32}
index_type m_from
index we point from.
std::vector< weight_type > m_weights
weights for to-indices.
std::vector< index_type > m_to
indices we point to.

◆ RelationElement() [2/4]

RelationElement ( index_type  from,
index_type  to,
weight_type  weight = 1.0 
)
inline

Constructor for a 1:1 relation.

Parameters
fromindex to point from
toindex to point to
weightweight of the relation

Definition at line 44 of file RelationElement.h.

44 :
45 TObject(), m_from(from), m_to(1, to), m_weights(1, weight) {}

◆ RelationElement() [3/4]

RelationElement ( index_type  from,
const std::vector< index_type > &  to,
const std::vector< weight_type > &  weights 
)

Constructor for a 1:n relation.

Parameters
fromindex to point from
toindices to point to
weightsweights of the relation

Definition at line 18 of file RelationElement.cc.

18 :
19 TObject(),
20 m_from(from),
21 m_to(to.begin(), to.end()),
22 m_weights(weights.begin(), weights.end())
23{
24 if (to.size() != weights.size()) {
25 B2FATAL("Index and weight vector sizes differ!");
26 }
27}

◆ RelationElement() [4/4]

RelationElement ( index_type  from,
const InputIterator &  begin,
const InputIterator &  end 
)
inline

Constructor for a 1:n relation.

Parameters
fromindex to point from
beginiterator pointing to the begin of a sequence of std::pair<index_type,weight_type> or compatible
enditerator pointing to the end of a sequence of std::pair<index_type,weight_type> or compatible

Definition at line 63 of file RelationElement.h.

63 :
64 TObject(), m_from(from)
65 {
66 setToIndices(begin, end);
67 }
void setToIndices(InputIterator begin, const InputIterator &end)
Set new indices and weights we point to.

Member Function Documentation

◆ getFromIndex()

index_type getFromIndex ( ) const
inline

Get index we point from.

Definition at line 70 of file RelationElement.h.

70{ return m_from; }

◆ getSize()

size_t getSize ( ) const
inline

Get number of indices we points to.

Definition at line 73 of file RelationElement.h.

73{ return m_to.size(); }

◆ getTo()

std::pair< index_type, weight_type > getTo ( size_t  n = 0) const
inline

Get nth pair of index,weight we point to.

Definition at line 76 of file RelationElement.h.

76{ return std::make_pair(m_to[n], m_weights[n]); }

◆ getToIndex()

index_type getToIndex ( size_t  n = 0) const
inline

Get nth index we point to.

Definition at line 79 of file RelationElement.h.

79{ return m_to[n]; }

◆ getToIndices()

const std::vector< index_type > & getToIndices ( ) const
inline

Get vector of indices we point to.

Definition at line 85 of file RelationElement.h.

85{ return m_to; }

◆ getWeight()

weight_type getWeight ( size_t  n = 0) const
inline

Get nth weight we point to.

Definition at line 82 of file RelationElement.h.

82{ return m_weights[n]; }

◆ getWeights()

const std::vector< weight_type > & getWeights ( ) const
inline

Get vector of weights we point to.

Definition at line 88 of file RelationElement.h.

88{ return m_weights; }

◆ setFromIndex()

void setFromIndex ( index_type  from)
inline

Set index we point from.

Definition at line 91 of file RelationElement.h.

91{ m_from = from; }

◆ setToIndex()

void setToIndex ( index_type  to,
weight_type  weight = 1.0 
)
inline

Set index we point to, converts relation to 1:1 and discards all existing to-indices.

Definition at line 94 of file RelationElement.h.

95 {
96 m_to = std::vector<index_type>(1, to);
97 m_weights = std::vector<weight_type>(1, weight);
98 }

◆ setToIndices()

void setToIndices ( InputIterator  begin,
const InputIterator &  end 
)
inline

Set new indices and weights we point to.

Parameters
beginiterator pointing to the begin of a sequence of std::pair<index_type,weight_type> or compatible
enditerator pointing to the end of a sequence of std::pair<index_type,weight_type> or compatible

Definition at line 107 of file RelationElement.h.

108 {
109 for (; begin != end; ++begin) {
110 m_to.push_back(begin->first);
111 m_weights.push_back(begin->second);
112 }
113 }

Member Data Documentation

◆ m_from

index_type m_from
protected

index we point from.

Definition at line 118 of file RelationElement.h.

◆ m_to

std::vector<index_type> m_to
protected

indices we point to.

Definition at line 121 of file RelationElement.h.

◆ m_weights

std::vector<weight_type> m_weights
protected

weights for to-indices.

Definition at line 124 of file RelationElement.h.


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