Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions hist/histv7/doc/CodeArchitecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ It also keeps statistics of the unbinned values for each dimension.
This class combines `RHistEngine`, with its axes and bin contents, and `RHistStats`.
During `Fill`, it delegates to `RHistEngine::Fill` but also updates the histogram statistics.

### `RProfile`

This class builds on `RHistEngine`, but requires an additional value during `Fill`.

## Classes for Weighted Filling

### `RBinWithError`
Expand Down
1 change: 1 addition & 0 deletions hist/histv7/headers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(histv7_headers
ROOT/RHistStats.hxx
ROOT/RHistUtils.hxx
ROOT/RLinearizedIndex.hxx
ROOT/RProfile.hxx
ROOT/RRegularAxis.hxx
ROOT/RSliceBinIndexMapper.hxx
ROOT/RSliceSpec.hxx
Expand Down
4 changes: 4 additions & 0 deletions hist/histv7/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#pragma link C++ class ROOT::Experimental::RHistEngine<double>-;
#pragma link C++ class ROOT::Experimental::RHistEngine<ROOT::Experimental::RBinWithError>-;

#pragma link C++ class ROOT::Experimental::RProfile::RProfileBin-;
#pragma link C++ class ROOT::Experimental::RHistEngine<ROOT::Experimental::RProfile::RProfileBin>-;
#pragma link C++ class ROOT::Experimental::RProfile-;

#pragma link C++ class ROOT::Experimental::RAxisVariant-;
#pragma link C++ class ROOT::Experimental::RCategoricalAxis-;
#pragma link C++ class ROOT::Experimental::RHistStats-;
Expand Down
1 change: 0 additions & 1 deletion hist/histv7/inc/ROOT/RHist.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "RAxisVariant.hxx"
#include "RBinIndex.hxx"
#include "RBinIndexMultiDimRange.hxx"
#include "RCategoricalAxis.hxx"
#include "RHistEngine.hxx"
#include "RHistStats.hxx"
#include "RRegularAxis.hxx"
Expand Down
31 changes: 24 additions & 7 deletions hist/histv7/inc/ROOT/RHistEngine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class RHistEngine final {
// For slicing, RHist needs to call SliceImpl.
friend class RHist<BinContentType>;

friend class RProfile;

/// The axis configuration for this histogram. Relevant methods are forwarded from the public interface.
Internal::RAxes fAxes;
/// The bin contents for this histogram
Expand Down Expand Up @@ -407,6 +409,25 @@ public:
}
}

/// \}
// End the group to ensure that all contained member functions are public.

private:
// Also used by RProfile::Fill(const A &... args)
template <std::size_t N, typename... A, typename W>
void FillImpl(const std::tuple<A...> &args, const W &weight)
{
RLinearizedIndex index = fAxes.ComputeGlobalIndexImpl<N>(args);
if (index.fValid) {
assert(index.fIndex < fBinContents.size());
fBinContents[index.fIndex] += weight;
}
}

public:
/// \name Filling
/// \{

/// Fill an entry into the histogram with a user-defined weight.
///
/// This overload is only available for user-defined bin content types.
Expand All @@ -430,11 +451,7 @@ public:
if (sizeof...(A) != GetNDimensions()) {
throw std::invalid_argument("invalid number of arguments to Fill");
}
RLinearizedIndex index = fAxes.ComputeGlobalIndexImpl<sizeof...(A)>(args);
if (index.fValid) {
assert(index.fIndex < fBinContents.size());
fBinContents[index.fIndex] += weight;
}
FillImpl<sizeof...(A)>(args, weight);
}

/// Fill an entry into the histogram.
Expand Down Expand Up @@ -470,7 +487,7 @@ public:
if constexpr (std::is_same_v<typename Internal::LastType<A...>::type, RWeight>) {
static_assert(SupportsWeightedFilling, "weighted filling is not supported for integral bin content types");
static constexpr std::size_t N = sizeof...(A) - 1;
if (N != fAxes.GetNDimensions()) {
if (N != GetNDimensions()) {
throw std::invalid_argument("invalid number of arguments to Fill");
}
RWeight weight = std::get<N>(t);
Expand Down Expand Up @@ -566,7 +583,7 @@ public:
if constexpr (std::is_same_v<typename Internal::LastType<A...>::type, RWeight>) {
static_assert(SupportsWeightedFilling, "weighted filling is not supported for integral bin content types");
static constexpr std::size_t N = sizeof...(A) - 1;
if (N != fAxes.GetNDimensions()) {
if (N != GetNDimensions()) {
throw std::invalid_argument("invalid number of arguments to Fill");
}
RWeight weight = std::get<N>(t);
Expand Down
15 changes: 15 additions & 0 deletions hist/histv7/inc/ROOT/RHistUtils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#ifndef ROOT_RHistUtils
#define ROOT_RHistUtils

#include <tuple>
#include <type_traits>
#include <utility>

#ifdef _MSC_VER
#include <atomic>
Expand All @@ -25,6 +27,19 @@ struct LastType<T> {
using type = T;
};

template <typename... Ts, std::size_t... I, typename A>
std::tuple<const Ts &..., const A &>
AppendReferenceImpl(const std::tuple<Ts...> &t, std::index_sequence<I...>, const A &a)
{
return std::tuple<const Ts &..., const A &>(std::get<I>(t)..., a);
}

template <typename... Ts, typename A>
std::tuple<const Ts &..., const A &> AppendReference(const std::tuple<Ts...> &t, const A &a)
{
return AppendReferenceImpl(t, std::make_index_sequence<sizeof...(Ts)>(), a);
}

#ifdef _MSC_VER
namespace MSVC {
template <std::size_t N>
Expand Down
Loading
Loading