Logo ROOT   6.16/01
Reference Guide
RCustomColumn.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo CERN 09/2018
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RCUSTOMCOLUMN
12#define ROOT_RCUSTOMCOLUMN
13
17#include "ROOT/RDF/Utils.hxx"
19#include "ROOT/RStringView.hxx"
20#include "ROOT/TypeTraits.hxx"
21#include "RtypesCore.h"
22
23#include <deque>
24#include <type_traits>
25#include <vector>
26
27class TTreeReader;
28
29namespace ROOT {
30namespace Detail {
31namespace RDF {
32
33using namespace ROOT::TypeTraits;
34
35// clang-format off
36namespace CustomColExtraArgs {
37struct None{};
38struct Slot{};
39struct SlotAndEntry{};
40}
41// clang-format on
42
43template <typename F, typename ExtraArgsTag = CustomColExtraArgs::None>
44class RCustomColumn final : public RCustomColumnBase {
45 // shortcuts
49 // other types
50 using FunParamTypes_t = typename CallableTraits<F>::arg_types;
52 RDFInternal::RemoveFirstParameterIf_t<std::is_same<ExtraArgsTag, SlotTag>::value, FunParamTypes_t>;
54 RDFInternal::RemoveFirstTwoParametersIf_t<std::is_same<ExtraArgsTag, SlotAndEntryTag>::value, ColumnTypesTmp_t>;
56 using ret_type = typename CallableTraits<F>::ret_type;
57 // Avoid instantiating vector<bool> as `operator[]` returns temporaries in that case. Use std::deque instead.
59 typename std::conditional<std::is_same<ret_type, bool>::value, std::deque<ret_type>, std::vector<ret_type>>::type;
60
64
65 std::vector<RDFInternal::RDFValueTuple_t<ColumnTypes_t>> fValues;
66
67public:
68 RCustomColumn(RLoopManager *lm, std::string_view name, F &&expression, const ColumnNames_t &bl, unsigned int nSlots,
69 const RDFInternal::RBookedCustomColumns &customColumns, bool isDSColumn = false)
70 : RCustomColumnBase(lm, name, nSlots, isDSColumn, customColumns), fExpression(std::forward<F>(expression)),
72 {
73 }
74
75 RCustomColumn(const RCustomColumn &) = delete;
77
78 void InitSlot(TTreeReader *r, unsigned int slot) final
79 {
80 // TODO: Each node calls this method for each column it uses. Multiple nodes may share the same columns, and this
81 // would lead to this method being called multiple times.
83 }
84
85 void *GetValuePtr(unsigned int slot) final { return static_cast<void *>(&fLastResults[slot]); }
86
87 void Update(unsigned int slot, Long64_t entry) final
88 {
89 if (entry != fLastCheckedEntry[slot]) {
90 // evaluate this filter, cache the result
91 UpdateHelper(slot, entry, TypeInd_t(), ColumnTypes_t(), ExtraArgsTag{});
92 fLastCheckedEntry[slot] = entry;
93 }
94 }
95
96 const std::type_info &GetTypeId() const
97 {
98 return fIsDataSourceColumn ? typeid(typename std::remove_pointer<ret_type>::type) : typeid(ret_type);
99 }
100
101 template <std::size_t... S, typename... BranchTypes>
103 {
104 fLastResults[slot] = fExpression(std::get<S>(fValues[slot]).Get(entry)...);
105 // silence "unused parameter" warnings in gcc
106 (void)slot;
107 (void)entry;
108 }
109
110 template <std::size_t... S, typename... BranchTypes>
112 {
113 fLastResults[slot] = fExpression(slot, std::get<S>(fValues[slot]).Get(entry)...);
114 // silence "unused parameter" warnings in gcc
115 (void)slot;
116 (void)entry;
117 }
118
119 template <std::size_t... S, typename... BranchTypes>
120 void
122 {
123 fLastResults[slot] = fExpression(slot, entry, std::get<S>(fValues[slot]).Get(entry)...);
124 // silence "unused parameter" warnings in gcc
125 (void)slot;
126 (void)entry;
127 }
128
129 void ClearValueReaders(unsigned int slot) final
130 {
131 // TODO: Each node calls this method for each column it uses. Multiple nodes may share the same columns, and this
132 // would lead to this method being called multiple times.
134 }
135};
136
137} // ns RDF
138} // ns Detail
139} // ns ROOT
140
141#endif // ROOT_RCUSTOMCOLUMN
ROOT::R::TRInterface & r
Definition: Object.C:4
long long Long64_t
Definition: RtypesCore.h:69
int type
Definition: TGX11.cxx:120
typedef void((*Func_t)())
const bool fIsDataSourceColumn
does the custom column refer to a data-source column? (or a user-define column?)
std::vector< Long64_t > fLastCheckedEntry
RDFInternal::RBookedCustomColumns fCustomColumns
const unsigned int fNSlots
number of thread slots used by this node, inherited from parent node.
std::make_index_sequence< ColumnTypes_t::list_size > TypeInd_t
std::vector< RDFInternal::RDFValueTuple_t< ColumnTypes_t > > fValues
typename std::conditional< std::is_same< ret_type, bool >::value, std::deque< ret_type >, std::vector< ret_type > >::type ValuesPerSlot_t
typename CallableTraits< F >::ret_type ret_type
RCustomColumn & operator=(const RCustomColumn &)=delete
RCustomColumn(const RCustomColumn &)=delete
const std::type_info & GetTypeId() const
RCustomColumn(RLoopManager *lm, std::string_view name, F &&expression, const ColumnNames_t &bl, unsigned int nSlots, const RDFInternal::RBookedCustomColumns &customColumns, bool isDSColumn=false)
void ClearValueReaders(unsigned int slot) final
void UpdateHelper(unsigned int slot, Long64_t entry, std::index_sequence< S... >, TypeList< BranchTypes... >, SlotTag)
RDFInternal::RemoveFirstParameterIf_t< std::is_same< ExtraArgsTag, SlotTag >::value, FunParamTypes_t > ColumnTypesTmp_t
RDFInternal::RemoveFirstTwoParametersIf_t< std::is_same< ExtraArgsTag, SlotAndEntryTag >::value, ColumnTypesTmp_t > ColumnTypes_t
typename CallableTraits< F >::arg_types FunParamTypes_t
void InitSlot(TTreeReader *r, unsigned int slot) final
void * GetValuePtr(unsigned int slot) final
void UpdateHelper(unsigned int slot, Long64_t entry, std::index_sequence< S... >, TypeList< BranchTypes... >, SlotAndEntryTag)
void Update(unsigned int slot, Long64_t entry) final
void UpdateHelper(unsigned int slot, Long64_t entry, std::index_sequence< S... >, TypeList< BranchTypes... >, NoneTag)
The head node of a RDF computation graph.
Encapsulates the columns defined by the user.
A simple, robust and fast interface to read values from ROOT colmnar datasets such as TTree,...
Definition: TTreeReader.h:44
#define F(x, y, z)
void InitRDFValues(unsigned int slot, RDFValueTuple &valueTuple, TTreeReader *r, const ColumnNames_t &bn, const RBookedCustomColumns &customCols, std::index_sequence< S... >)
Initialize a tuple of RColumnValues.
Definition: NodesUtils.hxx:54
void ResetRDFValueTuple(std::vector< RTypeErasedColumnValue > &values, std::index_sequence< S... >, ROOT::TypeTraits::TypeList< ColTypes... >)
This overload is specialized to act on RTypeErasedColumnValues instead of RColumnValues.
Definition: RAction.hxx:90
ROOT type_traits extensions.
Definition: TypeTraits.hxx:23
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
ROOT::Detail::RDF::ColumnNames_t ColumnNames_t
Definition: RDataFrame.cxx:790
RooArgSet S(const RooAbsArg &v1)
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
Definition: NeuralNet.icc:544
STL namespace.
basic_string_view< char > string_view
Definition: RStringView.hxx:35
make_integer_sequence< size_t, _Np > make_index_sequence
Lightweight storage for a collection of types.
Definition: TypeTraits.hxx:27