Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
EvalContext.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 12/2021
5 *
6 * Copyright (c) 2023, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#ifndef RooFit_Detail_EvalContext_h
14#define RooFit_Detail_EvalContext_h
15
16#include <RooAbsArg.h>
17
18#include <ROOT/RSpan.hxx>
19
20#include <TNamed.h>
21#include <TObject.h>
22
23#include <Math/Util.h>
24
25#include <map>
26#include <stdexcept>
27#include <sstream>
28
29template <class T>
31
32namespace RooBatchCompute {
33class Config;
34}
35
36/// \class RooFit::DataKey
37/// To use as a key type for RooFit data maps and containers. A RooFit::DataKey
38/// can be constructed with no runtime overhead from a RooAbsArg (or any
39/// templated RooFit proxy for convenience). Compared to using the RooAbsArg
40/// pointer directly, this has the advantage that one can easily change the way
41/// the key is constructed from the object, just by changing the implementation
42/// of the DataKey. For example, it is trivial to move from using the RooAbsArg
43/// pointer to using the unique name pointer retrieved by RooAbsArg::namePtr().
44
45namespace RooFit {
46namespace Detail {
47
48class DataKey {
49public:
50 inline DataKey(RooAbsArg const *arg) : _ptr{arg->namePtr()} {}
51 inline DataKey(TNamed const *arg) : _ptr{arg} {}
52 template <class T>
53 inline DataKey(RooTemplateProxy<T> const &proxy) : DataKey{&*proxy}
54 {
55 }
56
57 // Comparison operators that wrap the pointer comparisons.
58 friend inline bool operator==(const DataKey &k1, const DataKey &k2) { return k1._ptr == k2._ptr; }
59 friend inline bool operator!=(const DataKey &k1, const DataKey &k2) { return k1._ptr != k2._ptr; }
60 friend inline bool operator<(const DataKey &k1, const DataKey &k2) { return k1._ptr < k2._ptr; }
61
62 // Implementing pointer-style operators.
63 inline TObject const &operator*() const { return *_ptr; }
64 inline TObject const *operator->() const { return _ptr; }
65
66private:
67 TObject const *_ptr;
68};
69
70} // namespace Detail
71} // namespace RooFit
72
73namespace std {
74
75template <>
76struct hash<RooFit::Detail::DataKey> {
77 std::size_t operator()(const RooFit::Detail::DataKey &k) const { return hash<TObject const *>{}(&*k); }
78};
79
80} // namespace std
81
82namespace RooFit {
83
85public:
87
88 auto size() const { return _ctx.size(); }
89 void resize(std::size_t n);
90
91 inline void set(RooAbsArg const *arg, std::span<const double> const &span)
92 {
93 if (!arg->hasDataToken())
94 return;
95 std::size_t idx = arg->dataToken();
96 _ctx[idx] = span;
97 }
98
99 void setConfig(RooAbsArg const *arg, RooBatchCompute::Config const &config);
100
101 std::span<const double> at(RooAbsArg const *arg, RooAbsArg const *caller = nullptr);
102
103 template <class T>
104 inline std::span<const double> at(RooTemplateProxy<T> const &proxy)
105 {
106 return at(&proxy.arg(), proxy.owner());
107 }
108
109 RooBatchCompute::Config config(RooAbsArg const *arg) const;
110 void enableVectorBuffers(bool enable) { _enableVectorBuffers = enable; }
112 std::span<double> output() { return _currentOutput; }
113
116
117private:
118 friend class Evaluator;
119
121 std::span<double> _currentOutput;
122 std::vector<std::span<const double>> _ctx;
124 std::vector<std::vector<double>> _buffers;
125 std::size_t _bufferIdx = 0;
126 std::vector<RooBatchCompute::Config> _cfgs;
127};
128
129} // namespace RooFit
130
131#endif
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 offset
TRObject operator()(const T1 &t1) const
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
Definition Util.h:122
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:77
bool hasDataToken() const
Definition RooAbsArg.h:648
std::size_t dataToken() const
Returns the token for retrieving results in the BatchMode. For internal use only.
Definition RooAbsArg.h:647
RooAbsArg * owner() const
Returns the owner of this proxy.
Definition RooArgProxy.h:57
Minimal configuration struct to steer the evaluation of a single node with the RooBatchCompute librar...
DataKey(RooTemplateProxy< T > const &proxy)
Definition EvalContext.h:53
friend bool operator!=(const DataKey &k1, const DataKey &k2)
Definition EvalContext.h:59
DataKey(RooAbsArg const *arg)
Definition EvalContext.h:50
DataKey(TNamed const *arg)
Definition EvalContext.h:51
TObject const * _ptr
Definition EvalContext.h:67
TObject const * operator->() const
Definition EvalContext.h:64
friend bool operator<(const DataKey &k1, const DataKey &k2)
Definition EvalContext.h:60
friend bool operator==(const DataKey &k1, const DataKey &k2)
Definition EvalContext.h:58
TObject const & operator*() const
Definition EvalContext.h:63
auto size() const
Definition EvalContext.h:88
std::vector< RooBatchCompute::Config > _cfgs
void set(RooAbsArg const *arg, std::span< const double > const &span)
Definition EvalContext.h:91
std::span< const double > at(RooAbsArg const *arg, RooAbsArg const *caller=nullptr)
std::span< double > output()
void enableVectorBuffers(bool enable)
std::size_t _bufferIdx
OffsetMode _offsetMode
std::span< const double > at(RooTemplateProxy< T > const &proxy)
RooBatchCompute::Config config(RooAbsArg const *arg) const
void setConfig(RooAbsArg const *arg, RooBatchCompute::Config const &config)
std::vector< std::span< const double > > _ctx
void setOutputWithOffset(RooAbsArg const *arg, ROOT::Math::KahanSum< double > val, ROOT::Math::KahanSum< double > const &offset)
Sets the output value with an offset.
std::vector< std::vector< double > > _buffers
std::span< double > _currentOutput
void resize(std::size_t n)
Evaluates a RooAbsReal object in other ways than recursive graph traversal.
Definition Evaluator.h:36
const T & arg() const
Return reference to object held in proxy.
The TNamed class is the base class for all named ROOT classes.
Definition TNamed.h:29
Mother of all ROOT objects.
Definition TObject.h:41
const Int_t n
Definition legend1.C:16
Namespace for dispatching RooFit computations to various backends.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition JSONIO.h:26