CMS 3D CMS Logo

PiecewiseScalingPolynomial.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_PiecewiseScalingPolynomial_h_
2 #define CondFormats_HcalObjects_PiecewiseScalingPolynomial_h_
3 
5 
6 #include "boost/serialization/vector.hpp"
7 #include "boost/serialization/version.hpp"
8 
9 #include <vector>
10 
12 public:
14 
15  PiecewiseScalingPolynomial(const std::vector<std::vector<double> >& coeffs, const std::vector<double>& limits);
16 
17  inline double operator()(const double x) const {
18  double scale(0.0);
19  if (x > 0.0) {
20  const unsigned nLimits(limits_.size());
21  if (nLimits) {
22  const double* limits(&limits_[0]);
23  unsigned which(0U);
24  for (; which < nLimits; ++which)
25  if (x < limits[which])
26  break;
27  const std::vector<double>& c(coeffs_[which]);
28  const double* a = &c[0];
29  for (int deg = c.size() - 1; deg >= 0; --deg) {
30  scale *= x;
31  scale += a[deg];
32  }
33  }
34  }
35  return scale * x;
36  }
37 
38  inline bool operator==(const PiecewiseScalingPolynomial& r) const {
39  return coeffs_ == r.coeffs_ && limits_ == r.limits_;
40  }
41 
42  inline bool operator!=(const PiecewiseScalingPolynomial& r) const { return !(*this == r); }
43 
44 private:
45  bool validate() const;
46 
47  std::vector<std::vector<double> > coeffs_;
48  std::vector<double> limits_;
49 
51 
52  template <class Archive>
53  inline void save(Archive& ar, const unsigned /* version */) const {
54  if (!validate())
55  throw cms::Exception("In PiecewiseScalingPolynomial::save: invalid data");
56  ar& coeffs_& limits_;
57  }
58 
59  template <class Archive>
60  inline void load(Archive& ar, const unsigned /* version */) {
61  ar& coeffs_& limits_;
62  if (!validate())
63  throw cms::Exception("In PiecewiseScalingPolynomial::load: invalid data");
64  }
65 
66  BOOST_SERIALIZATION_SPLIT_MEMBER()
67 };
68 
69 BOOST_CLASS_VERSION(PiecewiseScalingPolynomial, 1)
70 
71 #endif // CondFormats_HcalObjects_PiecewiseScalingPolynomial_h_
void load(Archive &ar, const unsigned)
void save(Archive &ar, const unsigned) const
bool operator!=(const PiecewiseScalingPolynomial &r) const
bool operator==(const PiecewiseScalingPolynomial &r) const
std::vector< std::vector< double > > coeffs_
double a
Definition: hdecay.h:121
def which(cmd)
Definition: eostools.py:336
friend class boost::serialization::access
double operator()(const double x) const