ATLAS Offline Software
MonitoredScalar.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef AthenaMonitoringKernel_MonitoredScalar_h
6 #define AthenaMonitoringKernel_MonitoredScalar_h
7 
8 
9 #include <vector>
10 
12 
13 
14 namespace Monitored {
15 
34  template <class T> class Scalar : public IMonitoredVariable {
35  public:
36  static_assert(std::is_convertible<T, double>::value or std::is_constructible<std::string, T>::value, "Conversion of scalar template type to double or string is impossible");
37 
39 
50  Scalar(std::string name, const T& defaultValue = {}) :
51  IMonitoredVariable(std::move(name)),
52  m_value(defaultValue)
53  {}
54 
65  Scalar(std::string name, const T& defaultValue, std::function<double(const T&)> valueTransform) :
66  IMonitoredVariable(std::move(name)),
67  m_value(defaultValue),
68  m_valueTransform(std::move(valueTransform))
69  {}
70 
80  Scalar(std::string name, std::function<T()> generator) :
81  IMonitoredVariable(std::move(name)),
82  m_valueGenerator(std::move(generator))
83  {}
84 
86 
87  Scalar(Scalar&&) = default;
88  Scalar(Scalar const&) = delete;
89 
90  Scalar& operator=(Scalar const&) = delete;
91  // cppcheck-suppress passedByValue
93  {
94  m_value = value;
95  return value;
96  }
97 
98  // cppcheck-suppress returnByReference
99  operator T() const { return m_value; }
100  // cppcheck-suppress returnByReference
101  operator T&() { return m_value; }
102 
103  // Needed to work around an apparent bug in clang 4.0.1.
104  // Without these declarations, clang rejects `--SCALAR'
105  // (but ++SCALAR, SCALAR++, and SCALAR-- are all accepted!).
106  T operator--() { return --m_value; }
107  T operator--(int) { return m_value--; }
108 
109  virtual double get(size_t) const override {
110  if constexpr (std::is_convertible_v<double, T>) {
111  return (m_valueGenerator ? static_cast<double>(m_valueGenerator()) :
112  m_valueTransform ? m_valueTransform(m_value) : static_cast<double>(m_value));
113  }
114  else return 0;
115  }
116 
117  virtual std::string getString(size_t) const override {
118  if constexpr (std::is_constructible_v<std::string, T>) {
120  }
121  else return {};
122  }
123 
124  virtual bool hasStringRepresentation() const override {
126  }
127 
128  virtual size_t size() const override {
129  return 1;
130  }
131 
132  private:
133  T m_value{};
134  std::function<double(const T&)> m_valueTransform;
135  std::function<T()> m_valueGenerator;
136  };
137 
138 } // namespace Monitored
139 
140 #endif /* AthenaMonitoringKernel_MonitoredScalar_h */
Monitored::Scalar::Scalar
Scalar(Scalar &&)=default
Monitored::Scalar::size
virtual size_t size() const override
gives size of vector representation
Definition: MonitoredScalar.h:128
Monitored::Scalar::m_valueTransform
std::function< double(const T &)> m_valueTransform
Definition: MonitoredScalar.h:134
Monitored::Scalar::hasStringRepresentation
virtual bool hasStringRepresentation() const override
indcates that the stored content can be converted to strings
Definition: MonitoredScalar.h:124
Monitored::Scalar::getString
virtual std::string getString(size_t) const override
Definition: MonitoredScalar.h:117
IMonitoredVariable.h
Monitored::Scalar::operator--
T operator--(int)
Definition: MonitoredScalar.h:107
Monitored::Scalar::Scalar
Scalar(std::string name, const T &defaultValue, std::function< double(const T &)> valueTransform)
Scalar with default value and optional transformation applied before filling.
Definition: MonitoredScalar.h:65
Monitored::Scalar::operator=
Scalar & operator=(Scalar const &)=delete
athena.value
value
Definition: athena.py:124
Monitored::IMonitoredVariable::IMonitoredVariable
IMonitoredVariable(std::string name)
Definition: IMonitoredVariable.h:27
Monitored::Scalar::get
virtual double get(size_t) const override
Definition: MonitoredScalar.h:109
Monitored::Scalar::Scalar
Scalar(std::string name, std::function< T()> generator)
Scalar with generator function to retrieve the value.
Definition: MonitoredScalar.h:80
Monitored::Scalar::operator=
T operator=(T value)
Definition: MonitoredScalar.h:92
Monitored::IMonitoredVariable
Definition: IMonitoredVariable.h:14
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
Monitored::Scalar::m_value
T m_value
Definition: MonitoredScalar.h:133
Monitored::Scalar::Scalar
Scalar(Scalar const &)=delete
Monitored::Scalar::m_valueGenerator
std::function< T()> m_valueGenerator
Definition: MonitoredScalar.h:135
mc.generator
generator
Configure Herwig7 These are the commands corresponding to what would go into the regular Herwig infil...
Definition: mc.MGH7_FxFx_H71-DEFAULT_test.py:18
Monitored::Scalar::operator--
T operator--()
Definition: MonitoredScalar.h:106
Monitored::IMonitoredVariable::name
const std::string & name() const
Definition: IMonitoredVariable.h:19
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Monitored::Scalar::Scalar
Scalar(std::string name, const T &defaultValue={})
Scalar with optional default value.
Definition: MonitoredScalar.h:50