The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
CounterArray.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 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
18namespace Gaudi::Accumulators {
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, std::invocable<int> FormatName, std::size_t... Ns>
40 CounterArrayInternal( OWNER* owner, FormatName&& fname, std::integer_sequence<std::size_t, Ns...> )
41 : std::array<Counter, N>{ Counter{ owner, fname( Ns ) }... } {
42 static_assert( sizeof...( Ns ) < 1000, "Using CounterArray with 1000 arrays or more is prohibited. This "
43 "would lead to very long compilation times" );
44 }
45
46 template <typename OWNER, std::size_t... Ns>
47 CounterArrayInternal( OWNER* owner, std::string_view name, std::integer_sequence<std::size_t, Ns...> )
48 : std::array<Counter, N>{ Counter{ owner, FormatCounterDefault{ name }( Ns ) }... } {
49 static_assert( sizeof...( Ns ) < 1000, "Using CounterArray with 1000 arrays or more is prohibited. This "
50 "would lead to very long compilation times" );
51 }
52
53 template <std::size_t... Ns>
54 auto buffer( std::integer_sequence<std::size_t, Ns...> ) {
55 return std::array{ ( *this )[Ns].buffer()... };
56 }
57 };
58 } // namespace details
59
88 template <typename Counter, std::size_t N>
90 template <typename OWNER, typename FormatName>
91 CounterArray( OWNER* owner, FormatName&& fname )
92 : details::CounterArrayInternal<Counter, N>( owner, fname, std::make_integer_sequence<std::size_t, N>{} ) {}
93 auto buffer() {
94 return details::CounterArrayInternal<Counter, N>::buffer( std::make_integer_sequence<std::size_t, N>{} );
95 }
96 };
97
98} // namespace Gaudi::Accumulators
Efficient counter implementations for Gaudi.
STL namespace.
CounterArray(OWNER *owner, FormatName &&fname)
A basic integral counter;.
internal class implementing an array of counters
CounterArrayInternal(OWNER *owner, FormatName &&fname, std::integer_sequence< std::size_t, Ns... >)
constructor with callables for FormatName
auto buffer(std::integer_sequence< std::size_t, Ns... >)
Method to form an array of buffers.
CounterArrayInternal(OWNER *owner, std::string_view name, std::integer_sequence< std::size_t, Ns... >)
constructor for strings, FormatCounterDefault is used as the default callable
Default formating for counter names, only calling fmt::format on the text given at construction and p...