PDFxTMDLib 2.0.0
Loading...
Searching...
No Matches
IUncertainty.h
Go to the documentation of this file.
1#pragma once
2#include <PDFxTMDLib/Common/Uncertainty.h>
3#include <PDFxTMDLib/Common/YamlMetaInfo/YamlErrorInfo.h>
4#include <vector>
5
6namespace PDFxTMD
7{
10{
11 public:
12 template <typename UncertaintyApproachT>
13 explicit IUncertainty(UncertaintyApproachT uncertaintyApproach)
14 : pimpl_(new OwningModel<UncertaintyApproachT>(std::move(uncertaintyApproach)),
15 [](void *uncertaintyApproachBytes) {
16 using Model = OwningModel<UncertaintyApproachT>;
17 auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
18 delete model;
19 }),
20 uncertaintyOperation_([](void *uncertaintyApproachBytes,
21 const std::vector<double> &values, const int numCoreErrMember,
22 const double cl, PDFUncertainty &uncertainty) -> void {
23 using Model = OwningModel<UncertaintyApproachT>;
24 auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
25 return model->Uncertainty(values, numCoreErrMember, cl, uncertainty);
26 }),
27 correlationOperation_(
28 [](void *uncertaintyApproachBytes, const std::vector<double> &valuesA,
29 const std::vector<double> &valuesB, const int numCoreErrMember) -> double {
30 using Model = OwningModel<UncertaintyApproachT>;
31 auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
32 return model->Correlation(valuesA, valuesB, numCoreErrMember);
33 }),
34 clone_([](void *uncertaintyApproachBytes) -> void * {
35 using Model = OwningModel<UncertaintyApproachT>;
36 auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
37 return new Model(*model);
38 })
39 {
40 }
41
43 void Uncertainty(const std::vector<double> &values, const int numCoreErrMember, const double cl,
44 PDFUncertainty &uncertainty) const
45 {
46 uncertaintyOperation_(pimpl_.get(), values, numCoreErrMember, cl, uncertainty);
47 }
48
50 double Correlation(const std::vector<double> &valuesA, const std::vector<double> &valuesB,
51 const int numCoreErrMember) const
52 {
53 return correlationOperation_(pimpl_.get(), valuesA, valuesB, numCoreErrMember);
54 }
63 : pimpl_(other.clone_(other.pimpl_.get()), other.pimpl_.get_deleter()),
64 clone_(other.clone_), correlationOperation_(other.correlationOperation_),
65 uncertaintyOperation_(other.uncertaintyOperation_)
66 {
67 }
68
78 {
79 using std::swap;
80 IUncertainty copy(other);
81 swap(pimpl_, copy.pimpl_);
82 swap(clone_, copy.clone_);
83 swap(correlationOperation_, copy.correlationOperation_);
84 swap(uncertaintyOperation_, copy.uncertaintyOperation_);
85 return *this;
86 }
87
88 IUncertainty(IUncertainty &&other) noexcept = default;
89 ~IUncertainty() = default;
90 IUncertainty &operator=(IUncertainty &&other) = default;
91
92 private:
93 template <typename UncertaintyApproachT> struct OwningModel
94 {
95 OwningModel(UncertaintyApproachT uncertaintyApporach)
96 : uncertaintyApporach_(std::move(uncertaintyApporach))
97 {
98 }
99
100 double Correlation(const std::vector<double> &valuesA, const std::vector<double> &valuesB,
101 const int numCoreErrMember)
102 {
103 return uncertaintyApporach_.Correlation(valuesA, valuesB, numCoreErrMember);
104 }
105 void Uncertainty(const std::vector<double> &values, const int numCoreErrMember,
106 const double cl, PDFUncertainty &uncertainty)
107 {
108 return uncertaintyApporach_.Uncertainty(values, numCoreErrMember, cl, uncertainty);
109 }
110 UncertaintyApproachT uncertaintyApporach_;
111 };
112
113 using DestroyOperation = void(void *);
114 using CloneOperation = void *(void *);
115 using UncertaintyOperation = void(void *, const std::vector<double> &, const int, const double,
116 PDFUncertainty &);
117 using CorrelationOperation = double(void *, const std::vector<double> &,
118 const std::vector<double> &, const int);
119
120 std::unique_ptr<void, DestroyOperation *> pimpl_;
121 CloneOperation *clone_{nullptr};
122 UncertaintyOperation *uncertaintyOperation_{nullptr};
123 CorrelationOperation *correlationOperation_{nullptr};
124};
125} // namespace PDFxTMD
Type-erased interface for PDF uncertainty calculations.
Definition IUncertainty.h:10
void Uncertainty(const std::vector< double > &values, const int numCoreErrMember, const double cl, PDFUncertainty &uncertainty) const
Calculate uncertainty from values evaluated for all set members.
Definition IUncertainty.h:43
IUncertainty & operator=(IUncertainty const &other)
Assignment operator for ICPDF objects.
Definition IUncertainty.h:77
IUncertainty(IUncertainty &&other) noexcept=default
IUncertainty(UncertaintyApproachT uncertaintyApproach)
Definition IUncertainty.h:13
IUncertainty & operator=(IUncertainty &&other)=default
double Correlation(const std::vector< double > &valuesA, const std::vector< double > &valuesB, const int numCoreErrMember) const
Calculate the correlation between two member-value series.
Definition IUncertainty.h:50
IUncertainty(const IUncertainty &other)
Copy constructor for ICPDF objects.
Definition IUncertainty.h:62
Definition Factory.h:9