test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
11 template<class T> class TRange : public std::pair<T,T> {
12 public:
13 
14  TRange() { }
15 
16  TRange(const T & aMin, const T & aMax)
17  : std::pair<T,T> (aMin,aMax) { }
18 
19  TRange(const std::pair<T,T> & apair )
20  : std::pair<T,T> (apair) { }
21 
23  const T & min() const { return this->first; }
24 
26  const T & max() const { return this->second; }
27 
28  T mean() const { return (this->first+this->second)/2.; }
29 
31  bool empty() const { return (this->second < this->first); }
32 
34  bool inside(const T & value) const {
35  if (value < this->first || this->second < value) return false;
36  else return true;
37  }
38 
39 /*
41  bool hasIntersection( const TRange<T> & r) const {
42  return rangesIntersect(*this,r);
43  }
44 
46  TRange<T> intersection(
47  const TRange<T> & r) const {
48  return rangeIntersection(*this,r);
49  }
50 */
51 
53  TRange<T> sum(const TRange<T> & r) const {
54  if( this->empty()) return r;
55  else if( r.empty()) return *this;
56  else return TRange( (min() < r.min()) ? min() : r.min(),
57  (max() < r.max()) ? r.max() : max());
58  }
59 
60  void sort() { if (empty() ) std::swap(this->first,this->second); }
61 };
62 
63 template <class T> std::ostream & operator<<(
64  std::ostream& out, const TRange<T>& r)
65 {
66  return out << "("<<r.min()<<","<<r.max()<<")";
67 }
68 #endif
T mean() const
Definition: TRange.h:28
TRange()
Definition: TRange.h:14
bool inside(const T &value) const
check if object is inside region
Definition: TRange.h:34
TRange< T > sum(const TRange< T > &r) const
sum of overlaping regions. the overlapping should be checked before.
Definition: TRange.h:53
std::ostream & operator<<(std::ostream &out, const ALILine &li)
Definition: ALILine.cc:187
const T & min() const
lower edge of range
Definition: TRange.h:23
Definition: TRange.h:11
U second(std::pair< T, U > const &p)
void sort()
Definition: TRange.h:60
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool first
Definition: L1TdeRCT.cc:75
tuple out
Definition: dbtoconf.py:99
const T & max() const
upper edge of range
Definition: TRange.h:26
bool empty() const
true for empty region. note that region [x,x] is not empty
Definition: TRange.h:31
TRange(const std::pair< T, T > &apair)
Definition: TRange.h:19
TRange(const T &aMin, const T &aMax)
Definition: TRange.h:16
long double T