All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TimeRange.h
Go to the documentation of this file.
1 /**
2  * \file TimeRange.h
3  *
4  * \ingroup Algorithm
5  *
6  * \brief Class def header for a class TimeRange
7  *
8  * @author kazuhiro
9  */
10 
11 /** \addtogroup Algorithm
12 
13  @{*/
14 #ifndef OPT0FINDER_TIMERANGE_H
15 #define OPT0FINDER_TIMERANGE_H
16 
17 #include <iostream>
18 #include <utility>
19 #include <algorithm>
20 #include <vector>
21 
22 namespace flashmatch {
23 
24 
25  /**
26  \class TimeRange
27  User defined class TimeRange ... these comments are used to generate
28  doxygen documentation!
29  */
30  class TimeRange {
31 
32  public:
33 
34  /// Default constructor
35  TimeRange(double start=0,double end=0)
36  { SetRange(start,end); }
37 
38  /// Default destructor
40 
41  void SetRange(double start,double end)
42  {
43  if(start >= end) throw std::exception();
44  _start=start;
45  _end=end;
46  }
47 
48  double Start() const { return _start; }
49 
50  double End() const { return _end; }
51 
52  inline bool operator<(const TimeRange& rhs) const {
53  if(_end < rhs.Start()) return true;
54  if(rhs.End() < _start) return false;
55  return false;
56  }
57 
58  inline bool operator<(const double& rhs) const {
59  if(_end < rhs) return true;
60  if(rhs < _start ) return false;
61  return false;
62  }
63 
64  private:
65 
66  double _start;
67  double _end;
68 
69  };
70 
71  class TimeRangeSet {
72 
73  public:
75 
77 
78  //int RangeIndex(double time);
79 
80  void Print() const
81  {
82  for(auto const& r : _time_range_v)
83  std::cout<<r.Start()<<" => "<<r.End()<<std::endl;
84  }
85 
86  bool Overlap(const flashmatch::TimeRange& range) const
87  {
88  auto low = std::lower_bound(_time_range_v.begin(),
89  _time_range_v.end(),
90  range);
91  if(low == _time_range_v.end()) return false;
92  if(range.End() >= (*low).Start()) return true;
93  return false;
94  }
95 
96  bool Overlap(double time) const
97  { auto low = std::lower_bound(_time_range_v.begin(),
98  _time_range_v.end(),
99  time);
100  if(low == _time_range_v.end()) return false;
101  return ((*low).Start() <= time && time <= (*low).End());
102  }
103 
104  void Insert(const flashmatch::TimeRange& range)
105  {
106  auto low = std::lower_bound(_time_range_v.begin(),
107  _time_range_v.end(),
108  range);
109 
110  if(low == _time_range_v.end()) {
111  _time_range_v.push_back(range);
112  return;
113  }
114 
115  // Check if found one is overlapping
116  if(range.End() < (*low).Start()){
117 
118  double next_start=0;
119  double next_end =0;
120  double start=range.Start();
121  double end=range.End();
122  while(low != _time_range_v.end()) {
123  next_start = (*low).Start();
124  next_end = (*low).End();
125  (*low).SetRange(start,end);
126  start = next_start;
127  end = next_end;
128  ++low;
129  }
130  _time_range_v.push_back(TimeRange(start,end));
131  }else{
132 
133  if((*low).Start() <= range.End()) {
134 
135  (*low).SetRange(std::min((*low).Start(),range.Start()),
136  std::max((*low).End(),range.End()));
137 
138  // If this overlaps with previous window, set it to previous window's max boundary
139  size_t dist = std::distance(_time_range_v.begin(),low);
140  if(dist) {
141  auto prev = low-1;
142  if((*prev).End() > (*low).Start()) (*low).SetRange((*prev).End(),(*low).End());
143  }
144 
145  // If this overlaps with next window, set it to next window's min boundary
146  if( (dist+1) < _time_range_v.size() ) {
147  auto next = low+1;
148  if((*low).End() > (*next).Start()) (*low).SetRange((*low).Start(),(*next).Start());
149  }
150  }
151  }
152  }
153 
154  private:
155 
156  std::vector<flashmatch::TimeRange> _time_range_v;
157 
158  };
159 }
160 
161 namespace std {
162  template <>
163  class less<flashmatch::TimeRange*>
164  {
165  public:
167  { return (*lhs) < (*rhs); }
168  };
169 }
170 
171 #endif
172 /** @} */ // end of doxygen group
173 
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Definition: UtilFunc.cxx:42
double Start() const
Definition: TimeRange.h:48
void Print() const
Definition: TimeRange.h:80
void SetRange(double start, double end)
Definition: TimeRange.h:41
bool operator<(const double &rhs) const
Definition: TimeRange.h:58
double End() const
Definition: TimeRange.h:50
standard_dbscan3dalg useful for diagnostics hits not in a line will not be clustered on on only for track like only for track like on on the smaller the less shower like tracks low
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
std::vector< flashmatch::TimeRange > _time_range_v
Definition: TimeRange.h:156
void Insert(const flashmatch::TimeRange &range)
Definition: TimeRange.h:104
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
bool operator<(const TimeRange &rhs) const
Definition: TimeRange.h:52
TimeRange(double start=0, double end=0)
Default constructor.
Definition: TimeRange.h:35
bool Overlap(const flashmatch::TimeRange &range) const
Definition: TimeRange.h:86
bool Overlap(double time) const
Definition: TimeRange.h:96
esac echo uname r
BEGIN_PROLOG could also be cout
~TimeRange()
Default destructor.
Definition: TimeRange.h:39
bool operator()(const flashmatch::TimeRange *lhs, const flashmatch::TimeRange *rhs)
Definition: TimeRange.h:166