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(valueTransform)
69  {}
70 
80  Scalar(std::string name, std::function<T()> generator) :
81  IMonitoredVariable(std::move(name)),
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  operator T() const { return m_value; }
99  operator T&() { return m_value; }
100 
101  // Needed to work around an apparent bug in clang 4.0.1.
102  // Without these declarations, clang rejects `--SCALAR'
103  // (but ++SCALAR, SCALAR++, and SCALAR-- are all accepted!).
104  T operator--() { return --m_value; }
105  T operator--(int) { return m_value--; }
106 
107  virtual double get(size_t) const override {
108  if constexpr (std::is_convertible_v<double, T>) {
109  return (m_valueGenerator ? static_cast<double>(m_valueGenerator()) :
110  m_valueTransform ? m_valueTransform(m_value) : static_cast<double>(m_value));
111  }
112  else return 0;
113  }
114 
115  virtual std::string getString(size_t) const override {
116  if constexpr (std::is_constructible_v<std::string, T>) {
118  }
119  else return {};
120  }
121 
122  virtual bool hasStringRepresentation() const override {
124  }
125 
126  virtual size_t size() const override {
127  return 1;
128  }
129 
130  private:
131  T m_value{};
132  std::function<double(const T&)> m_valueTransform;
133  std::function<T()> m_valueGenerator;
134  };
135 
136 } // namespace Monitored
137 
138 #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:126
Monitored::Scalar::m_valueTransform
std::function< double(const T &)> m_valueTransform
Definition: MonitoredScalar.h:132
Monitored::Scalar::hasStringRepresentation
virtual bool hasStringRepresentation() const override
indcates that the stored content can be converted to strings
Definition: MonitoredScalar.h:122
Monitored::Scalar::getString
virtual std::string getString(size_t) const override
Definition: MonitoredScalar.h:115
IMonitoredVariable.h
Monitored::Scalar::operator--
T operator--(int)
Definition: MonitoredScalar.h:105
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:122
Monitored::IMonitoredVariable::IMonitoredVariable
IMonitoredVariable(std::string name)
Definition: IMonitoredVariable.h:27
Monitored::Scalar::get
virtual double get(size_t) const override
Definition: MonitoredScalar.h:107
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:131
Monitored::Scalar::Scalar
Scalar(Scalar const &)=delete
Monitored::Scalar::m_valueGenerator
std::function< T()> m_valueGenerator
Definition: MonitoredScalar.h:133
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:104
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