Belle II Software  release-05-01-25
NamedFloatTuple.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 <RtypesCore.h>
13 
14 #include <tracking/trackFindingCDC/utilities/Named.h>
15 #include <tracking/trackFindingCDC/utilities/MayBePtr.h>
16 
17 #include <vector>
18 #include <map>
19 #include <string>
20 
21 namespace Belle2 {
26  namespace TrackFindingCDC {
27 
29  class NamedFloatTuple {
30 
31  public:
33  virtual ~NamedFloatTuple();
34 
36  virtual size_t size() const = 0;
37 
46  virtual int getNameIndex(const char* name) const = 0;
47 
49  virtual std::string getName(int iValue) const = 0;
50 
52  virtual void set(int iValue, Float_t value) = 0;
53 
55  void set(const char* const name, Float_t value)
56  {
57  set(getNameIndex(name), value);
58  }
59 
61  virtual Float_t get(int iValue) const = 0;
62 
64  Float_t get(const char* const name) const
65  {
66  return get(getNameIndex(name));
67  }
68 
73  virtual MayBePtr<Float_t> find(std::string name)
74  {
75  size_t nameindex = getNameIndex(name.c_str());
76  return (nameindex < size()) ? &(operator[](nameindex)) : nullptr;
77  }
78 
80  virtual Float_t& operator[](int iValue) = 0;
81 
83  Float_t& operator[](const char* const name)
84  {
85  return operator[](getNameIndex(name));
86  }
87 
89  std::map<std::string, Float_t> getNamedValues(std::string prefix = "") const;
90 
92  std::vector<Named<Float_t*>> getNamedVariables(std::string prefix = "");
93  };
94  }
96 }
Belle2::TrackFindingCDC::NamedFloatTuple::getNamedValues
std::map< std::string, Float_t > getNamedValues(std::string prefix="") const
Getter for a map of all name and value pairs in this tuple.
Definition: NamedFloatTuple.cc:17
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::NamedFloatTuple::set
virtual void set(int iValue, Float_t value)=0
Setter for the value of the ith part.
Belle2::TrackFindingCDC::NamedFloatTuple::getNameIndex
virtual int getNameIndex(const char *name) const =0
Getter for the index from a name.
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::NamedFloatTuple::size
virtual size_t size() const =0
Getter for the number of parts.
Belle2::TrackFindingCDC::NamedFloatTuple::getName
virtual std::string getName(int iValue) const =0
Getter for the ith name.
Belle2::TrackFindingCDC::NamedFloatTuple::get
virtual Float_t get(int iValue) const =0
Getter for the value of the ith part.
Belle2::TrackFindingCDC::NamedFloatTuple::operator[]
virtual Float_t & operator[](int iValue)=0
Reference getter for the value of the ith part.
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::NamedFloatTuple::~NamedFloatTuple
virtual ~NamedFloatTuple()
Marking the destructor virtual since we are using virtual functions.