Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
16#include "ROOT/RDF/Utils.hxx"
18#include <ROOT/TypeTraits.hxx>
19
20#include <deque>
21#include <vector>
22
23namespace ROOT {
24namespace Detail {
25namespace RDF {
26
27using namespace ROOT::TypeTraits;
28
29template <typename F>
30class R__CLING_PTRCHECK(off) RDefinePerSample final : public RDefineBase {
32
33 // Avoid instantiating vector<bool> as `operator[]` returns temporaries in that case. Use std::deque instead.
35 std::conditional_t<std::is_same<RetType_t, bool>::value, std::deque<RetType_t>, std::vector<RetType_t>>;
36
39
40public:
41 RDefinePerSample(std::string_view name, std::string_view type, F expression, RLoopManager &lm)
42 : RDefineBase(name, type, /*colRegister*/ {nullptr}, lm, /*columnNames*/ {}), fExpression(std::move(expression)),
43 fLastResults(lm.GetNSlots() * RDFInternal::CacheLineStep<RetType_t>())
44 {
45 fLoopManager->Book(this);
46 auto callUpdate = [this](unsigned int slot, const ROOT::RDF::RSampleInfo &id) { this->Update(slot, id); };
47 fLoopManager->AddSampleCallback(this, std::move(callUpdate));
48 }
49
52
53 ~RDefinePerSample() { fLoopManager->Deregister(this); }
54
55 /// Return the (type-erased) address of the Define'd value for the given processing slot.
56 void *GetValuePtr(unsigned int slot) final
57 {
58 return static_cast<void *>(&fLastResults[slot * RDFInternal::CacheLineStep<RetType_t>()]);
59 }
60
61 void Update(unsigned int, Long64_t) final
62 {
63 // no-op
64 }
65
66 /// Update the value at the address returned by GetValuePtr with the content corresponding to the given entry
67 void Update(unsigned int slot, const ROOT::RDF::RSampleInfo &id) final
68 {
69 fLastResults[slot * RDFInternal::CacheLineStep<RetType_t>()] = fExpression(slot, id);
70 }
71
72 const std::type_info &GetTypeId() const { return typeid(RetType_t); }
73
74 void InitSlot(TTreeReader *, unsigned int) final {}
75
76 void FinaliseSlot(unsigned int) final {}
77
78 // No-op for RDefinePerSample: it never depends on systematic variations
79 void MakeVariations(const std::vector<std::string> &) final {}
80
81 RDefineBase &GetVariedDefine(const std::string &) final
82 {
83 R__ASSERT(false && "This should never be called");
84 return *this;
85 }
86};
87
88} // namespace RDF
89} // namespace Detail
90} // namespace ROOT
91
92#endif // ROOT_RDF_RDEFINEPERSAMPLE
long long Long64_t
Definition RtypesCore.h:80
#define R__ASSERT(e)
Definition TError.h:118
XFontStruct * id
Definition TGX11.cxx:109
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...
RDefineBase & GetVariedDefine(const std::string &) final
Return a clone of this Define that works with values in the variationName "universe".
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
RDefinePerSample(std::string_view name, std::string_view type, F expression, RLoopManager &lm)
void MakeVariations(const std::vector< std::string > &) final
Create clones of this Define that work with values in varied "universes".
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
The head node of a RDF computation graph.
This type represents a sample identifier, to be used in conjunction with RDataFrame features such as ...
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
Definition TTreeReader.h:44
#define F(x, y, z)
ROOT type_traits extensions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Extract types from the signature of a callable object. See CallableTraits.