Belle II Software development
FixedSizeNamedFloatTuple< ANames > Class Template Reference

Generic class that contains a fixed number of named float values. More...

#include <FixedSizeNamedFloatTuple.h>

Inheritance diagram for FixedSizeNamedFloatTuple< ANames >:
NamedFloatTuple

Public Member Functions

size_t size () const final
 Getter for number of floating point values represented by this class.
 
int getNameIndex (const char *name) const final
 Getter for the index from a name.
 
std::string getName (int iValue) const final
 Getter for the ith name.
 
template<int I>
void set (Float_t value)
 Setter for the ith values. Static index version.
 
void set (int iValue, Float_t value) final
 Setter for the ith value.
 
void set (const char *name, Float_t value)
 Setter for the value with the given name.
 
template<int I>
Float_t get () const
 Getter for the ith value. Static index version.
 
Float_t get (int iValue) const final
 Getter for the ith value.
 
Float_t get (const char *name) const
 Getter for the value with the given name.
 
template<int I>
Float_t & var ()
 Reference getter for the ith value. Static index version.
 
Float_t & operator[] (int iValue) final
 Reference getter for the ith value.
 
Float_t & operator[] (const char *name)
 Reference getter for the value with the given name.
 
virtual MayBePtr< Float_t > find (std::string name)
 Getter for a pointer to the value with the given name.
 
std::map< std::string, Float_t > getNamedValues (std::string prefix="") const
 Getter for a map of all name and value pairs in this tuple.
 
std::vector< Named< Float_t * > > getNamedVariables (std::string prefix="")
 Getter for named references to the variables in this tuple.
 

Public Attributes

Float_t m_values [nVars] = {}
 Memory for nVars floating point values.
 

Static Protected Member Functions

static constexpr int named (const char *name)
 Static getter for the index from the name.
 

Static Private Attributes

static const size_t nVars = ANames::nVars
 Number of floating point values represented by this class.
 

Detailed Description

template<class ANames>
class Belle2::TrackFindingCDC::FixedSizeNamedFloatTuple< ANames >

Generic class that contains a fixed number of named float values.

This object template provides the memory and the names of the float values.

Template Parameters
ANamesClass with two contained parameters:
  • nVars : Number of parts that will be peeled from the complex object.
  • names : Array of names which contain the nVars names of the float values.

Definition at line 98 of file FixedSizeNamedFloatTuple.h.

Member Function Documentation

◆ find()

virtual MayBePtr< Float_t > find ( std::string  name)
inlinevirtualinherited

Getter for a pointer to the value with the given name.

Return nullptr if not found.

Definition at line 71 of file NamedFloatTuple.h.

72 {
73 size_t nameindex = getNameIndex(name.c_str());
74 return (nameindex < size()) ? &(operator[](nameindex)) : nullptr;
75 }
virtual int getNameIndex(const char *name) const =0
Getter for the index from a name.
virtual Float_t & operator[](int iValue)=0
Reference getter for the value of the ith part.
virtual size_t size() const =0
Getter for the number of parts.

◆ get() [1/3]

Float_t get ( ) const
inline

Getter for the ith value. Static index version.

Definition at line 175 of file FixedSizeNamedFloatTuple.h.

176 {
177 static_assert(nVars != I, "Requested name not found in names.");
178 assert(I < (int)nVars);
179 assert(I >= 0);
180 return m_values[I];
181 }
Float_t m_values[nVars]
Memory for nVars floating point values.
static const size_t nVars
Number of floating point values represented by this class.

◆ get() [2/3]

Float_t get ( const char *  name) const
inline

Getter for the value with the given name.

Definition at line 192 of file FixedSizeNamedFloatTuple.h.

193 {
194 return get(named(name));
195 }
static constexpr int named(const char *name)
Static getter for the index from the name.
Float_t get() const
Getter for the ith value. Static index version.

◆ get() [3/3]

Float_t get ( int  iValue) const
inlinefinalvirtual

Getter for the ith value.

Implements NamedFloatTuple.

Definition at line 184 of file FixedSizeNamedFloatTuple.h.

185 {
186 assert(iValue < (int)nVars);
187 assert(iValue >= 0);
188 return m_values[iValue];
189 }

◆ getName()

std::string getName ( int  iValue) const
inlinefinalvirtual

Getter for the ith name.

Implements NamedFloatTuple.

Definition at line 141 of file FixedSizeNamedFloatTuple.h.

142 {
143 assert(iValue < (int)nVars);
144 assert(iValue >= 0);
145 return ANames::getName(iValue);
146 }

◆ getNamedValues()

std::map< std::string, Float_t > getNamedValues ( std::string  prefix = "") const
inherited

Getter for a map of all name and value pairs in this tuple.

