Skip to content

Commit 6595db0

Browse files
committed
DPL: cleanup HistogramRegistry::fill function
* make sure that the fill method fills arithmetic types. * instanciate templates for common case
1 parent fcd565d commit 6595db0

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Framework/Core/include/Framework/HistogramRegistry.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ namespace o2::framework
4242
struct HistFiller {
4343
// fill any type of histogram (if weight was requested it must be the last argument)
4444
template <typename T, typename... Ts>
45-
static void fillHistAny(std::shared_ptr<T> hist, const Ts&... positionAndWeight);
45+
static void fillHistAny(std::shared_ptr<T> hist, Ts... positionAndWeight)
46+
requires(std::is_arithmetic_v<Ts> && ...);
4647

4748
// fill any type of histogram with columns (Cs) of a filtered table (if weight is requested it must reside the last specified column)
4849
template <typename... Cs, typename R, typename T>
@@ -127,7 +128,8 @@ class HistogramRegistry
127128

128129
// fill hist with values
129130
template <typename... Ts>
130-
void fill(const HistName& histName, Ts&&... positionAndWeight);
131+
void fill(const HistName& histName, Ts... positionAndWeight)
132+
requires(std::is_arithmetic_v<Ts> && ...);
131133

132134
// fill hist with content of (filtered) table columns
133135
template <typename... Cs, typename T>
@@ -197,7 +199,8 @@ class HistogramRegistry
197199
//--------------------------------------------------------------------------------------------------
198200

199201
template <typename T, typename... Ts>
200-
void HistFiller::fillHistAny(std::shared_ptr<T> hist, const Ts&... positionAndWeight)
202+
void HistFiller::fillHistAny(std::shared_ptr<T> hist, Ts... positionAndWeight)
203+
requires(std::is_arithmetic_v<Ts> && ...)
201204
{
202205
constexpr int nArgs = sizeof...(Ts);
203206

@@ -412,11 +415,16 @@ uint32_t HistogramRegistry::getHistIndex(const T& histName)
412415
}
413416

414417
template <typename... Ts>
415-
void HistogramRegistry::fill(const HistName& histName, Ts&&... positionAndWeight)
418+
void HistogramRegistry::fill(const HistName& histName, Ts... positionAndWeight)
419+
requires(std::is_arithmetic_v<Ts> && ...)
416420
{
417-
std::visit([&positionAndWeight...](auto&& hist) { HistFiller::fillHistAny(hist, std::forward<Ts>(positionAndWeight)...); }, mRegistryValue[getHistIndex(histName)]);
421+
std::visit([positionAndWeight...](auto&& hist) { HistFiller::fillHistAny(hist, positionAndWeight...); }, mRegistryValue[getHistIndex(histName)]);
418422
}
419423

424+
extern template void HistogramRegistry::fill(const HistName& histName, double);
425+
extern template void HistogramRegistry::fill(const HistName& histName, float);
426+
extern template void HistogramRegistry::fill(const HistName& histName, int);
427+
420428
template <typename... Cs, typename T>
421429
void HistogramRegistry::fill(const HistName& histName, const T& table, const o2::framework::expressions::Filter& filter)
422430
{

Framework/Core/src/HistogramRegistry.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
namespace o2::framework
1818
{
1919

20+
template void HistogramRegistry::fill(const HistName& histName, double);
21+
template void HistogramRegistry::fill(const HistName& histName, float);
22+
template void HistogramRegistry::fill(const HistName& histName, int);
23+
2024
constexpr HistogramRegistry::HistName::HistName(char const* const name)
2125
: str(name),
2226
hash(runtime_hash(name)),

0 commit comments

Comments
 (0)