Belle II Software  release-05-02-19
VarSet.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/varsets/BaseVarSet.h>
13 
14 #include <tracking/trackFindingCDC/varsets/FixedSizeNamedFloatTuple.h>
15 
16 #include <vector>
17 #include <string>
18 #include <limits>
19 #include <cmath>
20 
21 namespace Belle2 {
26  namespace TrackFindingCDC {
37  template<class AVarNames>
38  class VarSet : public BaseVarSet<typename AVarNames::Object> {
39 
40  private:
42  using Super = BaseVarSet<typename AVarNames::Object>;
43 
44  public:
46  using Object = typename Super::Object;
47 
48  private:
50  static const size_t nVars = AVarNames::nVars;
51 
52  public:
57  std::vector<Named<Float_t*>> getNamedVariables(const std::string& prefix) override
58  {
59  return m_variables.getNamedVariables(prefix);
60  }
61 
66  MayBePtr<Float_t> find(const std::string& varName) override
67  {
68  return m_variables.find(varName);
69  }
70 
71  protected:
80  constexpr static int named(const char* name)
81  {
82  return index<nVars>(AVarNames::getName, name);
83  }
84 
86  template<int I>
87  Float_t get() const
88  {
89  static_assert(I < nVars, "Requested variable index exceeds number of variables.");
90  return m_variables.get(I);
91  }
92 
94  template<int I>
95  Float_t& var()
96  {
97  static_assert(I < nVars, "Requested variable index exceeds number of variables.");
98  return m_variables[I];
99  }
100 
102  template<typename AFloat>
103  struct AssignFinite {
105  explicit AssignFinite(AFloat& value)
106  : m_value(value)
107  {
108  }
109 
111  operator AFloat& ()
112  {
113  return m_value;
114  }
115 
117  void operator=(const AFloat value)
118  {
119  m_value = value;
120  if (not std::isfinite(value)) {
121  m_value = std::copysign(std::numeric_limits<AFloat>::max(), value);
122  }
123  }
124 
125  private:
127  AFloat& m_value;
128  };
129 
131  template<int I>
133  {
134  static_assert(I < nVars, "Requested variable index exceeds number of variables.");
136  }
137 
138  private:
141  };
142  }
144 }
Belle2::TrackFindingCDC::FixedSizeNamedFloatTuple::get
Float_t get() const
Getter for the ith value. Static index version.
Definition: FixedSizeNamedFloatTuple.h:184
Belle2::TrackFindingCDC::FixedSizeNamedFloatTuple< AVarNames >
Belle2::TrackFindingCDC::VarSet::find
MayBePtr< Float_t > find(const std::string &varName) override
Pointer to the variable with the given name.
Definition: VarSet.h:74
Belle2::TrackFindingCDC::VarSet::get
Float_t get() const
Getter for the value of the ith variable. Static version.
Definition: VarSet.h:95
Belle2::TrackFindingCDC::VarSet::finitevar
AssignFinite< Float_t > finitevar()
Reference getter for the value of the ith variable. Transforms non-finite values to finite value.
Definition: VarSet.h:140
Belle2::TrackFindingCDC::NamedFloatTuple::getNamedVariables
std::vector< Named< Float_t * > > getNamedVariables(std::string prefix="")
Getter for named references to the variables in this tuple.
Definition: NamedFloatTuple.cc:31
Belle2::TrackFindingCDC::VarSet::AssignFinite::m_value
AFloat & m_value
Reference to the variable to be assigned.
Definition: VarSet.h:135
Belle2::TrackFindingCDC::VarSet::AssignFinite::operator=
void operator=(const AFloat value)
Assign value replacing infinite values with the maximum value possible.
Definition: VarSet.h:125
Belle2::TrackFindingCDC::VarSet::m_variables
FixedSizeNamedFloatTuple< AVarNames > m_variables
Memory for nVars floating point values.
Definition: VarSet.h:148
Belle2::TrackFindingCDC::BaseVarSet< AVarNames::Object >::getNamedVariables
std::vector< Named< Float_t * > > getNamedVariables()
Getter for the named references to the individual variables.
Definition: BaseVarSet.h:80
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::VarSet::AssignFinite::AssignFinite
AssignFinite(AFloat &value)
Setup the assignment to a variable.
Definition: VarSet.h:113
Belle2::TrackFindingCDC::VarSet::AssignFinite
Helper construct to assign a finite value to float variables.
Definition: VarSet.h:111
Belle2::TrackFindingCDC::VarSet::Object
typename Super::Object Object
Type from which variables should be extracted.
Definition: VarSet.h:54
Belle2::TrackFindingCDC::VarSet::named
constexpr static int named(const char *name)
Getter for the index from the name.
Definition: VarSet.h:88
Belle2::TrackFindingCDC::NamedFloatTuple::find
virtual MayBePtr< Float_t > find(std::string name)
Getter for a pointer to the value with the given name.
Definition: NamedFloatTuple.h:81
Belle2::TrackFindingCDC::VarSet::var
Float_t & var()
Reference getter for the value of the ith variable. Static version.
Definition: VarSet.h:103
Belle2::TrackFindingCDC::VarSet::Super
BaseVarSet< typename AVarNames::Object > Super
Type of the super class.
Definition: VarSet.h:50
Belle2::TrackFindingCDC::VarSet::nVars
static const size_t nVars
Number of floating point values represented by this class.
Definition: VarSet.h:58
Belle2::TrackFindingCDC::BaseVarSet::Object
AObject Object
Object type from which variables shall be extracted.
Definition: BaseVarSet.h:47