Definition at line 15 of file NamedFloatTuple.cc.

16{
17 std::map<std::string, Float_t> namedValues;
18 size_t nVars = size();
19
20 for (size_t iVar = 0; iVar < nVars; ++iVar) {
21 std::string name = prefix + getName(iVar);
22 Float_t value = get(iVar);
23 namedValues[name] = value;
24 }
25
26 return namedValues;
27}
virtual Float_t get(int iValue) const =0
Getter for the value of the ith part.
virtual std::string getName(int iValue) const =0
Getter for the ith name.

◆ getNamedVariables()

std::vector< Named< Float_t * > > getNamedVariables ( std::string  prefix = "")
inherited

Getter for named references to the variables in this tuple.

Definition at line 29 of file NamedFloatTuple.cc.

30{
31 std::vector<Named<Float_t*> > namedVariables;
32 int nVars = size();
33 namedVariables.reserve(nVars);
34
35 for (int iVar = 0; iVar < nVars; ++iVar) {
36 std::string name = prefix + getName(iVar);
37 Float_t& value = operator[](iVar);
38 namedVariables.emplace_back(name, &value);
39 }
40
41 return namedVariables;
42}

◆ getNameIndex()

int getNameIndex ( const char *  name) const
inlinefinalvirtual

Getter for the index from a name.

Looks through the associated names and returns the right index if found. Returns size() (one after the last element) if not found.

Parameters
nameName of the sought part
Returns
Index of the name, nParts if not found.

Implements NamedFloatTuple.

Definition at line 135 of file FixedSizeNamedFloatTuple.h.

136 {
137 return named(name);
138 }

◆ named()

static constexpr int named ( const char *  name)
inlinestaticconstexprprotected

Static getter for the index from the name.

Looks through the associated names and returns the right index if found Returns nVars (one after the last element) if not found.

Short hand named spells nice in implementation code.

Parameters
nameThe sough name.
Returns
Index of the name, nVars if not found.

Definition at line 115 of file FixedSizeNamedFloatTuple.h.

116 {
117 return index<nVars>(ANames::getName, name);
118 }

◆ operator[]() [1/2]

Float_t & operator[] ( const char *  name)
inline

Reference getter for the value with the given name.

Definition at line 216 of file FixedSizeNamedFloatTuple.h.

217 {
218 return this->var(named(name));
219 }
Float_t & var()
Reference getter for the ith value. Static index version.

◆ operator[]() [2/2]

Float_t & operator[] ( int  iValue)
inlinefinalvirtual

Reference getter for the ith value.

Implements NamedFloatTuple.

Definition at line 208 of file FixedSizeNamedFloatTuple.h.

209 {
210 assert(iValue < (int)nVars);
211 assert(iValue >= 0);
212 return m_values[iValue];
213 }

◆ set() [1/3]

void set ( const char *  name,
Float_t  value 
)
inline

Setter for the value with the given name.

Definition at line 168 of file FixedSizeNamedFloatTuple.h.

169 {
170 set(named(name), value);
171 }
void set(Float_t value)
Setter for the ith values. Static index version.

◆ set() [2/3]

void set ( Float_t  value)
inline

Setter for the ith values. Static index version.

Definition at line 151 of file FixedSizeNamedFloatTuple.h.

152 {
153 static_assert(nVars != I, "Requested name not found in names.");
154 assert(I < (int)nVars);
155 assert(I >= 0);
156 m_values[I] = value;
157 }

◆ set() [3/3]

void set ( int  iValue,
Float_t  value 
)
inlinefinalvirtual

Setter for the ith value.

Implements NamedFloatTuple.

Definition at line 160 of file FixedSizeNamedFloatTuple.h.

161 {
162 assert(iValue < (int)nVars);
163 assert(iValue >= 0);
164 m_values[iValue] = value;
165 }

◆ size()

size_t size ( ) const
inlinefinalvirtual

Getter for number of floating point values represented by this class.

Implements NamedFloatTuple.

Definition at line 122 of file FixedSizeNamedFloatTuple.h.

123 {
124 return ANames::nVars;
125 }

◆ var()

Float_t & var ( )
inline

Reference getter for the ith value. Static index version.

Definition at line 199 of file FixedSizeNamedFloatTuple.h.

200 {
201 static_assert(nVars != I, "Requested name not found in names.");
202 assert(I < (int)nVars);
203 assert(I >= 0);
204 return m_values[I];
205 }

Member Data Documentation

◆ m_values

Float_t m_values[nVars] = {}

Memory for nVars floating point values.

Definition at line 223 of file FixedSizeNamedFloatTuple.h.

◆ nVars

const size_t nVars = ANames::nVars
staticprivate

Number of floating point values represented by this class.

Definition at line 102 of file FixedSizeNamedFloatTuple.h.


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