Skip to content

Commit 206c68b

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 206c68b

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

Framework/Core/include/Framework/HistogramRegistry.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ namespace o2::framework
3939
* Static helper class to fill root histograms of any type. Contains functionality to fill once per call or a whole (filtered) table at once.
4040
*/
4141
//**************************************************************************************************
42+
template <typename T>
43+
concept FillValue = std::is_integral_v<T> || std::is_floating_point_v<T> || std::is_enum_v<T>;
44+
4245
struct HistFiller {
4346
// fill any type of histogram (if weight was requested it must be the last argument)
4447
template <typename T, typename... Ts>
45-
static void fillHistAny(std::shared_ptr<T> hist, const Ts&... positionAndWeight);
48+
static void fillHistAny(std::shared_ptr<T> hist, Ts... positionAndWeight)
49+
requires(FillValue<Ts> && ...);
4650

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

128132
// fill hist with values
129133
template <typename... Ts>
130-
void fill(const HistName& histName, Ts&&... positionAndWeight);
134+
void fill(const HistName& histName, Ts... positionAndWeight)
135+
requires(FillValue<Ts> && ...);
131136

132137
// fill hist with content of (filtered) table columns
133138
template <typename... Cs, typename T>
@@ -197,7 +202,8 @@ class HistogramRegistry
197202
//--------------------------------------------------------------------------------------------------
198203

199204
template <typename T, typename... Ts>
200-
void HistFiller::fillHistAny(std::shared_ptr<T> hist, const Ts&... positionAndWeight)
205+
void HistFiller::fillHistAny(std::shared_ptr<T> hist, Ts... positionAndWeight)
206+
requires(FillValue<Ts> && ...)
201207
{
202208
constexpr int nArgs = sizeof...(Ts);
203209

@@ -412,11 +418,16 @@ uint32_t HistogramRegistry::getHistIndex(const T& histName)
412418
}
413419

414420
template <typename... Ts>
415-
void HistogramRegistry::fill(const HistName& histName, Ts&&... positionAndWeight)
421+
void HistogramRegistry::fill(const HistName& histName, Ts... positionAndWeight)
422+
requires(FillValue<Ts> && ...)
416423
{
417-
std::visit([&positionAndWeight...](auto&& hist) { HistFiller::fillHistAny(hist, std::forward<Ts>(positionAndWeight)...); }, mRegistryValue[getHistIndex(histName)]);
424+
std::visit([positionAndWeight...](auto&& hist) { HistFiller::fillHistAny(hist, positionAndWeight...); }, mRegistryValue[getHistIndex(histName)]);
418425
}
419426

427+
extern template void HistogramRegistry::fill(const HistName& histName, double);
428+
extern template void HistogramRegistry::fill(const HistName& histName, float);
429+
extern template void HistogramRegistry::fill(const HistName& histName, int);
430+
420431
template <typename... Cs, typename T>
421432
void HistogramRegistry::fill(const HistName& histName, const T& table, const o2::framework::expressions::Filter& filter)
422433
{

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)