The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
HistogramArray.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
14
15#include <fmt/format.h>
16
17#include <boost/container/static_vector.hpp>
18
19#include <array>
20#include <utility>
21
22namespace 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, std::invocable<int> FormatName, std::invocable<int> FormatTitle>
46 HistogramArrayInternal( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
47 typename Histo::AxisTupleType&& allAxis ) {
48 for ( std::size_t i = 0; i < N; i++ ) { this->emplace_back( owner, fname( i ), ftitle( i ), allAxis ); }
49 }
50
51 template <typename OWNER>
52 HistogramArrayInternal( OWNER* owner, std::string_view name, std::string_view title,
53 typename Histo::AxisTupleType&& allAxis ) {
54 for ( std::size_t i = 0; i < N; i++ ) {
55 this->emplace_back( owner, FormatHistDefault{ name }( i ), FormatHistDefault{ title }( i ), allAxis );
56 }
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...>>
102 template <typename OWNER, typename FormatName, typename FormatTitle, std::size_t M = N>
103 HistogramArray( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle, typename Histo::AxisTupleType&& allAxis )
104 : details::HistogramArrayInternal<Histo, N>( owner, fname, ftitle,
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
Efficient counter implementations for Gaudi.
STL namespace.
generic class implementing an array of histograms The only addition to a raw array is the constructor...
HistogramArray(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, typename Histo::AxisTupleType &&allAxis)
HistogramArray(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, AxisType< ND >... allAxis)
Default formating for histogram names and title, only calling fmt::format on the text given at constr...
internal class implementing an "array" of histograms
HistogramArrayInternal(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, typename Histo::AxisTupleType &&allAxis)
constructor with callables for FormatName and FormatTitle
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