Logo ROOT  
Reference Guide
RDefinePerSample.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, CERN 08/2021
2
3/*************************************************************************
4 * Copyright (C) 1995-2021, 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_RDF_RDEFINEPERSAMPLE
12#define ROOT_RDF_RDEFINEPERSAMPLE
13
15#include "ROOT/RDF/Utils.hxx"
17#include <ROOT/TypeTraits.hxx>
18
19#include <deque>
20#include <vector>
21
22namespace ROOT {
23namespace Detail {
24namespace RDF {
25
26using namespace ROOT::TypeTraits;
27
28template <typename F>
29class R__CLING_PTRCHECK(off) RDefinePerSample final : public RDefineBase {
30 using RetType_t = typename CallableTraits<F>::ret_type;
31
32 // Avoid instantiating vector<bool> as `operator[]` returns temporaries in that case. Use std::deque instead.
34 std::conditional_t<std::is_same<RetType_t, bool>::value, std::deque<RetType_t>, std::vector<RetType_t>>;
35
38
39public:
40 RDefinePerSample(std::string_view name, std::string_view type, F expression, unsigned int nSlots)
41 : RDefineBase(name, type, nSlots, /*defines*/ {}, /*DSValuePtrs*/ {}, /*ds*/ nullptr, /*columnNames*/ {}),
42 fExpression(std::move(expression)), fLastResults(nSlots * RDFInternal::CacheLineStep<RetType_t>())
43 {
44 }
45
48
49 /// Return the (type-erased) address of the Define'd value for the given processing slot.
50 void *GetValuePtr(unsigned int slot) final
51 {
52 return static_cast<void *>(&fLastResults[slot * RDFInternal::CacheLineStep<RetType_t>()]);
53 }
54
55 void Update(unsigned int, Long64_t) final
56 {
57 // no-op
58 }
59
60 /// Update the value at the address returned by GetValuePtr with the content corresponding to the given entry
61 void Update(unsigned int slot, const ROOT::RDF::RSampleInfo &id) final
62 {
63 fLastResults[slot * RDFInternal::CacheLineStep<RetType_t>()] = fExpression(slot, id);
64 }
65
66 const std::type_info &GetTypeId() const { return typeid(RetType_t); }
67
68 void InitSlot(TTreeReader *, unsigned int) final {}
69 void FinaliseSlot(unsigned int) final {}
70};
71
72} // namespace RDF
73} // namespace Detail
74} // namespace ROOT
75
76#endif // ROOT_RDF_RDEFINEPERSAMPLE
long long Long64_t
Definition: RtypesCore.h:80
char name[80]
Definition: TGX11.cxx:110
int type
Definition: TGX11.cxx:121
RDefinePerSample & operator=(const RDefinePerSample &)=delete
const std::type_info & GetTypeId() const
RDefinePerSample(const RDefinePerSample &)=delete
void InitSlot(TTreeReader *, unsigned int) final
void Update(unsigned int slot, const ROOT::RDF::RSampleInfo &id) final
Update the value at the address returned by GetValuePtr with the content corresponding to the given e...
RDefinePerSample(std::string_view name, std::string_view type, F expression, unsigned int nSlots)
void * GetValuePtr(unsigned int slot) final
Return the (type-erased) address of the Define'd value for the given processing slot.
typename CallableTraits< F >::ret_type RetType_t
void FinaliseSlot(unsigned int) final
Clean-up operations to be performed at the end of a task.
void Update(unsigned int, Long64_t) final
Update the value at the address returned by GetValuePtr with the content corresponding to the given e...
std::conditional_t< std::is_same< RetType_t, bool >::value, std::deque< RetType_t >, std::vector< RetType_t > > ValuesPerSlot_t
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
Definition: RSampleInfo.hxx:32
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition: TTreeReader.h:44
basic_string_view< char > string_view
#define F(x, y, z)
ROOT type_traits extensions.
Definition: TypeTraits.hxx:21
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...