The Gaudi Framework  v39r0 (5b8b5eda)
HistogramArray.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 
14 
15 #include <fmt/format.h>
16 
17 #include <utility>
18 
19 namespace Gaudi::Accumulators {
20 
21  namespace details {
22 
28  std::string_view text;
29  FormatHistDefault( std::string_view t ) : text{ t } {}
30  auto operator()( size_t n ) { return fmt::format( fmt::runtime( text ), n ); }
31  };
32 
37  template <typename Histo, std::size_t N>
38  struct HistogramArrayInternal : std::array<Histo, N> {
40  template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t... Ns,
41  typename = typename std::enable_if_t<std::is_invocable_v<FormatName, int>>,
42  typename = typename std::enable_if_t<std::is_invocable_v<FormatTitle, int>>>
43  HistogramArrayInternal( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
44  std::integer_sequence<std::size_t, Ns...>, typename Histo::AxisTupleType&& allAxis )
45  : std::array<Histo, N>{ Histo{ owner, fname( Ns ), ftitle( Ns ), allAxis }... } {
46  static_assert( sizeof...( Ns ) < 1000, "Using HistogramArray with 1000 arrays or more is prohibited. This "
47  "would lead to very long compilation times" );
48  }
50  template <typename OWNER, std::size_t... Ns>
51  HistogramArrayInternal( OWNER* owner, std::string_view name, std::string_view title,
52  std::integer_sequence<std::size_t, Ns...>, typename Histo::AxisTupleType&& allAxis )
53  : std::array<Histo, N>{
54  Histo{ owner, FormatHistDefault{ name }( Ns ), FormatHistDefault{ title }( Ns ), allAxis }... } {
55  static_assert( sizeof...( Ns ) < 1000, "Using HistogramArray with 1000 arrays or more is prohibited. This "
56  "would lead to very long compilation times" );
57  }
58  };
59  } // namespace details
60 
96  template <typename Histo, std::size_t N,
97  typename Seq = std::make_integer_sequence<unsigned int, std::tuple_size_v<typename Histo::AxisTupleType>>>
99  template <typename Histo, std::size_t N, unsigned int... ND>
100  struct HistogramArray<Histo, N, std::integer_sequence<unsigned int, ND...>>
101  : details::HistogramArrayInternal<Histo, N> {
102  template <typename OWNER, typename FormatName, typename FormatTitle>
103  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, typename Histo::AxisTupleType&& allAxis )
104  : details::HistogramArrayInternal<Histo, N>( owner, fname, ftitle, std::make_integer_sequence<std::size_t, N>{},
105  std::forward<typename Histo::AxisTupleType>( allAxis ) ) {}
106 
107  template <unsigned int I>
108  using AxisType = std::tuple_element_t<I, typename Histo::AxisTupleType>;
109 
110  template <typename OWNER, typename FormatName, typename FormatTitle>
111  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, AxisType<ND>... allAxis )
112  : HistogramArray( owner, fname, ftitle, std::make_tuple( allAxis... ) ) {}
113  };
114 
115 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::details::HistogramArrayInternal::HistogramArrayInternal
HistogramArrayInternal(OWNER *owner, std::string_view name, std::string_view title, std::integer_sequence< std::size_t, Ns... >, typename Histo::AxisTupleType &&allAxis)
constructor for strings, FormatHistDefault is used as the default callable
Definition: HistogramArray.h:51
IOTest.N
N
Definition: IOTest.py:112
std::integer_sequence
Histogram.h
Gaudi::Accumulators::details::FormatHistDefault::text
std::string_view text
Definition: HistogramArray.h:28
Gaudi::Accumulators::details::FormatHistDefault
Default formating for histogram names and title, only calling fmt::format on the text given at constr...
Definition: HistogramArray.h:27
Gaudi::Accumulators::HistogramArray
generic class implementing an array of histograms The only addition to a raw array is the constructor...
Definition: HistogramArray.h:98
bug_34121.t
t
Definition: bug_34121.py:31
Gaudi::Accumulators::HistogramArray< Histo, N, std::integer_sequence< unsigned int, ND... > >::AxisType
std::tuple_element_t< I, typename Histo::AxisTupleType > AxisType
Definition: HistogramArray.h:108
details
Definition: AnyDataWrapper.h:19
Gaudi::Accumulators::details::HistogramArrayInternal
internal class implementing an array of histograms
Definition: HistogramArray.h:38
std::array
STL class.
Gaudi::Accumulators::HistogramArray< Histo, N, std::integer_sequence< unsigned int, ND... > >::HistogramArray
HistogramArray(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, AxisType< ND >... allAxis)
Definition: HistogramArray.h:111
format
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:119
cpluginsvc.n
n
Definition: cpluginsvc.py:234
Gaudi::Accumulators
Definition: CounterArray.h:18
Gaudi::Accumulators::details::HistogramArrayInternal::HistogramArrayInternal
HistogramArrayInternal(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, std::integer_sequence< std::size_t, Ns... >, typename Histo::AxisTupleType &&allAxis)
constructor with callables for FormatName and FormatTitle
Definition: HistogramArray.h:43
Gaudi::Accumulators::HistogramArray< Histo, N, std::integer_sequence< unsigned int, ND... > >::HistogramArray
HistogramArray(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, typename Histo::AxisTupleType &&allAxis)
Definition: HistogramArray.h:103
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.
Gaudi::Accumulators::details::FormatHistDefault::FormatHistDefault
FormatHistDefault(std::string_view t)
Definition: HistogramArray.h:29
std::size_t
Gaudi::Accumulators::details::FormatHistDefault::operator()
auto operator()(size_t n)
Definition: HistogramArray.h:30