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