Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:12

0001 #ifndef CondFormats_HcalObjects_AbsHcalFunctor_h
0002 #define CondFormats_HcalObjects_AbsHcalFunctor_h
0003 
0004 #include <cfloat>
0005 #include <typeinfo>
0006 
0007 #include "boost/serialization/access.hpp"
0008 #include "boost/serialization/base_object.hpp"
0009 #include "boost/serialization/export.hpp"
0010 
0011 // Archive headers are needed here for the serialization registration to work.
0012 // <cassert> is needed for the archive headers to work.
0013 #if !defined(__GCCXML__)
0014 #include <cassert>
0015 #include "CondFormats/Serialization/interface/eos/portable_iarchive.hpp"
0016 #include "CondFormats/Serialization/interface/eos/portable_oarchive.hpp"
0017 #endif /* #if !defined(__GCCXML__) */
0018 
0019 class AbsHcalFunctor {
0020 public:
0021   inline virtual ~AbsHcalFunctor() {}
0022 
0023   // Method to override by concrete storable functor classes
0024   virtual double operator()(double x) const = 0;
0025 
0026   // Functor domain. Should be overriden by derived classes if needed.
0027   inline virtual double xmin() const { return -DBL_MAX; }
0028   inline virtual double xmax() const { return DBL_MAX; }
0029 
0030   // Comparison operators. Note that they are not virtual and should
0031   // not be overriden by derived classes. These operators are very
0032   // useful for I/O testing.
0033   inline bool operator==(const AbsHcalFunctor& r) const { return (typeid(*this) == typeid(r)) && this->isEqual(r); }
0034   inline bool operator!=(const AbsHcalFunctor& r) const { return !(*this == r); }
0035 
0036 protected:
0037   // Method needed to compare objects for equality.
0038   // Must be implemented by derived classes.
0039   virtual bool isEqual(const AbsHcalFunctor&) const = 0;
0040 
0041   // Check if the sequence of values is strictly increasing
0042   template <class Iter>
0043   static bool isStrictlyIncreasing(Iter begin, Iter const end) {
0044     if (begin == end)
0045       return false;
0046     Iter first(begin);
0047     bool status = ++begin != end;
0048     for (; begin != end && status; ++begin, ++first)
0049       if (!(*first < *begin))
0050         status = false;
0051     return status;
0052   }
0053 
0054   // Check if the sequence of values is strictly decreasing
0055   template <class Iter>
0056   static bool isStrictlyDecreasing(Iter begin, Iter const end) {
0057     if (begin == end)
0058       return false;
0059     Iter first(begin);
0060     bool status = ++begin != end;
0061     for (; begin != end && status; ++begin, ++first)
0062       if (!(*begin < *first))
0063         status = false;
0064     return status;
0065   }
0066 
0067 private:
0068   friend class boost::serialization::access;
0069   template <typename Ar>
0070   inline void serialize(Ar& ar, unsigned /* version */) {}
0071 };
0072 
0073 BOOST_CLASS_EXPORT_KEY(AbsHcalFunctor)
0074 
0075 #endif  // CondFormats_HcalObjects_AbsHcalFunctor_h