Skip to content
Open
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
87 changes: 81 additions & 6 deletions tree/dataframe/inc/ROOT/RDF/ActionHelpers.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include <ROOT/RHist.hxx>
#include <ROOT/RHistConcurrentFiller.hxx>
#include <ROOT/RHistEngine.hxx>
#include <ROOT/RHistFillContext.hxx>
#include <ROOT/RProfile.hxx>
#include <ROOT/RProfileConcurrentFiller.hxx>
#include <ROOT/RProfileFillContext.hxx>
#include <ROOT/RWeight.hxx>
#endif

Expand Down Expand Up @@ -550,8 +554,6 @@ public:
RHistFillHelper &operator=(RHistFillHelper &&) = default;
~RHistFillHelper() = default;

std::shared_ptr<Result_t> GetResultPtr() const { return fFiller.GetHist(); }

void Initialize() {}
void InitTask(TTreeReader *, unsigned int) {}

Expand Down Expand Up @@ -611,8 +613,6 @@ public:
RHistEngineFillHelper &operator=(RHistEngineFillHelper &&) = default;
~RHistEngineFillHelper() = default;

std::shared_ptr<Result_t> GetResultPtr() const { return fHist; }

void Initialize() {}
void InitTask(TTreeReader *, unsigned int) {}

Expand Down Expand Up @@ -647,6 +647,83 @@ public:

std::string GetActionName() { return "Hist"; }
};

template <bool WithWeight = false>
class R__CLING_PTRCHECK(off) RProfileFillHelper : public RActionImpl<RProfileFillHelper<WithWeight>>,
public ExecLoopTrait<RProfileFillHelper<WithWeight>> {
public:
using Result_t = ROOT::Experimental::RProfile;

private:
std::unique_ptr<ROOT::Experimental::RProfileConcurrentFiller> fFiller;
std::vector<std::shared_ptr<ROOT::Experimental::RProfileFillContext>> fContexts;

public:
RProfileFillHelper(std::shared_ptr<ROOT::Experimental::RProfile> p, unsigned int nSlots)
: fFiller(new ROOT::Experimental::RProfileConcurrentFiller(p)), fContexts(nSlots)
{
for (unsigned int i = 0; i < nSlots; i++) {
fContexts[i] = fFiller->CreateFillContext();
}
}
RProfileFillHelper(const RProfileFillHelper &) = delete;
RProfileFillHelper(RProfileFillHelper &&) = default;
RProfileFillHelper &operator=(const RProfileFillHelper &) = delete;
RProfileFillHelper &operator=(RProfileFillHelper &&) = default;
~RProfileFillHelper() = default;

void Initialize() {}
void InitTask(TTreeReader *, unsigned int) {}

template <typename... ColumnTypes, const std::size_t... I>
void ExecWithValueAndWeight(unsigned int slot, const std::tuple<const ColumnTypes &...> &columnValues,
std::index_sequence<I...>)
{
// Build a tuple of const references with the actual arguments, stripping the value and weight and avoiding
// copies.
std::tuple<const std::tuple_element_t<I, std::tuple<ColumnTypes...>> &...> args(std::get<I>(columnValues)...);
const auto &value = std::get<sizeof...(ColumnTypes) - 2>(columnValues);
ROOT::Experimental::RWeight weight(std::get<sizeof...(ColumnTypes) - 1>(columnValues));
fContexts[slot]->Fill(args, value, weight);
}

template <typename... ColumnTypes, const std::size_t... I>
void
ExecWithValue(unsigned int slot, const std::tuple<const ColumnTypes &...> &columnValues, std::index_sequence<I...>)
{
// Build a tuple of const references with the actual arguments, stripping the value and avoiding copies.
std::tuple<const std::tuple_element_t<I, std::tuple<ColumnTypes...>> &...> args(std::get<I>(columnValues)...);
const auto &value = std::get<sizeof...(ColumnTypes) - 1>(columnValues);
fContexts[slot]->Fill(args, value);
}

template <typename... ColumnTypes>
void ExecSingle(unsigned int slot, const ColumnTypes &...columnValues)
{
auto t = std::forward_as_tuple(columnValues...);
if constexpr (WithWeight) {
ExecWithValueAndWeight(slot, t, std::make_index_sequence<sizeof...(ColumnTypes) - 2>());
} else {
ExecWithValue(slot, t, std::make_index_sequence<sizeof...(ColumnTypes) - 1>());
}
}

void Finalize()
{
for (auto &&context : fContexts) {
context->Flush();
}
}

RProfileFillHelper MakeNew(void *newResult, std::string_view /*variation*/ = "nominal")
{
auto &result = *static_cast<std::shared_ptr<Result_t> *>(newResult);
result->Clear();
return RProfileFillHelper(result, fContexts.size());
}

std::string GetActionName() { return "Profile"; }
};
#endif

class R__CLING_PTRCHECK(off) FillTGraphHelper : public ROOT::Detail::RDF::RActionImpl<FillTGraphHelper> {
Expand Down Expand Up @@ -1522,8 +1599,6 @@ public:

std::string GetActionName() { return "Median"; }

std::shared_ptr<double> GetResultPtr() const { return fResult; }

MedianHelper MakeNew(void *newResult, std::string_view /*variation*/ = "nominal")
{
auto &result = *static_cast<std::shared_ptr<double> *>(newResult);
Expand Down
26 changes: 26 additions & 0 deletions tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ struct Graph{};
struct GraphAsymmErrors{};
struct Profile1D{};
struct Profile2D{};
struct Profile{};
struct ProfileWithWeight{};
struct Min{};
struct Max{};
struct Sum{};
Expand Down Expand Up @@ -225,6 +227,30 @@ BuildAction(const ColumnNames_t &columnList, const std::shared_ptr<ROOT::Experim
using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<ColTypes...>>;
return std::make_unique<Action_t>(Helper_t(h), columnList, std::move(prevNode), colRegister);
}

// Action for RProfile using RProfileConcurrentFiller without weights
template <typename... ColTypes, typename PrevNodeType>
std::unique_ptr<RActionBase>
BuildAction(const ColumnNames_t &columnList, const std::shared_ptr<ROOT::Experimental::RProfile> &p,
const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode, ActionTags::Profile,
const RColumnRegister &colRegister)
{
using Helper_t = RProfileFillHelper<>;
using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<ColTypes...>>;
return std::make_unique<Action_t>(Helper_t(p, nSlots), columnList, std::move(prevNode), colRegister);
}

// Action for RProfile using RProfileConcurrentFiller with weights
template <typename... ColTypes, typename PrevNodeType>
std::unique_ptr<RActionBase>
BuildAction(const ColumnNames_t &columnList, const std::shared_ptr<ROOT::Experimental::RProfile> &p,
const unsigned int nSlots, std::shared_ptr<PrevNodeType> prevNode, ActionTags::ProfileWithWeight,
const RColumnRegister &colRegister)
{
using Helper_t = RProfileFillHelper<true>;
using Action_t = RAction<Helper_t, PrevNodeType, TTraits::TypeList<ColTypes...>>;
return std::make_unique<Action_t>(Helper_t(p, nSlots), columnList, std::move(prevNode), colRegister);
}
#endif

template <typename... ColTypes, typename PrevNodeType>
Expand Down
Loading
Loading