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