CMS 3D CMS Logo

AbsHcalFunctor.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_AbsHcalFunctor_h
2 #define CondFormats_HcalObjects_AbsHcalFunctor_h
3 
4 #include <cfloat>
5 #include <typeinfo>
6 
7 #include "boost/serialization/access.hpp"
8 #include "boost/serialization/base_object.hpp"
9 #include "boost/serialization/export.hpp"
10 
11 // Archive headers are needed here for the serialization registration to work.
12 // <cassert> is needed for the archive headers to work.
13 #if !defined(__GCCXML__)
14 #include <cassert>
15 #include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"
16 #include "CondFormats/Serialization/interface/eos/portable_oarchive.hpp"
17 #endif /* #if !defined(__GCCXML__) */
18 
20 {
21 public:
22  inline virtual ~AbsHcalFunctor() {}
23 
24  // Method to override by concrete storable functor classes
25  virtual double operator()(double x) const = 0;
26 
27  // Functor domain. Should be overriden by derived classes if needed.
28  inline virtual double xmin() const {return -DBL_MAX;}
29  inline virtual double xmax() const {return DBL_MAX;}
30 
31  // Comparison operators. Note that they are not virtual and should
32  // not be overriden by derived classes. These operators are very
33  // useful for I/O testing.
34  inline bool operator==(const AbsHcalFunctor& r) const
35  {return (typeid(*this) == typeid(r)) && this->isEqual(r);}
36  inline bool operator!=(const AbsHcalFunctor& r) const
37  {return !(*this == r);}
38 
39 protected:
40  // Method needed to compare objects for equality.
41  // Must be implemented by derived classes.
42  virtual bool isEqual(const AbsHcalFunctor&) const = 0;
43 
44  // Check if the sequence of values is strictly increasing
45  template<class Iter>
46  static bool isStrictlyIncreasing(Iter begin, Iter const end)
47  {
48  if (begin == end)
49  return false;
50  Iter first(begin);
51  bool status = ++begin != end;
52  for (; begin != end && status; ++begin, ++first)
53  if (!(*first < *begin))
54  status = false;
55  return status;
56  }
57 
58  // Check if the sequence of values is strictly decreasing
59  template<class Iter>
60  static bool isStrictlyDecreasing(Iter begin, Iter const end)
61  {
62  if (begin == end)
63  return false;
64  Iter first(begin);
65  bool status = ++begin != end;
66  for (; begin != end && status; ++begin, ++first)
67  if (!(*begin < *first))
68  status = false;
69  return status;
70  }
71 
72 private:
74  template <typename Ar>
75  inline void serialize(Ar& ar, unsigned /* version */) {}
76 };
77 
78 BOOST_CLASS_EXPORT_KEY(AbsHcalFunctor)
79 
80 #endif // CondFormats_HcalObjects_AbsHcalFunctor_h
static bool isStrictlyIncreasing(Iter begin, Iter const end)
virtual ~AbsHcalFunctor()
virtual double xmax() const
bool operator!=(const AbsHcalFunctor &r) const
static bool isStrictlyDecreasing(Iter begin, Iter const end)
virtual double operator()(double x) const =0
friend class boost::serialization::access
void serialize(Ar &ar, unsigned)
#define end
Definition: vmac.h:39
virtual bool isEqual(const AbsHcalFunctor &) const =0
virtual double xmin() const
#define begin
Definition: vmac.h:32
bool operator==(const AbsHcalFunctor &r) const