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{nullptr}, lm, /*columnNames*/ {}),
43 fExpression(std::move(expression)), fLastResults(lm.GetNSlots() * RDFInternal::CacheLineStep<RetType_t>())
44 {
45 fLoopManager->Register(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 final { return typeid(RetType_t); }
73
74 void InitSlot(TTreeReader *, unsigned int) final {}
75
76 void FinalizeSlot(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
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:44
#define F(x, y, z)
ROOT type_traits extensions.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Extract types from the signature of a callable object. See CallableTraits.