CMS 3D CMS Logo

HcalLinearCompositionFunctor.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalLinearCompositionFunctor_h
2 #define CondFormats_HcalObjects_HcalLinearCompositionFunctor_h
3 
5 
7 
8 #include "boost/serialization/access.hpp"
9 #include "boost/serialization/version.hpp"
10 #include "boost/serialization/shared_ptr.hpp"
11 
12 //
13 // A functor returning a linearly transformed value
14 // of another functor: f(x) = a*p(x) + b. Useful for
15 // implementing cuts symmetric about 0, etc.
16 //
18 {
19 public:
20  // Dummy constructor, to be used for deserialization only
21  inline HcalLinearCompositionFunctor() : a_(0.0), b_(0.0) {}
22 
23  // Normal constructor
24  HcalLinearCompositionFunctor(boost::shared_ptr<AbsHcalFunctor> p,
25  double a, double b);
26 
27  inline ~HcalLinearCompositionFunctor() override {}
28 
29  double operator()(double x) const override;
30 
31  inline double xmin() const override {return other_->xmin();}
32  inline double xmax() const override {return other_->xmax();}
33 
34  inline double a() const {return a_;}
35  inline double b() const {return b_;}
36 
37 protected:
38  inline bool isEqual(const AbsHcalFunctor& other) const override
39  {
41  static_cast<const HcalLinearCompositionFunctor&>(other);
42  return *other_ == *r.other_ && a_ == r.a_ && b_ == r.b_;
43  }
44 
45 private:
46  boost::shared_ptr<AbsHcalFunctor> other_;
47  double a_;
48  double b_;
49 
51 
52  template<class Archive>
53  inline void serialize(Archive & ar, unsigned /* version */)
54  {
55  boost::serialization::base_object<AbsHcalFunctor>(*this);
56  // Direct polymorphic serialization of shared_ptr is broken
57  // in boost for versions 1.56, 1.57, 1.58. For detail, see
58  // https://svn.boost.org/trac/boost/ticket/10727
59 #if BOOST_VERSION < 105600 || BOOST_VERSION > 105800
60  ar & other_ & a_ & b_;
61 #else
62  throw cms::Exception("HcalLinearCompositionFunctor can not be"
63  " serialized with this version of boost");
64 #endif
65  }
66 };
67 
68 BOOST_CLASS_VERSION(HcalLinearCompositionFunctor, 1)
69 BOOST_CLASS_EXPORT_KEY(HcalLinearCompositionFunctor)
70 
71 #endif // CondFormats_HcalObjects_HcalLinearCompositionFunctor_h
double operator()(double x) const override
boost::shared_ptr< AbsHcalFunctor > other_
friend class boost::serialization::access
void serialize(Archive &ar, unsigned)
bool isEqual(const AbsHcalFunctor &other) const override