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 public:
19  // Dummy constructor, to be used for deserialization only
20  inline HcalLinearCompositionFunctor() : a_(0.0), b_(0.0) {}
21 
22  // Normal constructor
23  HcalLinearCompositionFunctor(std::shared_ptr<AbsHcalFunctor> p, double a, double b);
24 
25  inline ~HcalLinearCompositionFunctor() override {}
26 
27  double operator()(double x) const override;
28 
29  inline double xmin() const override { return other_->xmin(); }
30  inline double xmax() const override { return other_->xmax(); }
31 
32  inline double a() const { return a_; }
33  inline double b() const { return b_; }
34 
35 protected:
36  inline bool isEqual(const AbsHcalFunctor& other) const override {
38  return *other_ == *r.other_ && a_ == r.a_ && b_ == r.b_;
39  }
40 
41 private:
42  std::shared_ptr<AbsHcalFunctor> other_;
43  double a_;
44  double b_;
45 
47 
48  template <class Archive>
49  inline void serialize(Archive& ar, unsigned /* version */) {
50  boost::serialization::base_object<AbsHcalFunctor>(*this);
51  // Direct polymorphic serialization of shared_ptr is broken
52  // in boost for versions 1.56, 1.57, 1.58. For detail, see
53  // https://svn.boost.org/trac/boost/ticket/10727
54 #if BOOST_VERSION < 105600 || BOOST_VERSION > 105800
55  ar& other_& a_& b_;
56 #else
57  throw cms::Exception(
58  "HcalLinearCompositionFunctor can not be"
59  " serialized with this version of boost");
60 #endif
61  }
62 };
63 
64 BOOST_CLASS_VERSION(HcalLinearCompositionFunctor, 1)
65 BOOST_CLASS_EXPORT_KEY(HcalLinearCompositionFunctor)
66 
67 #endif // CondFormats_HcalObjects_HcalLinearCompositionFunctor_h
std::shared_ptr< AbsHcalFunctor > other_
friend class boost::serialization::access
void serialize(Archive &ar, unsigned)
bool isEqual(const AbsHcalFunctor &other) const override
double operator()(double x) const override