File indexing completed on 2025-01-18 10:10:27
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef RooFit_Detail_EvalContext_h
0014 #define RooFit_Detail_EvalContext_h
0015
0016 #include <RooAbsArg.h>
0017
0018 #include <ROOT/RSpan.hxx>
0019
0020 #include <TNamed.h>
0021 #include <TObject.h>
0022
0023 #include <Math/Util.h>
0024
0025 #include <map>
0026 #include <stdexcept>
0027 #include <sstream>
0028
0029 template <class T>
0030 class RooTemplateProxy;
0031
0032 namespace RooBatchCompute {
0033 class Config;
0034 }
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045 namespace RooFit {
0046 namespace Detail {
0047
0048 class DataKey {
0049 public:
0050 inline DataKey(RooAbsArg const *arg) : _ptr{arg->namePtr()} {}
0051 inline DataKey(TNamed const *arg) : _ptr{arg} {}
0052 template <class T>
0053 inline DataKey(RooTemplateProxy<T> const &proxy) : DataKey{&*proxy}
0054 {
0055 }
0056
0057
0058 friend inline bool operator==(const DataKey &k1, const DataKey &k2) { return k1._ptr == k2._ptr; }
0059 friend inline bool operator!=(const DataKey &k1, const DataKey &k2) { return k1._ptr != k2._ptr; }
0060 friend inline bool operator<(const DataKey &k1, const DataKey &k2) { return k1._ptr < k2._ptr; }
0061
0062
0063 inline TObject const &operator*() const { return *_ptr; }
0064 inline TObject const *operator->() const { return _ptr; }
0065
0066 private:
0067 TObject const *_ptr;
0068 };
0069
0070 }
0071 }
0072
0073 namespace std {
0074
0075 template <>
0076 struct hash<RooFit::Detail::DataKey> {
0077 std::size_t operator()(const RooFit::Detail::DataKey &k) const { return hash<TObject const *>{}(&*k); }
0078 };
0079
0080 }
0081
0082 namespace RooFit {
0083
0084 class EvalContext {
0085 public:
0086 enum class OffsetMode { WithoutOffset, WithOffset, OnlyOffset };
0087
0088 auto size() const { return _ctx.size(); }
0089 void resize(std::size_t n);
0090
0091 inline void set(RooAbsArg const *arg, std::span<const double> const &span)
0092 {
0093 if (!arg->hasDataToken())
0094 return;
0095 std::size_t idx = arg->dataToken();
0096 _ctx[idx] = span;
0097 }
0098
0099 void setConfig(RooAbsArg const *arg, RooBatchCompute::Config const &config);
0100
0101 std::span<const double> at(RooAbsArg const *arg, RooAbsArg const *caller = nullptr);
0102
0103 template <class T>
0104 inline std::span<const double> at(RooTemplateProxy<T> const &proxy)
0105 {
0106 return at(&proxy.arg(), proxy.owner());
0107 }
0108
0109 RooBatchCompute::Config config(RooAbsArg const *arg) const;
0110 void enableVectorBuffers(bool enable) { _enableVectorBuffers = enable; }
0111 void resetVectorBuffers() { _bufferIdx = 0; }
0112 std::span<double> output() { return _currentOutput; }
0113
0114 void setOutputWithOffset(RooAbsArg const *arg, ROOT::Math::KahanSum<double> val,
0115 ROOT::Math::KahanSum<double> const &offset);
0116
0117 private:
0118 friend class Evaluator;
0119
0120 OffsetMode _offsetMode = OffsetMode::WithoutOffset;
0121 std::span<double> _currentOutput;
0122 std::vector<std::span<const double>> _ctx;
0123 bool _enableVectorBuffers = false;
0124 std::vector<std::vector<double>> _buffers;
0125 std::size_t _bufferIdx = 0;
0126 std::vector<RooBatchCompute::Config> _cfgs;
0127 };
0128
0129 }
0130
0131 #endif