CMS 3D CMS Logo

PixelRecoRange.h
Go to the documentation of this file.
1 #ifndef PixelRecoRange_H
2 #define PixelRecoRange_H
3 
6 #include <ostream>
7 #include <utility>
8 #include <algorithm>
9 
12 
13 template <class T>
14 class PixelRecoRange : public std::pair<T, T> {
15 public:
17 
18  template <class U>
20 
21  PixelRecoRange(T aMin, T aMax) : std::pair<T, T>(aMin, aMax) {}
22 
23  PixelRecoRange(const std::pair<T, T>& aPair) : std::pair<T, T>(aPair) {}
24 
25  T min() const { return this->first; }
26  T max() const { return this->second; }
27  T mean() const { return T(0.5) * (this->first + this->second); }
28 
29  bool empty() const { return (this->second < this->first); }
30 
32  std::swap(this->second, this->first);
33  return *this;
34  }
35 
36  bool inside(const T& value) const { return !((value < this->first) | (this->second < value)); }
37 
38  bool hasIntersection(const PixelRecoRange<T>& r) const { return rangesIntersect(*this, r); }
39 
41 
43  if (this->empty())
44  return r;
45  else if (r.empty())
46  return *this;
47  else
48  return PixelRecoRange(std::min(min(), r.min()), std::max(max(), r.max()));
49  }
50 
52  if (empty())
53  std::swap(this->first, this->second);
54  return *this;
55  }
56 };
57 
58 template <class T>
59 std::ostream& operator<<(std::ostream& out, const PixelRecoRange<T>& r) {
60  return out << "(" << r.min() << "," << r.max() << ")";
61 }
62 #endif
PixelRecoRange(const std::pair< T, T > &aPair)
bool inside(const T &value) const
PixelRecoRange< T > & sort()
PixelRecoRange< T > & swap()
PixelRecoRange(PixelRecoRange< U > other)
U second(std::pair< T, U > const &p)
bool hasIntersection(const PixelRecoRange< T > &r) const
bool empty() const
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: value.py:1
bool rangesIntersect(const Range &a, const Range &b)
PixelRecoRange< T > intersection(const PixelRecoRange< T > &r) const
T mean() const
Range rangeIntersection(const Range &a, const Range &b)
PixelRecoRange< T > sum(const PixelRecoRange< T > &r) const
PixelRecoRange(T aMin, T aMax)
long double T