The Gaudi Framework  v39r1 (adb068b2)
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 <boost/container/static_vector.hpp>
18 
19 #include <array>
20 #include <utility>
21 
22 namespace Gaudi::Accumulators {
23 
24  namespace details {
25 
31  std::string_view text;
32  FormatHistDefault( std::string_view t ) : text{ t } {}
33  auto operator()( size_t n ) { return fmt::format( fmt::runtime( text ), n ); }
34  };
35 
46  template <typename Histo, std::size_t N, typename = void>
48 
52  template <typename Histo, std::size_t N>
53  struct HistogramArrayInternal<Histo, N, std::enable_if_t<( N < 30 )>> : std::array<Histo, N> {
55  template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t... Ns,
56  typename = typename std::enable_if_t<std::is_invocable_v<FormatName, int>>,
57  typename = typename std::enable_if_t<std::is_invocable_v<FormatTitle, int>>>
58  HistogramArrayInternal( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
59  std::integer_sequence<std::size_t, Ns...>, typename Histo::AxisTupleType&& allAxis )
60  : std::array<Histo, N>{ Histo{ owner, fname( Ns ), ftitle( Ns ), allAxis }... } {}
62  template <typename OWNER, std::size_t... Ns>
63  HistogramArrayInternal( OWNER* owner, std::string_view name, std::string_view title,
64  std::integer_sequence<std::size_t, Ns...>, typename Histo::AxisTupleType&& allAxis )
65  : std::array<Histo, N>{
66  Histo{ owner, FormatHistDefault{ name }( Ns ), FormatHistDefault{ title }( Ns ), allAxis }... } {}
67  };
68 
72  template <typename Histo, std::size_t N>
73  struct HistogramArrayInternal<Histo, N, std::enable_if_t<( N >= 30 )>> : boost::container::static_vector<Histo, N> {
75  template <typename OWNER, typename FormatName, typename FormatTitle,
76  typename = typename std::enable_if_t<std::is_invocable_v<FormatName, int>>,
77  typename = typename std::enable_if_t<std::is_invocable_v<FormatTitle, int>>>
78  HistogramArrayInternal( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
79  typename Histo::AxisTupleType&& allAxis ) {
80  for ( std::size_t i = 0; i < N; i++ ) { this->emplace_back( owner, fname( i ), ftitle( i ), allAxis ); }
81  }
83  template <typename OWNER>
84  HistogramArrayInternal( OWNER* owner, std::string_view name, std::string_view title,
85  typename Histo::AxisTupleType&& allAxis ) {
86  for ( std::size_t i = 0; i < N; i++ ) {
87  this->emplace_back( owner, FormatHistDefault{ name }( i ), FormatHistDefault{ title }( i ), allAxis );
88  }
89  }
90  };
91  } // namespace details
92 
128  template <typename Histo, std::size_t N,
129  typename Seq = std::make_integer_sequence<unsigned int, std::tuple_size_v<typename Histo::AxisTupleType>>>
131  template <typename Histo, std::size_t N, unsigned int... ND>
132  struct HistogramArray<Histo, N, std::integer_sequence<unsigned int, ND...>>
133  : details::HistogramArrayInternal<Histo, N> {
134  template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t M = N,
135  typename std::enable_if_t<( M < 30 ), int> = 0>
136  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, typename Histo::AxisTupleType&& allAxis )
137  : details::HistogramArrayInternal<Histo, N>( owner, fname, ftitle, std::make_integer_sequence<std::size_t, N>{},
138  std::forward<typename Histo::AxisTupleType>( allAxis ) ) {}
139 
140  template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t M = N,
141  typename std::enable_if_t<( M >= 30 ), int> = 0>
142  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, typename Histo::AxisTupleType&& allAxis )
143  : details::HistogramArrayInternal<Histo, N>( owner, fname, ftitle,
144  std::forward<typename Histo::AxisTupleType>( allAxis ) ) {}
145 
146  template <unsigned int I>
147  using AxisType = std::tuple_element_t<I, typename Histo::AxisTupleType>;
148 
149  template <typename OWNER, typename FormatName, typename FormatTitle>
150  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, AxisType<ND>... allAxis )
151  : HistogramArray( owner, fname, ftitle, std::make_tuple( allAxis... ) ) {}
152  };
153 
154 } // namespace Gaudi::Accumulators
IOTest.N
N
Definition: IOTest.py:112
std::integer_sequence
Histogram.h
Gaudi::Accumulators::details::FormatHistDefault::text
std::string_view text
Definition: HistogramArray.h:31
Gaudi::Accumulators::details::FormatHistDefault
Default formating for histogram names and title, only calling fmt::format on the text given at constr...
Definition: HistogramArray.h:30
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:136
Gaudi::Accumulators::HistogramArray
generic class implementing an array of histograms The only addition to a raw array is the constructor...
Definition: HistogramArray.h:130
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:147
details
Definition: AnyDataWrapper.h:19
Gaudi::Accumulators::details::HistogramArrayInternal
internal class implementing an "array" of histograms
Definition: HistogramArray.h:47
std::array
STL class.
Gaudi::Accumulators::details::enable_if_t<(N< 30)> >::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:63
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:150
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::details::enable_if_t<(N< 30)> >::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:58
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.
Gaudi::Accumulators::details::FormatHistDefault::FormatHistDefault
FormatHistDefault(std::string_view t)
Definition: HistogramArray.h:32
std::size_t
Gaudi::Accumulators::details::FormatHistDefault::operator()
auto operator()(size_t n)
Definition: HistogramArray.h:33