Belle II Software  release-08-01-10
WithWeight.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 #pragma once
9 
10 
11 #include <tracking/trackFindingCDC/numerics/Weight.h>
12 
13 #include <tracking/trackFindingCDC/utilities/Scalar.h>
14 
15 namespace Belle2 {
20  namespace TrackFindingCDC {
21 
23  template<class T>
24  class WithWeight : public ScalarToClass<T> {
25 
26  private:
28  using Super = ScalarToClass<T>;
29 
30  public:
32  using Super::Super;
33 
35  explicit WithWeight(const T& t)
36  : Super(t)
37  {
38  }
39 
41  WithWeight(const T& t, Weight weight)
42  : Super(t)
43  , m_weight(weight)
44  {
45  }
46 
48  bool operator<(const WithWeight<T>& other) const
49  {
50  // cppcheck-suppress constVariable
51  const T& t(*this);
52  // cppcheck-suppress constVariable
53  const T& otherT(other);
54  return t < otherT or (not(otherT < t) and getWeight() < other.getWeight());
55  }
56 
58  Weight getWeight() const
59  {
60  return m_weight;
61  }
62 
64  void setWeight(Weight weight)
65  {
66  m_weight = weight;
67  }
68 
70  Weight& weight()
71  {
72  return m_weight;
73  }
74 
75  private:
77  Weight m_weight = 0;
78  };
79  }
81 }
A mixin class to attach a weight to an object.
Definition: WithWeight.h:24
Weight getWeight() const
Getter for the weight.
Definition: WithWeight.h:58
WithWeight(const T &t, Weight weight)
Constructor which may also initialise the weight to a desired value.
Definition: WithWeight.h:41
ScalarToClass< T > Super
Type of the base class.
Definition: WithWeight.h:28
Weight m_weight
Memory for the weight.
Definition: WithWeight.h:77
void setWeight(Weight weight)
Setter for the weight of the object.
Definition: WithWeight.h:64
Weight & weight()
Mutable getter for the weight.
Definition: WithWeight.h:70
WithWeight(const T &t)
Also forward the copy constructor form the base class object.
Definition: WithWeight.h:35
bool operator<(const WithWeight< T > &other) const
Comparison operator establishing an ordering considering the pointer first and the weight second.
Definition: WithWeight.h:48
Abstract base class for different kinds of events.