The Gaudi Framework  master (37c0b60a)
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 
42  template <typename Histo, std::size_t N>
43  struct HistogramArrayInternal : boost::container::static_vector<Histo, N> {
45  template <typename OWNER, typename FormatName, typename FormatTitle,
46  typename = typename std::enable_if_t<std::is_invocable_v<FormatName, int>>,
47  typename = typename std::enable_if_t<std::is_invocable_v<FormatTitle, int>>>
48  HistogramArrayInternal( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
49  typename Histo::AxisTupleType&& allAxis ) {
50  for ( std::size_t i = 0; i < N; i++ ) { this->emplace_back( owner, fname( i ), ftitle( i ), allAxis ); }
51  }
53  template <typename OWNER>
54  HistogramArrayInternal( OWNER* owner, std::string_view name, std::string_view title,
55  typename Histo::AxisTupleType&& allAxis ) {
56  for ( std::size_t i = 0; i < N; i++ ) {
57  this->emplace_back( owner, FormatHistDefault{ name }( i ), FormatHistDefault{ title }( i ), allAxis );
58  }
59  }
60  };
61  } // namespace details
62 
98  template <typename Histo, std::size_t N,
99  typename Seq = std::make_integer_sequence<unsigned int, std::tuple_size_v<typename Histo::AxisTupleType>>>
101  template <typename Histo, std::size_t N, unsigned int... ND>
102  struct HistogramArray<Histo, N, std::integer_sequence<unsigned int, ND...>>
103  : details::HistogramArrayInternal<Histo, N> {
104  template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t M = N>
105  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, typename Histo::AxisTupleType&& allAxis )
106  : details::HistogramArrayInternal<Histo, N>( owner, fname, ftitle,
107  std::forward<typename Histo::AxisTupleType>( allAxis ) ) {}
108 
109  template <unsigned int I>
110  using AxisType = std::tuple_element_t<I, typename Histo::AxisTupleType>;
111 
112  template <typename OWNER, typename FormatName, typename FormatTitle>
113  HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, AxisType<ND>... allAxis )
114  : HistogramArray( owner, fname, ftitle, std::make_tuple( allAxis... ) ) {}
115  };
116 
117 } // namespace Gaudi::Accumulators
Gaudi::Accumulators::details::HistogramArrayInternal::HistogramArrayInternal
HistogramArrayInternal(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, typename Histo::AxisTupleType &&allAxis)
constructor with callables for FormatName and FormatTitle
Definition: HistogramArray.h:48
IOTest.N
N
Definition: IOTest.py:112
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
generic class implementing an array of histograms The only addition to a raw array is the constructor...
Definition: HistogramArray.h:100
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:105
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:110
details
Definition: AnyDataWrapper.h:19
Gaudi::Accumulators::details::HistogramArrayInternal
internal class implementing an "array" of histograms
Definition: HistogramArray.h:43
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:113
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
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
std
STL namespace.
Gaudi::Accumulators::details::HistogramArrayInternal::HistogramArrayInternal
HistogramArrayInternal(OWNER *owner, std::string_view name, std::string_view title, typename Histo::AxisTupleType &&allAxis)
constructor for strings, FormatHistDefault is used as the default callable
Definition: HistogramArray.h:54
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