ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaMonitoringKernel
AthenaMonitoringKernel
MonitoredScalar.h
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 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
#include <string_view>
11
#include "
AthenaMonitoringKernel/IMonitoredVariable.h
"
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
40
50
Scalar
(std::string
name
,
const
T& defaultValue = {}) :
51
IMonitoredVariable
(
std
::move(
name
)),
52
m_value
(defaultValue)
53
{}
54
55
// Special constructor for more effecient string usage
56
Scalar
(std::string
name
,
const
char
* defaultValue)
57
requires
std::is_same_v<T, std::string>
58
:
IMonitoredVariable
(std::move(
name
)),
59
m_value
(defaultValue)
60
{}
61
62
// Special constructor for more effecient string usage
63
Scalar
(std::string
name
, std::string_view defaultValue)
64
requires
std::is_same_v<T, std::string>
65
:
IMonitoredVariable
(std::move(
name
)),
66
m_value
(defaultValue)
67
{}
68
79
Scalar
(std::string
name
,
const
T& defaultValue, std::function<
double
(
const
T&)> valueTransform) :
80
IMonitoredVariable
(
std
::move(
name
)),
81
m_value
(defaultValue),
82
m_valueTransform
(
std
::move(valueTransform))
83
{}
84
94
Scalar
(std::string
name
, std::function<T()> generator) :
95
IMonitoredVariable
(
std
::move(
name
)),
96
m_valueGenerator
(
std
::move(generator))
97
{}
98
100
101
Scalar
(
Scalar
&&) =
default
;
102
Scalar
(
Scalar
const
&) =
delete
;
103
104
Scalar
&
operator=
(
Scalar
const
&) =
delete
;
105
// cppcheck-suppress passedByValue
106
T
operator=
(T value)
107
{
108
m_value
= value;
109
return
value;
110
}
111
112
operator
const
T&()
const
{
return
m_value
; }
113
operator
T&() {
return
m_value
; }
114
115
// string concatenation
116
friend
std::string
operator+
(
const
Scalar
& lhs,
const
std::string& rhs) {
117
return
lhs.
m_value
+ rhs;
118
}
119
120
friend
std::string
operator+
(
const
std::string& lhs,
const
Scalar
& rhs) {
121
return
lhs + rhs.
m_value
;
122
}
123
124
virtual
double
get
(
size_t
)
const override
{
125
if
constexpr
(std::is_convertible_v<double, T>) {
126
return
(
m_valueGenerator
?
static_cast<
double
>
(
m_valueGenerator
()) :
127
m_valueTransform
?
m_valueTransform
(
m_value
) :
static_cast<
double
>
(
m_value
));
128
}
129
else
return
0;
130
}
131
132
virtual
std::string
getString
(
size_t
)
const override
{
133
if
constexpr
(std::is_constructible_v<std::string, T>) {
134
return
(
m_valueGenerator
?
m_valueGenerator
() :
m_value
);
135
}
136
else
return
{};
137
}
138
139
virtual
bool
hasStringRepresentation
()
const override
{
140
return
std::is_constructible<std::string, T>::value;
141
}
142
143
virtual
size_t
size
()
const override
{
144
return
1;
145
}
146
147
private
:
148
T
m_value
{};
149
std::function<double(
const
T&)>
m_valueTransform
;
150
std::function<T()>
m_valueGenerator
;
151
};
152
153
}
// namespace Monitored
154
155
#endif
/* AthenaMonitoringKernel_MonitoredScalar_h */
IMonitoredVariable.h
Monitored::IMonitoredVariable
Definition
IMonitoredVariable.h:14
Monitored::IMonitoredVariable::name
const std::string & name() const
Definition
IMonitoredVariable.h:19
Monitored::IMonitoredVariable::IMonitoredVariable
IMonitoredVariable(std::string name)
Definition
IMonitoredVariable.h:27
Monitored::Scalar::m_value
T m_value
Definition
MonitoredScalar.h:148
Monitored::Scalar::operator+
friend std::string operator+(const std::string &lhs, const Scalar &rhs)
Definition
MonitoredScalar.h:120
Monitored::Scalar::Scalar
Scalar(std::string name, std::function< T()> generator)
Scalar with generator function to retrieve the value.
Definition
MonitoredScalar.h:94
Monitored::Scalar::size
virtual size_t size() const override
gives size of vector representation
Definition
MonitoredScalar.h:143
Monitored::Scalar::Scalar
Scalar(Scalar &&)=default
Monitored::Scalar::m_valueGenerator
std::function< T()> m_valueGenerator
Definition
MonitoredScalar.h:150
Monitored::Scalar::operator+
friend std::string operator+(const Scalar &lhs, const std::string &rhs)
Definition
MonitoredScalar.h:116
Monitored::Scalar::operator=
T operator=(T value)
Definition
MonitoredScalar.h:106
Monitored::Scalar::m_valueTransform
std::function< double(const T &)> m_valueTransform
Definition
MonitoredScalar.h:149
Monitored::Scalar::Scalar
Scalar(std::string name, std::string_view defaultValue)
Definition
MonitoredScalar.h:63
Monitored::Scalar::getString
virtual std::string getString(size_t) const override
Definition
MonitoredScalar.h:132
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:79
Monitored::Scalar::get
virtual double get(size_t) const override
Definition
MonitoredScalar.h:124
Monitored::Scalar::operator=
Scalar & operator=(Scalar const &)=delete
Monitored::Scalar::Scalar
Scalar(std::string name, const T &defaultValue={})
Scalar with optional default value.
Definition
MonitoredScalar.h:50
Monitored::Scalar::hasStringRepresentation
virtual bool hasStringRepresentation() const override
indcates that the stored content can be converted to strings
Definition
MonitoredScalar.h:139
Monitored::Scalar::Scalar
Scalar(std::string name, const char *defaultValue)
Definition
MonitoredScalar.h:56
Monitored::Scalar::Scalar
Scalar(Scalar const &)=delete
Monitored
Generic monitoring tool for athena components.
Definition
GenericMonitoringTool.h:28
std
STL namespace.
Generated on
for ATLAS Offline Software by
1.17.0