Skip to content

Commit

Permalink
DPL: cleanup HistogramRegistry::fill function
Browse files Browse the repository at this point in the history
* make sure that the fill method fills arithmetic types.
* instanciate templates for common case
  • Loading branch information
ktf committed Mar 13, 2024
1 parent fc10ef8 commit bb1f858
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Framework/Core/include/Framework/HistogramRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ namespace o2::framework
* Static helper class to fill root histograms of any type. Contains functionality to fill once per call or a whole (filtered) table at once.
*/
//**************************************************************************************************
template <typename T>
concept FillValue = std::is_integral_v<T> || std::is_floating_point_v<T> || std::is_enum_v<T>;

struct HistFiller {
// fill any type of histogram (if weight was requested it must be the last argument)
template <typename T, typename... Ts>
static void fillHistAny(std::shared_ptr<T> hist, const Ts&... positionAndWeight);
static void fillHistAny(std::shared_ptr<T> hist, Ts... positionAndWeight)
requires(FillValue<Ts> && ...);

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

// fill hist with values
template <typename... Ts>
void fill(const HistName& histName, Ts&&... positionAndWeight);
void fill(const HistName& histName, Ts... positionAndWeight)
requires(FillValue<Ts> && ...);

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

template <typename T, typename... Ts>
void HistFiller::fillHistAny(std::shared_ptr<T> hist, const Ts&... positionAndWeight)
void HistFiller::fillHistAny(std::shared_ptr<T> hist, Ts... positionAndWeight)
requires(FillValue<Ts> && ...)
{
constexpr int nArgs = sizeof...(Ts);

Expand Down Expand Up @@ -412,11 +418,16 @@ uint32_t HistogramRegistry::getHistIndex(const T& histName)
}

template <typename... Ts>
void HistogramRegistry::fill(const HistName& histName, Ts&&... positionAndWeight)
void HistogramRegistry::fill(const HistName& histName, Ts... positionAndWeight)
requires(FillValue<Ts> && ...)
{
std::visit([&positionAndWeight...](auto&& hist) { HistFiller::fillHistAny(hist, std::forward<Ts>(positionAndWeight)...); }, mRegistryValue[getHistIndex(histName)]);
std::visit([positionAndWeight...](auto&& hist) { HistFiller::fillHistAny(hist, positionAndWeight...); }, mRegistryValue[getHistIndex(histName)]);
}

extern template void HistogramRegistry::fill(const HistName& histName, double);
extern template void HistogramRegistry::fill(const HistName& histName, float);
extern template void HistogramRegistry::fill(const HistName& histName, int);

template <typename... Cs, typename T>
void HistogramRegistry::fill(const HistName& histName, const T& table, const o2::framework::expressions::Filter& filter)
{
Expand Down
4 changes: 4 additions & 0 deletions Framework/Core/src/HistogramRegistry.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
namespace o2::framework
{

template void HistogramRegistry::fill(const HistName& histName, double);
template void HistogramRegistry::fill(const HistName& histName, float);
template void HistogramRegistry::fill(const HistName& histName, int);

constexpr HistogramRegistry::HistName::HistName(char const* const name)
: str(name),
hash(runtime_hash(name)),
Expand Down

0 comments on commit bb1f858

Please sign in to comment.