The Gaudi Framework
master (9f3f8895)
Toggle main menu visibility
Loading...
Searching...
No Matches
HistogramMap.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
13
#include <
Gaudi/Accumulators/StaticHistogram.h
>
14
15
#include <fmt/format.h>
16
17
#include <map>
18
#include <mutex>
19
20
namespace
Gaudi::Accumulators
{
21
22
namespace
details
{
23
28
template
<
typename
Key>
29
struct
FormatHistDefaultT
{
30
std::string
text
;
31
FormatHistDefaultT
( std::string_view t ) :
text
{ t } {}
32
auto
operator()
( Key k ) {
return
fmt::format( fmt::runtime(
text
), k ); }
33
};
34
40
template
<
typename
Key,
typename
Histo>
41
class
HistogramMapInternal
{
42
public
:
44
template
<
typename
OWNER, std::invocable<Key const&> FormatName, std::invocable<Key const&> FormatTitle>
45
HistogramMapInternal
( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
46
typename
Histo::AxisTupleType&& allAxis )
47
:
m_makeHisto
{ [owner, fname, ftitle, allAxis, this]( Key const& k ) -> Histo& {
48
return
m_map
49
.emplace( std::piecewise_construct, std::forward_as_tuple( k ),
50
std::forward_as_tuple( owner, fname( k ), ftitle( k ), allAxis ) )
51
.first->second;
52
} } {}
53
54
template
<
typename
OWNER>
55
HistogramMapInternal
( OWNER* owner, std::string_view name, std::string_view title,
56
typename
Histo::AxisTupleType&& allAxis )
57
:
m_makeHisto
{ [owner, name, title, allAxis, this]( Key const& k ) -> Histo& {
58
return
m_map
59
.emplace( std::piecewise_construct, std::forward_as_tuple( k ),
60
std::forward_as_tuple( owner,
FormatHistDefaultT<Key>
( name )( k ),
61
FormatHistDefaultT<Key>
( title )( k ), allAxis ) )
62
.first->second;
63
} } {}
64
65
Histo&
operator[]
( Key
const
& k )
const
{
66
std::scoped_lock lock{
m_mapLock
};
67
auto
it =
m_map
.find( k );
68
if
( it !=
m_map
.end() )
return
it->second;
69
return
m_makeHisto
( k );
70
}
71
72
private
:
73
mutable
std::map<Key, Histo>
m_map
;
74
mutable
std::mutex
m_mapLock
{};
75
std::function<Histo&( Key
const
& )>
m_makeHisto
;
76
// operator[],
77
};
78
}
// namespace details
79
123
template
<
typename
Key,
typename
Histo,
124
typename
Seq = std::make_integer_sequence<unsigned int, std::tuple_size_v<typename Histo::AxisTupleType>>>
125
struct
HistogramMap
;
126
template
<
typename
Key,
typename
Histo,
unsigned
int
... ND>
127
struct
HistogramMap
<Key, Histo,
std
::integer_sequence<unsigned int, ND...>>
128
:
details::HistogramMapInternal
<Key, Histo> {
129
template
<
typename
OWNER,
typename
FormatName,
typename
FormatTitle>
130
HistogramMap
( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
typename
Histo::AxisTupleType&& allAxis )
131
:
details
::
HistogramMapInternal
<Key, Histo>( owner, fname, ftitle,
132
std
::forward<typename Histo::AxisTupleType>( allAxis ) ) {}
133
134
template
<
unsigned
int
I>
135
using
AxisType
= std::tuple_element_t<I, typename Histo::AxisTupleType>;
136
137
template
<
typename
OWNER,
typename
FormatName,
typename
FormatTitle>
138
HistogramMap
( OWNER* owner, FormatName&& fname, FormatTitle&& ftitle,
AxisType<ND>
... allAxis )
139
:
HistogramMap
( owner, fname, ftitle,
std
::make_tuple( allAxis... ) ) {}
140
};
141
142
}
// namespace Gaudi::Accumulators
StaticHistogram.h
Gaudi::Accumulators::details::HistogramMapInternal
internal class implementing a map of histograms
Definition
HistogramMap.h:41
Gaudi::Accumulators::details::HistogramMapInternal::HistogramMapInternal
HistogramMapInternal(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, typename Histo::AxisTupleType &&allAxis)
constructor with callables for FormatName and FormatTitle
Definition
HistogramMap.h:45
Gaudi::Accumulators::details::HistogramMapInternal::operator[]
Histo & operator[](Key const &k) const
operator[] method, made thread safe and thus declared const
Definition
HistogramMap.h:65
Gaudi::Accumulators::details::HistogramMapInternal::m_makeHisto
std::function< Histo &(Key const &)> m_makeHisto
Definition
HistogramMap.h:75
Gaudi::Accumulators::details::HistogramMapInternal::m_mapLock
std::mutex m_mapLock
Definition
HistogramMap.h:74
Gaudi::Accumulators::details::HistogramMapInternal::m_map
std::map< Key, Histo > m_map
Definition
HistogramMap.h:73
Gaudi::Accumulators::details::HistogramMapInternal::HistogramMapInternal
HistogramMapInternal(OWNER *owner, std::string_view name, std::string_view title, typename Histo::AxisTupleType &&allAxis)
constructor for strings, FormatHistDefaultT is used as the default callable
Definition
HistogramMap.h:55
Gaudi::Accumulators::details
Definition
Accumulators.h:1177
Gaudi::Accumulators
Efficient counter implementations for Gaudi.
Definition
Accumulators.h:18
details
Definition
AnyDataWrapper.h:19
std
STL namespace.
Gaudi::Accumulators::HistogramMap< Key, Histo, std::integer_sequence< unsigned int, ND... > >::HistogramMap
HistogramMap(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, AxisType< ND >... allAxis)
Definition
HistogramMap.h:138
Gaudi::Accumulators::HistogramMap< Key, Histo, std::integer_sequence< unsigned int, ND... > >::HistogramMap
HistogramMap(OWNER *owner, FormatName &&fname, FormatTitle &&ftitle, typename Histo::AxisTupleType &&allAxis)
Definition
HistogramMap.h:130
Gaudi::Accumulators::HistogramMap< Key, Histo, std::integer_sequence< unsigned int, ND... > >::AxisType
std::tuple_element_t< I, typename Histo::AxisTupleType > AxisType
Definition
HistogramMap.h:135
Gaudi::Accumulators::HistogramMap
generic class implementing a thread safe map of histograms
Definition
HistogramMap.h:125
Gaudi::Accumulators::details::FormatHistDefaultT
Default formating for histogram names and title, only calling fmt::format on the text given at constr...
Definition
HistogramMap.h:29
Gaudi::Accumulators::details::FormatHistDefaultT::operator()
auto operator()(Key k)
Definition
HistogramMap.h:32
Gaudi::Accumulators::details::FormatHistDefaultT::text
std::string text
Definition
HistogramMap.h:30
Gaudi::Accumulators::details::FormatHistDefaultT::FormatHistDefaultT
FormatHistDefaultT(std::string_view t)
Definition
HistogramMap.h:31
GaudiKernel
include
Gaudi
Accumulators
HistogramMap.h
Generated on
for The Gaudi Framework by
1.17.0