PDFxTMDLib  1.0.0
IUncertainty.h
Go to the documentation of this file.
1 #pragma once
4 #include <vector>
5 
6 namespace PDFxTMD
7 {
9 {
10  public:
11  template <typename UncertaintyApproachT>
12  explicit IUncertainty(UncertaintyApproachT uncertaintyApproach)
13  : pimpl_(new OwningModel<UncertaintyApproachT>(std::move(uncertaintyApproach)),
14  [](void *uncertaintyApproachBytes) {
15  using Model = OwningModel<UncertaintyApproachT>;
16  auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
17  delete model;
18  }),
19  uncertaintyOperation_([](void *uncertaintyApproachBytes,
20  const std::vector<double> &values, const int numCoreErrMember,
21  const double cl, PDFUncertainty &uncertainty) -> void {
22  using Model = OwningModel<UncertaintyApproachT>;
23  auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
24  return model->Uncertainty(values, numCoreErrMember, cl, uncertainty);
25  }),
26  correlationOperation_(
27  [](void *uncertaintyApproachBytes, const std::vector<double> &valuesA,
28  const std::vector<double> &valuesB, const int numCoreErrMember) -> double {
29  using Model = OwningModel<UncertaintyApproachT>;
30  auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
31  return model->Correlation(valuesA, valuesB, numCoreErrMember);
32  }),
33  clone_([](void *uncertaintyApproachBytes) -> void * {
34  using Model = OwningModel<UncertaintyApproachT>;
35  auto *const model = static_cast<Model *>(uncertaintyApproachBytes);
36  return new Model(*model);
37  })
38  {
39  }
40 
41  void Uncertainty(const std::vector<double> &values, const int numCoreErrMember, const double cl,
42  PDFUncertainty &uncertainty) const
43  {
44  uncertaintyOperation_(pimpl_.get(), values, numCoreErrMember, cl, uncertainty);
45  }
46 
47  double Correlation(const std::vector<double> &valuesA, const std::vector<double> &valuesB,
48  const int numCoreErrMember) const
49  {
50  return correlationOperation_(pimpl_.get(), valuesA, valuesB, numCoreErrMember);
51  }
59  IUncertainty(const IUncertainty &other)
60  : pimpl_(other.clone_(other.pimpl_.get()), other.pimpl_.get_deleter()),
61  clone_(other.clone_), correlationOperation_(other.correlationOperation_),
62  uncertaintyOperation_(other.uncertaintyOperation_)
63  {
64  }
65 
75  {
76  using std::swap;
77  IUncertainty copy(other);
78  swap(pimpl_, copy.pimpl_);
79  swap(clone_, copy.clone_);
80  swap(correlationOperation_, copy.correlationOperation_);
81  swap(uncertaintyOperation_, copy.uncertaintyOperation_);
82  return *this;
83  }
84 
85  IUncertainty(IUncertainty &&other) noexcept = default;
86  ~IUncertainty() = default;
87  IUncertainty &operator=(IUncertainty &&other) = default;
88 
89  private:
90  template <typename UncertaintyApproachT> struct OwningModel
91  {
92  OwningModel(UncertaintyApproachT uncertaintyApporach)
93  : uncertaintyApporach_(std::move(uncertaintyApporach))
94  {
95  }
96 
97  double Correlation(const std::vector<double> &valuesA, const std::vector<double> &valuesB,
98  const int numCoreErrMember)
99  {
100  return uncertaintyApporach_.Correlation(valuesA, valuesB, numCoreErrMember);
101  }
102  void Uncertainty(const std::vector<double> &values, const int numCoreErrMember,
103  const double cl, PDFUncertainty &uncertainty)
104  {
105  return uncertaintyApporach_.Uncertainty(values, numCoreErrMember, cl, uncertainty);
106  }
107  UncertaintyApproachT uncertaintyApporach_;
108  };
109 
110  using DestroyOperation = void(void *);
111  using CloneOperation = void *(void *);
112  using UncertaintyOperation = void(void *, const std::vector<double> &, const int, const double,
113  PDFUncertainty &);
114  using CorrelationOperation = double(void *, const std::vector<double> &,
115  const std::vector<double> &, const int);
116 
117  std::unique_ptr<void, DestroyOperation *> pimpl_;
118  CloneOperation *clone_{nullptr};
119  UncertaintyOperation *uncertaintyOperation_{nullptr};
120  CorrelationOperation *correlationOperation_{nullptr};
121 };
122 } // namespace PDFxTMD
Definition: IUncertainty.h:9
void Uncertainty(const std::vector< double > &values, const int numCoreErrMember, const double cl, PDFUncertainty &uncertainty) const
Definition: IUncertainty.h:41
IUncertainty & operator=(IUncertainty &&other)=default
IUncertainty(IUncertainty &&other) noexcept=default
IUncertainty & operator=(IUncertainty const &other)
Assignment operator for ICPDF objects.
Definition: IUncertainty.h:74
IUncertainty(UncertaintyApproachT uncertaintyApproach)
Definition: IUncertainty.h:12
double Correlation(const std::vector< double > &valuesA, const std::vector< double > &valuesB, const int numCoreErrMember) const
Definition: IUncertainty.h:47
IUncertainty(const IUncertainty &other)
Copy constructor for ICPDF objects.
Definition: IUncertainty.h:59
Definition: AllFlavorsShape.h:14
Structure for storage of uncertainty info calculated over a PDF error set.
Definition: Uncertainty.h:10