The Gaudi Framework  master (37c0b60a)
CounterArray.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2022 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #pragma once
12 
13 #include <Gaudi/Accumulators.h>
14 #include <array>
15 #include <string>
16 #include <utility>
17 
19 
20  namespace details {
21 
27  std::string_view text;
28  FormatCounterDefault( std::string_view t ) : text{ t } {}
29  std::string operator()( size_t n );
30  };
31 
36  template <typename Counter, std::size_t N>
37  struct CounterArrayInternal : std::array<Counter, N> {
39  template <typename OWNER, typename FormatName, std::size_t... Ns,
40  typename = typename std::enable_if_t<std::is_invocable_v<FormatName, int>>>
42  : std::array<Counter, N>{ Counter{ owner, fname( Ns ) }... } {
43  static_assert( sizeof...( Ns ) < 1000, "Using CounterArray with 1000 arrays or more is prohibited. This "
44  "would lead to very long compilation times" );
45  }
47  template <typename OWNER, std::size_t... Ns>
49  : std::array<Counter, N>{ Counter{ owner, FormatCounterDefault{ name }( Ns ) }... } {
50  static_assert( sizeof...( Ns ) < 1000, "Using CounterArray with 1000 arrays or more is prohibited. This "
51  "would lead to very long compilation times" );
52  }
54  template <std::size_t... Ns>
56  return std::array{ ( *this )[Ns].buffer()... };
57  }
58  };
59  } // namespace details
60 
89  template <typename Counter, std::size_t N>
91  template <typename OWNER, typename FormatName>
92  CounterArray( OWNER* owner, FormatName&& fname )
93  : details::CounterArrayInternal<Counter, N>( owner, fname, std::make_integer_sequence<std::size_t, N>{} ) {}
94  auto buffer() {
95  return details::CounterArrayInternal<Counter, N>::buffer( std::make_integer_sequence<std::size_t, N>{} );
96  }
97  };
98 
99 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::details::FormatCounterDefault::operator()
std::string operator()(size_t n)
Definition: CounterArray.cpp:14
std::string
STL class.
IOTest.N
N
Definition: IOTest.py:112
Gaudi::Accumulators::details::CounterArrayInternal::CounterArrayInternal
CounterArrayInternal(OWNER *owner, FormatName &&fname, std::integer_sequence< std::size_t, Ns... >)
constructor with callables for FormatName
Definition: CounterArray.h:41
Gaudi::Accumulators::details::FormatCounterDefault::FormatCounterDefault
FormatCounterDefault(std::string_view t)
Definition: CounterArray.h:28
Gaudi::Accumulators::Counter
A basic integral counter;.
Definition: Accumulators.h:943
std::integer_sequence
Gaudi::Accumulators::details::CounterArrayInternal::buffer
auto buffer(std::integer_sequence< std::size_t, Ns... >)
Method to form an array of buffers.
Definition: CounterArray.h:55
bug_34121.t
t
Definition: bug_34121.py:31
Gaudi::Accumulators::details::FormatCounterDefault
Default formating for counter names, only calling fmt::format on the text given at construction and p...
Definition: CounterArray.h:26
Gaudi::Accumulators::CounterArray::CounterArray
CounterArray(OWNER *owner, FormatName &&fname)
Definition: CounterArray.h:92
details
Definition: AnyDataWrapper.h:19
std::array
STL class.
Gaudi::Accumulators::CounterArray
generic class implementing an array of counters The only addition to a raw array is the constructor t...
Definition: CounterArray.h:90
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::Accumulators::CounterArray::buffer
auto buffer()
Definition: CounterArray.h:94
Accumulators.h
Gaudi::Accumulators
Definition: CounterArray.h:18
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Containers::array
struct GAUDI_API array
Parametrisation class for redirection array - like implementation.
Definition: KeyedObjectManager.h:37
std
STL namespace.
std::size_t
Gaudi::Accumulators::details::CounterArrayInternal::CounterArrayInternal
CounterArrayInternal(OWNER *owner, std::string_view name, std::integer_sequence< std::size_t, Ns... >)
constructor for strings, FormatCounterDefault is used as the default callable
Definition: CounterArray.h:48
Gaudi::Accumulators::details::CounterArrayInternal
internal class implementing an array of counters
Definition: CounterArray.h:37
Gaudi::Accumulators::details::FormatCounterDefault::text
std::string_view text
Definition: CounterArray.h:27