File indexing completed on 2025-07-14 08:52:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <Gaudi/Accumulators/Histogram.h>
0014
0015 #include <fmt/format.h>
0016
0017 #include <utility>
0018
0019 namespace Gaudi::Accumulators {
0020
0021 namespace details {
0022
0023
0024
0025
0026
0027 struct FormatHistDefault {
0028 std::string_view text;
0029 FormatHistDefault( std::string_view t ) : text{ t } {}
0030 auto operator()( size_t n ) { return fmt::format( fmt::runtime( text ), n ); }
0031 };
0032
0033
0034
0035
0036
0037 template <typename Histo, std::size_t N>
0038 struct HistogramArrayInternal : std::array<Histo, N> {
0039
0040 template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t... Ns,
0041 typename = typename std::enable_if_t<std::is_invocable_v<FormatName, int>>,
0042 typename = typename std::enable_if_t<std::is_invocable_v<FormatTitle, int>>>
0043 HistogramArrayInternal( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
0044 std::integer_sequence<std::size_t, Ns...>, typename Histo::AxisTupleType&& allAxis )
0045 : std::array<Histo, N>{ Histo{ owner, fname( Ns ), ftitle( Ns ), allAxis }... } {
0046 static_assert( sizeof...( Ns ) < 1000, "Using HistogramArray with 1000 arrays or more is prohibited. This "
0047 "would lead to very long compilation times" );
0048 }
0049
0050 template <typename OWNER, std::size_t... Ns>
0051 HistogramArrayInternal( OWNER* owner, std::string_view name, std::string_view title,
0052 std::integer_sequence<std::size_t, Ns...>, typename Histo::AxisTupleType&& allAxis )
0053 : std::array<Histo, N>{
0054 Histo{ owner, FormatHistDefault{ name }( Ns ), FormatHistDefault{ title }( Ns ), allAxis }... } {
0055 static_assert( sizeof...( Ns ) < 1000, "Using HistogramArray with 1000 arrays or more is prohibited. This "
0056 "would lead to very long compilation times" );
0057 }
0058 };
0059 }
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 template <typename Histo, std::size_t N,
0097 typename Seq = std::make_integer_sequence<unsigned int, std::tuple_size_v<typename Histo::AxisTupleType>>>
0098 struct HistogramArray;
0099 template <typename Histo, std::size_t N, unsigned int... ND>
0100 struct HistogramArray<Histo, N, std::integer_sequence<unsigned int, ND...>>
0101 : details::HistogramArrayInternal<Histo, N> {
0102 template <typename OWNER, typename FormatName, typename FormatTitle>
0103 HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, typename Histo::AxisTupleType&& allAxis )
0104 : details::HistogramArrayInternal<Histo, N>( owner, fname, ftitle, std::make_integer_sequence<std::size_t, N>{},
0105 std::forward<typename Histo::AxisTupleType>( allAxis ) ) {}
0106
0107 template <unsigned int I>
0108 using AxisType = std::tuple_element_t<I, typename Histo::AxisTupleType>;
0109
0110 template <typename OWNER, typename FormatName, typename FormatTitle>
0111 HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, AxisType<ND>... allAxis )
0112 : HistogramArray( owner, fname, ftitle, std::make_tuple( allAxis... ) ) {}
0113 };
0114
0115 }