ATLAS Offline Software
MonitoredCollection.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef AthenaMonitoringKernel_MonitoredCollection_h
6 #define AthenaMonitoringKernel_MonitoredCollection_h
7 
8 #include <functional>
9 #include <type_traits>
10 #include <vector>
11 
13 
14 namespace Monitored {
15 
16  // Forward declares
17  template <class T> class ValuesCollection;
18  template <class T> class ValuesRefCollection;
19  template <class T, class R> class ObjectsCollection;
20  template <class T, class R> class ObjectsRefCollection;
21 
38  template <class T> ValuesCollection<T> Collection(std::string name, const T& collection) {
39  return ValuesCollection<T>(std::move(name), collection);
40  }
41 
42  // Disallow temporaries
43  template <class T> ValuesCollection<T> Collection(std::string name, T const&& collection) = delete;
44 
61  template <class T> ValuesRefCollection<T> Collection(std::string name, const std::reference_wrapper<T>& collection) {
62  return ValuesRefCollection<T>(std::move(name), collection);
63  }
64 
65  // Disallow temporaries
66  template <class T> ValuesRefCollection<T> Collection(std::string name, const std::reference_wrapper<T>&& collection) = delete;
67 
68 
89  template <class T>
91  Collection(std::string name, const T& collection,
92  std::function<double(const typename ObjectsCollection<T, double>::const_value_type&)> accessor) {
93  return ObjectsCollection<T, double>(std::move(name), collection, std::move(accessor));
94  }
95 
96  template <class T>
97  ObjectsCollection<T, double>
98  Collection(std::string name, const T&& collection,
99  std::function<double(const typename ObjectsCollection<T, double>::const_value_type&)> accessor) = delete;
100 
101 
102  template <class T>
104  Collection(std::string name, const T& collection,
105  std::function<std::string(const typename ObjectsCollection<T, std::string>::const_value_type&)> accessor) {
106  return ObjectsCollection<T, std::string>(std::move(name), collection, std::move(accessor));
107  }
108 
109  template <class T>
110  ObjectsCollection<T, std::string>
111  Collection(std::string name, const T&& collection,
112  std::function<std::string(const typename ObjectsCollection<T, std::string>::const_value_type&)> accessor) = delete;
113 
114 
135  template <class T>
137  Collection(std::string name, const std::reference_wrapper<T>& collection,
138  std::function<double(const typename ObjectsRefCollection<T, double>::const_value_type&)> accessor) {
139  return ObjectsRefCollection<T, double>(std::move(name), collection, std::move(accessor));
140  }
141 
142  template <class T>
143  ObjectsRefCollection<T, double>
144  Collection(std::string name, const std::reference_wrapper<T>&& collection,
145  std::function<double(const typename ObjectsRefCollection<T, double>::const_value_type&)> accessor) = delete;
146 
147  template <class T>
149  Collection(std::string name, const std::reference_wrapper<T>& collection,
150  std::function<std::string(const typename ObjectsRefCollection<T, std::string>::const_value_type&)> accessor) {
151  return ObjectsRefCollection<T, std::string>(std::move(name), collection, std::move(accessor));
152  }
153 
154  template <class T>
155  ObjectsRefCollection<T, std::string>
156  Collection(std::string name, const std::reference_wrapper<T>&& collection,
157  std::function<std::string(const typename ObjectsRefCollection<T, std::string>::const_value_type&)> accessor) = delete;
158 
159 
160  namespace detail {
162  template <typename T> struct get_value_type { typedef typename T::value_type value_type; };
164  template <typename T, size_t N> struct get_value_type<T[N]> { typedef T value_type; };
165 
167  template <typename T> struct get_value_type<std::reference_wrapper<T>> { typedef typename T::value_type value_type; };
168  template <typename T, size_t N> struct get_value_type<std::reference_wrapper<T[N]>> { typedef T value_type; };
169 
170  template <typename T> struct make_pointer_const { typedef T type; };
171  template <typename T> struct make_pointer_const<T*> { typedef const T* type; };
172  } // namespace detail
173 
174 
178  template <class T> class ValuesCollection : public IMonitoredVariable {
179  public:
182 
183  static_assert(std::is_convertible<value_type, double>::value or std::is_constructible<std::string, value_type>::value, "Conversion of collection values to double or string is impossible");
184 
185  // @brief . \if empty doc string required due to https://github.com/doxygen/doxygen/issues/6251 \endif
186  friend ValuesCollection<T> Collection<T>(std::string name, const T& collection);
187  friend ValuesCollection<T> Collection<T>(std::string name, const T&& collection);
188 
190 
191  virtual double get([[maybe_unused]] size_t i) const override {
192  if constexpr (std::is_convertible_v<value_type, double>)
193  return m_collection[i];
194  else
195  return -1;
196  }
197 
198  virtual std::string getString([[maybe_unused]] size_t i) const override {
199  if constexpr (std::is_constructible_v<std::string, value_type>)
200  return m_collection[i];
201  else
202  return {};
203  }
204 
205  virtual bool hasStringRepresentation() const override {
207  }
208 
209  virtual size_t size() const override {
210  return std::size(m_collection);
211  }
212 
213  private:
214  const T& m_collection;
215 
216 
217  ValuesCollection(std::string vname, const T& collection)
218  : IMonitoredVariable(std::move(vname)), m_collection{collection} {
219  }
220 
223  };
224 
225 
229  template <class T> class ValuesRefCollection : public IMonitoredVariable {
230  public:
233 
234  static_assert(std::is_convertible<value_type, double>::value or std::is_constructible<std::string, value_type>::value, "Conversion of collection values to double or string is impossible");
235 
236  // @brief . \if empty doc string required due to https://github.com/doxygen/doxygen/issues/6251 \endif
237  friend ValuesRefCollection<T> Collection<T>(std::string name, const std::reference_wrapper<T>& collection);
238  friend ValuesRefCollection<T> Collection<T>(std::string name, const std::reference_wrapper<T>&& collection);
239 
241 
242  virtual double get([[maybe_unused]] size_t i) const override {
243  if constexpr (std::is_convertible_v<value_type, double>)
244  return m_collection.get()[i];
245  else
246  return -1;
247  }
248 
249  virtual std::string getString([[maybe_unused]] size_t i) const override {
250  if constexpr (std::is_constructible_v<std::string, value_type>)
251  return m_collection.get()[i];
252  else
253  return {};
254  }
255 
256  virtual bool hasStringRepresentation() const override {
258  }
259 
260  virtual size_t size() const override {
261  return std::size(m_collection.get());
262  }
263 
264  private:
265  const std::reference_wrapper<T>& m_collection;
266 
267 
268  ValuesRefCollection(std::string vname, const std::reference_wrapper<T>& collection)
269  : IMonitoredVariable(std::move(vname)), m_collection{collection} {
270  }
271 
274  };
275 
276 
283  template <class T, class R> class ObjectsCollection : public IMonitoredVariable {
284  public:
288 
289  static_assert(std::is_convertible<R, double>::value or std::is_constructible<std::string, R>::value, "Conversion from type returned by the converter/accessor to double or string is impossible");
290 
291  // With a non-template friend declaration, clang 4.0.1
292  // fails to match the friend.
293  // @brief . \if empty doc string required due to https://github.com/doxygen/doxygen/issues/6251 \endif
294  template <class U> friend ObjectsCollection<U, double>
295  Collection(std::string name, const U& collection,
296  std::function<double(const typename ObjectsCollection<U, double>::const_value_type&)> accessor);
297 
298  template <class U> friend ObjectsCollection<U, std::string>
299  Collection(std::string name, const U& collection,
300  std::function<std::string(const typename ObjectsCollection<U, std::string>::const_value_type&)> converterToString);
301 
303 
304  virtual double get([[maybe_unused]] size_t i) const override {
305  if constexpr (std::is_convertible_v<R, double>)
306  return m_converterToR(m_collection[i]);
307  else
308  return -1;
309  }
310 
311  virtual std::string getString([[maybe_unused]] size_t i) const override {
312  if constexpr (std::is_constructible_v<std::string, R>)
313  return m_converterToR(m_collection[i]);
314  else
315  return {};
316  }
317 
318  virtual bool hasStringRepresentation() const override {
320  };
321  virtual size_t size() const override {
322  return std::size(m_collection);
323  }
324 
325  private:
326  const T& m_collection;
327  std::function<R(const const_value_type&)> m_converterToR;
328 
329  ObjectsCollection(std::string name, const T& collection,
330  std::function<R(const const_value_type&)> converterToR)
331  : IMonitoredVariable(std::move(name)),
332  m_collection(std::move(collection)),
333  m_converterToR(std::move(converterToR)) {}
334 
336 
338 
339  };
340 
341 
348  template <class T, class R> class ObjectsRefCollection : public IMonitoredVariable {
349  public:
353 
354  static_assert(std::is_convertible<R, double>::value or std::is_constructible<std::string, R>::value, "Conversion from type returned by the converter/accessor to double or string is impossible");
355 
356  // With a non-template friend declaration, clang 4.0.1
357  // fails to match the friend.
358  // @brief . \if empty doc string required due to https://github.com/doxygen/doxygen/issues/6251 \endif
359  template <class U> friend ObjectsRefCollection<U, double>
360  Collection(std::string name, const std::reference_wrapper<U>& collection,
361  std::function<double(const typename ObjectsRefCollection<U, double>::const_value_type&)> accessor);
362 
363  template <class U> friend ObjectsRefCollection<U, std::string>
364  Collection(std::string name, const std::reference_wrapper<U>& collection,
365  std::function<std::string(const typename ObjectsRefCollection<U, std::string>::const_value_type&)> converterToString);
366 
368 
369  virtual double get([[maybe_unused]] size_t i) const override {
370  if constexpr (std::is_convertible_v<R, double>)
371  return m_converterToR(m_collection.get()[i]);
372  else
373  return -1;
374  }
375 
376  virtual std::string getString([[maybe_unused]] size_t i) const override {
377  if constexpr (std::is_constructible_v<std::string, R>)
378  return m_converterToR(m_collection.get()[i]);
379  else
380  return {};
381  }
382 
383  virtual bool hasStringRepresentation() const override {
385  };
386  virtual size_t size() const override {
387  return std::size(m_collection.get());
388  }
389 
390  private:
391  const std::reference_wrapper<T>& m_collection;
392  std::function<R(const const_value_type&)> m_converterToR;
393 
394  ObjectsRefCollection(std::string name, const std::reference_wrapper<T>& collection,
395  std::function<R(const const_value_type&)> converterToR)
396  : IMonitoredVariable(std::move(name)),
397  m_collection(std::move(collection)),
398  m_converterToR(std::move(converterToR)) {}
399 
401 
403 
404  };
405 
406 } // namespace Monitored
407 
408 #endif /* AthenaMonitoringKernel_MonitoredCollection_h */
Monitored::detail::get_value_type< T[N]>::value_type
T value_type
Definition: MonitoredCollection.h:164
Monitored::detail::make_pointer_const< T * >::type
const T * type
Definition: MonitoredCollection.h:171
Monitored::ValuesRefCollection
Internal class not to be used by end user.
Definition: MonitoredCollection.h:18
Monitored::ObjectsCollection::ObjectsCollection
ObjectsCollection(ObjectsCollection const &)=delete
Monitored::ObjectsCollection::getString
virtual std::string getString([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:311
Monitored::ValuesRefCollection::m_collection
const std::reference_wrapper< T > & m_collection
Definition: MonitoredCollection.h:265
Monitored::ObjectsRefCollection::getString
virtual std::string getString([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:376
Monitored::ObjectsCollection::get
virtual double get([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:304
Monitored::ObjectsRefCollection::Collection
friend ObjectsRefCollection< U, double > Collection(std::string name, const std::reference_wrapper< U > &collection, std::function< double(const typename ObjectsRefCollection< U, double >::const_value_type &)> accessor)
Monitored::ValuesRefCollection::getString
virtual std::string getString([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:249
IMonitoredVariable.h
Monitored::ObjectsCollection::Collection
friend ObjectsCollection< U, double > Collection(std::string name, const U &collection, std::function< double(const typename ObjectsCollection< U, double >::const_value_type &)> accessor)
Monitored::ObjectsRefCollection::m_converterToR
std::function< R(const const_value_type &)> m_converterToR
Definition: MonitoredCollection.h:392
Monitored::ValuesCollection::size
virtual size_t size() const override
Definition: MonitoredCollection.h:209
Monitored::ObjectsRefCollection::size
virtual size_t size() const override
Definition: MonitoredCollection.h:386
Monitored::ObjectsCollection::ObjectsCollection
ObjectsCollection(std::string name, const T &collection, std::function< R(const const_value_type &)> converterToR)
Definition: MonitoredCollection.h:329
Monitored::ValuesRefCollection::operator=
ValuesRefCollection & operator=(ValuesRefCollection const &)=delete
Monitored::ValuesCollection::ValuesCollection
ValuesCollection(std::string vname, const T &collection)
Definition: MonitoredCollection.h:217
athena.value
value
Definition: athena.py:124
Monitored::detail::make_pointer_const
Definition: MonitoredCollection.h:170
detail
Definition: extract_histogram_tag.cxx:14
Monitored::ObjectsCollection
Monitoring of object collections (internal)
Definition: MonitoredCollection.h:19
Monitored::ObjectsCollection::m_collection
const T & m_collection
Definition: MonitoredCollection.h:326
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
Monitored::detail::get_value_type::value_type
T::value_type value_type
Definition: MonitoredCollection.h:162
Monitored::ObjectsCollection::hasStringRepresentation
virtual bool hasStringRepresentation() const override
Definition: MonitoredCollection.h:318
Monitored::detail::get_value_type
Get element type for containers.
Definition: MonitoredCollection.h:162
Monitored::ObjectsCollection::size
virtual size_t size() const override
Definition: MonitoredCollection.h:321
Monitored::ValuesCollection::get
virtual double get([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:191
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
Monitored::ObjectsRefCollection::hasStringRepresentation
virtual bool hasStringRepresentation() const override
Definition: MonitoredCollection.h:383
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Monitored::ObjectsRefCollection::ObjectsRefCollection
ObjectsRefCollection(ObjectsRefCollection &&)=default
Monitored::ValuesRefCollection::ValuesRefCollection
ValuesRefCollection(ValuesRefCollection &&)=default
Monitored::ObjectsCollection::ObjectsCollection
ObjectsCollection(ObjectsCollection &&)=default
Monitored::ValuesRefCollection::hasStringRepresentation
virtual bool hasStringRepresentation() const override
Definition: MonitoredCollection.h:256
Monitored::IMonitoredVariable
Definition: IMonitoredVariable.h:14
Monitored::ObjectsRefCollection::ObjectsRefCollection
ObjectsRefCollection(ObjectsRefCollection const &)=delete
Monitored::ObjectsCollection::m_converterToR
std::function< R(const const_value_type &)> m_converterToR
Definition: MonitoredCollection.h:327
Monitored::ObjectsCollection::Collection
friend ObjectsCollection< U, std::string > Collection(std::string name, const U &collection, std::function< std::string(const typename ObjectsCollection< U, std::string >::const_value_type &)> converterToString)
lumiFormat.i
int i
Definition: lumiFormat.py:85
Monitored::ObjectsRefCollection
Monitoring of object collection references (internal)
Definition: MonitoredCollection.h:20
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
Monitored::ObjectsCollection::const_value_type
typename detail::make_pointer_const< value_type >::type const_value_type
Definition: MonitoredCollection.h:287
Monitored::ValuesRefCollection::ValuesRefCollection
ValuesRefCollection(std::string vname, const std::reference_wrapper< T > &collection)
Definition: MonitoredCollection.h:268
Monitored::ObjectsRefCollection::Collection
friend ObjectsRefCollection< U, std::string > Collection(std::string name, const std::reference_wrapper< U > &collection, std::function< std::string(const typename ObjectsRefCollection< U, std::string >::const_value_type &)> converterToString)
Monitored::ValuesCollection::ValuesCollection
ValuesCollection(ValuesCollection const &)=delete
Monitored::ValuesCollection
Internal class not to be used by end user.
Definition: MonitoredCollection.h:17
Monitored::ObjectsRefCollection::m_collection
const std::reference_wrapper< T > & m_collection
Definition: MonitoredCollection.h:391
Monitored::ObjectsCollection::operator=
ObjectsCollection & operator=(ObjectsCollection const &)=delete
Monitored::detail::make_pointer_const::type
T type
Definition: MonitoredCollection.h:170
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:225
Monitored::ObjectsRefCollection::operator=
ObjectsRefCollection & operator=(ObjectsRefCollection const &)=delete
Monitored::ValuesRefCollection::ValuesRefCollection
ValuesRefCollection(ValuesRefCollection const &)=delete
Monitored::ValuesCollection::m_collection
const T & m_collection
Definition: MonitoredCollection.h:214
Monitored::ValuesCollection::getString
virtual std::string getString([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:198
Monitored::ValuesCollection::ValuesCollection
ValuesCollection(ValuesCollection &&)=default
Monitored::ValuesCollection::operator=
ValuesCollection & operator=(ValuesCollection const &)=delete
xAOD::JetAttributeAccessor::accessor
const AccessorWrapper< T > * accessor(xAOD::JetAttribute::AttributeID id)
Returns an attribute accessor corresponding to an AttributeID.
Definition: JetAccessorMap.h:26
Monitored::ValuesRefCollection::size
virtual size_t size() const override
Definition: MonitoredCollection.h:260
Monitored::ObjectsRefCollection::ObjectsRefCollection
ObjectsRefCollection(std::string name, const std::reference_wrapper< T > &collection, std::function< R(const const_value_type &)> converterToR)
Definition: MonitoredCollection.h:394
Monitored::detail::get_value_type< std::reference_wrapper< T > >::value_type
T::value_type value_type
Definition: MonitoredCollection.h:167
Monitored::ObjectsRefCollection::const_value_type
typename detail::make_pointer_const< value_type >::type const_value_type
Definition: MonitoredCollection.h:352
Monitored::ObjectsRefCollection::get
virtual double get([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:369
Monitored::ValuesCollection::hasStringRepresentation
virtual bool hasStringRepresentation() const override
Definition: MonitoredCollection.h:205
Monitored::ValuesRefCollection::get
virtual double get([[maybe_unused]] size_t i) const override
Definition: MonitoredCollection.h:242
value_type
Definition: EDM_MasterSearch.h:11
Monitored::detail::get_value_type< std::reference_wrapper< T[N]> >::value_type
T value_type
Definition: MonitoredCollection.h:168
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35