Belle II Software  release-08-01-10
VarSet.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 #include <tracking/trackFindingCDC/varsets/BaseVarSet.h>
11 
12 #include <tracking/trackFindingCDC/varsets/FixedSizeNamedFloatTuple.h>
13 
14 #include <vector>
15 #include <string>
16 #include <limits>
17 #include <cmath>
18 
19 namespace Belle2 {
24  namespace TrackFindingCDC {
35  template<class AVarNames>
36  class VarSet : public BaseVarSet<typename AVarNames::Object> {
37 
38  private:
41 
42  public:
44  using Object = typename Super::Object;
45 
46  private:
48  static const size_t nVars = AVarNames::nVars;
49 
50  public:
55  std::vector<Named<Float_t*>> getNamedVariables(const std::string& prefix) override
56  {
57  return m_variables.getNamedVariables(prefix);
58  }
59 
64  MayBePtr<Float_t> find(const std::string& varName) override
65  {
66  return m_variables.find(varName);
67  }
68 
69  protected:
78  constexpr static int named(const char* name)
79  {
80  return index<nVars>(AVarNames::getName, name);
81  }
82 
84  template<int I>
85  Float_t get() const
86  {
87  static_assert(I < nVars, "Requested variable index exceeds number of variables.");
88  return m_variables.get(I);
89  }
90 
92  template<int I>
93  Float_t& var()
94  {
95  static_assert(I < nVars, "Requested variable index exceeds number of variables.");
96  return m_variables[I];
97  }
98 
100  template<typename AFloat>
101  struct AssignFinite {
103  explicit AssignFinite(AFloat& value)
104  : m_value(value)
105  {
106  }
107 
109  operator AFloat& ()
110  {
111  return m_value;
112  }
113 
115  void operator=(const AFloat value)
116  {
117  m_value = value;
118  if (not std::isfinite(value)) {
119  m_value = std::copysign(std::numeric_limits<AFloat>::max(), value);
120  }
121  }
122 
123  private:
125  AFloat& m_value;
126  };
127 
129  template<int I>
131  {
132  static_assert(I < nVars, "Requested variable index exceeds number of variables.");
134  }
135 
136  private:
139  };
140  }
142 }
Generic class that generates some named float values from a given object.
Definition: BaseVarSet.h:33
AObject Object
Object type from which variables shall be extracted.
Definition: BaseVarSet.h:37
Float_t get() const
Getter for the ith value. Static index version.
std::vector< Named< Float_t * > > getNamedVariables(std::string prefix="")
Getter for named references to the variables in this tuple.
virtual MayBePtr< Float_t > find(std::string name)
Getter for a pointer to the value with the given name.
Interface for an algorithm part that needs to receive the module processing signals.
Generic class that generates some named float values from a given object.
Definition: VarSet.h:36
MayBePtr< Float_t > find(const std::string &varName) override
Pointer to the variable with the given name.
Definition: VarSet.h:64
typename Super::Object Object
Type from which variables should be extracted.
Definition: VarSet.h:44
constexpr static int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:78
static const size_t nVars
Number of floating point values represented by this class.
Definition: VarSet.h:48
Float_t get() const
Getter for the value of the ith variable. Static version.
Definition: VarSet.h:85
FixedSizeNamedFloatTuple< AVarNames > m_variables
Memory for nVars floating point values.
Definition: VarSet.h:138
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:93
std::vector< Named< Float_t * > > getNamedVariables(const std::string &prefix) override
Getter for the named references to the individual variables Base implementaton returns empty vector.
Definition: VarSet.h:55
AssignFinite< Float_t > finitevar()
Reference getter for the value of the ith variable. Transforms non-finite values to finite value.
Definition: VarSet.h:130
Abstract base class for different kinds of events.
Helper construct to assign a finite value to float variables.
Definition: VarSet.h:101
void operator=(const AFloat value)
Assign value replacing infinite values with the maximum value possible.
Definition: VarSet.h:115
AssignFinite(AFloat &value)
Setup the assignment to a variable.
Definition: VarSet.h:103
AFloat & m_value
Reference to the variable to be assigned.
Definition: VarSet.h:125