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, RDFInternal::RColumnRegister{&lm}, lm, /*columnNames*/ {}),
43 fExpression(std::move(expression)),
44 fLastResults(lm.GetNSlots() * RDFInternal::CacheLineStep<RetType_t>())
45 {
46 fLoopManager->Register(this);
47 auto callUpdate = [this](unsigned int slot, const ROOT::RDF::RSampleInfo &id) { this->Update(slot, id); };
48 fLoopManager->AddSampleCallback(this, std::move(callUpdate));
49 }
50
53
54 ~RDefinePerSample() { fLoopManager->Deregister(this); }
55
56 /// Return the (type-erased) address of the Define'd value for the given processing slot.
57 void *GetValuePtr(unsigned int slot) final
58 {
59 return static_cast<void *>(&fLastResults[slot * RDFInternal::CacheLineStep<RetType_t>()]);
60 }
61
62 void Update(unsigned int, Long64_t) final
63 {
64 // no-op
65 }
66
67 /// Update the value at the address returned by GetValuePtr with the content corresponding to the given entry
68 void Update(unsigned int slot, const ROOT::RDF::RSampleInfo &id) final
69 {
70 fLastResults[slot * RDFInternal::CacheLineStep<RetType_t>()] = fExpression(slot, id);
71 }
72
73 const std::type_info &GetTypeId() const final { return typeid(RetType_t); }
74
75 void InitSlot(TTreeReader *, unsigned int) final {}
76
77 void FinalizeSlot(unsigned int) final {}
78
79 // No-op for RDefinePerSample: it never depends on systematic variations
80 void MakeVariations(const std::vector<std::string> &) final {}
81
82 RDefineBase &GetVariedDefine(const std::string &) final
83 {
84 R__ASSERT(false && "This should never be called");
85 return *this;
86 }
87};
88
89} // namespace RDF
90} // namespace Detail
91} // namespace ROOT
92
93#endif // ROOT_RDF_RDEFINEPERSAMPLE
long long Long64_t
Definition RtypesCore.h:69
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:110
void FinalizeSlot(unsigned int) final
Clean-up operations to be performed at the end of a task.
RDefinePerSample & operator=(const RDefinePerSample &)=delete
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".
const std::type_info & GetTypeId() const final
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 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:46
#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.