Belle II Software  release-05-02-19
Mapping.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2015 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: dschneider, Oliver Frost *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
13 
14 #include <cassert>
15 
16 namespace Belle2 {
21  namespace TrackFindingCDC {
22 
24  template <class T>
25  class Mapping {
26 
27  public:
29  virtual ~Mapping() = default;
30 
32  virtual std::string map(int index __attribute__((unused)),
33  T& t __attribute__((unused)))
34  {
35  return "";
36  }
37 
39  virtual std::string info()
40  {
41  return "(no info available)\n";
42  }
43  };
44 
46  template <class T>
47  class ConstantMapping : public Mapping<T> {
48 
49  public:
51  explicit ConstantMapping(const std::string& value)
52  : m_value(value)
53  {
54  }
55 
57  std::string map(int index __attribute__((unused)), T& t __attribute__((unused))) override
58  {
59  return m_value;
60  }
61 
63  std::string info() override
64  {
65  return "always " + m_value + "\n";
66  }
67 
68  private:
70  std::string m_value;
71  };
72 
74  template <class T>
75  class CycleMapping : public Mapping<T> {
76 
77  public:
79  explicit CycleMapping(const std::vector<std::string>& values)
80  : m_values(values)
81  {
82  }
83 
85  std::string map(int index, T& t __attribute__((unused))) override
86  {
87  assert(index >= 0);
88  return m_values[index % m_values.size()];
89  }
90 
92  std::string info() override
93  {
94  return "Cycle through " + bracketed(join(", ", m_values)) + "\n";
95  }
96 
97  private:
99  std::vector<std::string> m_values;
100  };
101  }
103 }
Belle2::TrackFindingCDC::CycleMapping
Realizing a mapping from a pool of values to be cycled from the index.
Definition: Mapping.h:83
Belle2::TrackFindingCDC::Mapping::info
virtual std::string info()
Informal string summarizing the translation from the object to the attribute value.
Definition: Mapping.h:47
Belle2::TrackFindingCDC::ConstantMapping::info
std::string info() override
Informal string summarizing the translation from the object to the attribute value.
Definition: Mapping.h:71
Belle2::TrackFindingCDC::Mapping
Interface defining a mapping of objects to attribute values e.g. a color.
Definition: Mapping.h:33
Belle2::TrackFindingCDC::CycleMapping::m_values
std::vector< std::string > m_values
Memory for the attribute values to be cycled.
Definition: Mapping.h:107
Belle2::TrackFindingCDC::CycleMapping::info
std::string info() override
Informal string summarizing the translation from the object to the attribute value.
Definition: Mapping.h:100
Belle2::TrackFindingCDC::CycleMapping::map
std::string map(int index, T &t __attribute__((unused))) override
Return the a value from the cycle value according to the given inded.
Definition: Mapping.h:93
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TrackFindingCDC::ConstantMapping
Realizing a mapping returning a constant attribute value regardless of object or position.
Definition: Mapping.h:55
Belle2::TrackFindingCDC::Mapping::~Mapping
virtual ~Mapping()=default
Destructor of interfaces should be virtual.
Belle2::TrackFindingCDC::ConstantMapping::map
std::string map(int index __attribute__((unused)), T &t __attribute__((unused))) override
Return the constant value.
Definition: Mapping.h:65
Belle2::TrackFindingCDC::ConstantMapping::ConstantMapping
ConstantMapping(const std::string &value)
Constructor receiving the constant value.
Definition: Mapping.h:59
Belle2::TrackFindingCDC::ConstantMapping::m_value
std::string m_value
Memory for the returned attribute value.
Definition: Mapping.h:78
Belle2::TrackFindingCDC::CycleMapping::CycleMapping
CycleMapping(const std::vector< std::string > &values)
Constructor receiving the values to be cycled.
Definition: Mapping.h:87
Belle2::TrackFindingCDC::Mapping::map
virtual std::string map(int index __attribute__((unused)), T &t __attribute__((unused)))
Main function returning an attribute value for an object at the given index.
Definition: Mapping.h:40