CMS 3D CMS Logo

TRange.h
Go to the documentation of this file.
1 #ifndef TRange_H
2 #define TRange_H
3 
6 #include <iostream>
7 #include <utility>
8 #include <algorithm>
9 
10 template <class T>
11 class TRange : public std::pair<T, T> {
12 public:
13  TRange() {}
14 
15  TRange(const T& aMin, const T& aMax) : std::pair<T, T>(aMin, aMax) {}
16 
17  TRange(const std::pair<T, T>& apair) : std::pair<T, T>(apair) {}
18 
20  const T& min() const { return this->first; }
21 
23  const T& max() const { return this->second; }
24 
25  T mean() const { return (this->first + this->second) / 2.; }
26 
28  bool empty() const { return (this->second < this->first); }
29 
31  bool inside(const T& value) const {
32  if (value < this->first || this->second < value)
33  return false;
34  else
35  return true;
36  }
37 
38  /*
40  bool hasIntersection( const TRange<T> & r) const {
41  return rangesIntersect(*this,r);
42  }
43 
45  TRange<T> intersection(
46  const TRange<T> & r) const {
47  return rangeIntersection(*this,r);
48  }
49 */
50 
52  TRange<T> sum(const TRange<T>& r) const {
53  if (this->empty())
54  return r;
55  else if (r.empty())
56  return *this;
57  else
58  return TRange((min() < r.min()) ? min() : r.min(), (max() < r.max()) ? r.max() : max());
59  }
60 
61  void sort() {
62  if (empty())
63  std::swap(this->first, this->second);
64  }
65 };
66 
67 template <class T>
68 std::ostream& operator<<(std::ostream& out, const TRange<T>& r) {
69  return out << "(" << r.min() << "," << r.max() << ")";
70 }
71 #endif
TRange::inside
bool inside(const T &value) const
check if object is inside region
Definition: TRange.h:31
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
TRange::TRange
TRange(const std::pair< T, T > &apair)
Definition: TRange.h:17
dqmdumpme.first
first
Definition: dqmdumpme.py:55
TRange::TRange
TRange(const T &aMin, const T &aMax)
Definition: TRange.h:15
operator<<
std::ostream & operator<<(std::ostream &out, const TRange< T > &r)
Definition: TRange.h:68
std::swap
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Definition: DataFrameContainer.h:209
TRange
Definition: TRange.h:11
TRange::sum
TRange< T > sum(const TRange< T > &r) const
sum of overlaping regions. the overlapping should be checked before.
Definition: TRange.h:52
TRange::min
const T & min() const
lower edge of range
Definition: TRange.h:20
TRange::mean
T mean() const
Definition: TRange.h:25
value
Definition: value.py:1
alignCSCRings.r
r
Definition: alignCSCRings.py:93
TRange::TRange
TRange()
Definition: TRange.h:13
std
Definition: JetResolutionObject.h:76
T
long double T
Definition: Basic3DVectorLD.h:48
TRange::empty
bool empty() const
true for empty region. note that region [x,x] is not empty
Definition: TRange.h:28
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
TRange::max
const T & max() const
upper edge of range
Definition: TRange.h:23
TRange::sort
void sort()
Definition: TRange.h:61