GroupedHitList.h
Go to the documentation of this file.
1 #ifndef DDT_GROUPED_HIT_LIST_H
2 #define DDT_GROUPED_HIT_LIST_H
3 
4 
6 
7 #include <vector>
8 
9 
10 namespace novaddt
11 {
12  template <class VAL>
14  {
15  public:
17 
18 #ifndef __GCCXML__
19  typedef VAL value_t;
20 
21  // The following link shows how to properly design GroupedHitLists:
22  // https://cdcvs.fnal.gov/redmine/projects/novaddt/wiki/Designing_Proper_GroupedHitLists
23  template <class It>
24  GroupedHitList(It begin, It end, std::vector<size_t> boundary_list);
25 
26  unsigned n_groups() const;
27 
28  // this method provides the number of hits in the requested group
29  std::size_t group_size(unsigned group) const;
30 
31  typename VAL::value_type first_value() const;
32  typename VAL::value_type last_value() const;
33  typename VAL::value_type extent() const;
34 
35  // get a sorted hit list for the requested group or grab the entire thing
36  HitList get(unsigned group) const;
37  HitList const & get() const;
38 #endif
39 
40  private:
41 #ifndef __GCCXML__
42  // get the low and high bound of the requested group
43  std::size_t low(unsigned group) const;
44  std::size_t high(unsigned group) const;
45 
46  // convert the index to an iterator in the ordered hit list
47  HitList::const_iterator get_it(size_t index) const;
48 
49  // check whether HitList is empty (asserts when it is empty)
50  void check_empty() const;
51 
52 #endif
53 
55  std::vector<size_t> bound_list_;
56  };
57 
58 
59  template <class VAL>
61  {
62  }
63 
64 
65 #ifndef __GCCXML__
66 
67 
68  template <class VAL>
69  template <class It> inline
71  GroupedHitList(It begin, It end, std::vector<size_t> boundary_list)
72  : hits_(begin, end),
73  bound_list_(boundary_list)
74  {
75  }
76 
77 
78  template <class VAL> inline
80  {
81  unsigned result = 0;
82  if (!bound_list_.empty())
83  // Since the boundary list contains the beginning and the end,
84  // the number of groups is one less than the number of boundaries.
85  result = bound_list_.size() - 1;
86 
87  return result;
88  }
89 
90 
91  template <class VAL> inline
92  std::size_t GroupedHitList<VAL>::low(unsigned group) const
93  {
94  return bound_list_.at(group);
95  }
96 
97 
98  template <class VAL> inline
99  std::size_t GroupedHitList<VAL>::high(unsigned group) const
100  {
101  // the upper bound is the lower bound of the next group
102  return bound_list_.at(group + 1);
103  }
104 
105 
106  template <class VAL> inline
107  std::size_t GroupedHitList<VAL>::group_size(unsigned group) const
108  {
109  return high(group) - low(group);
110  }
111 
112 
113  template <class VAL> inline
115  {
116  if (hits_.empty())
117  {
118  std::cerr << "The HitList is empty, so you cannot retrieve any elements."
119  << std::endl;
120  assert(false);
121  }
122  }
123 
124 
125  template <class VAL> inline
126  typename VAL::value_type GroupedHitList<VAL>::first_value() const
127  {
128  check_empty();
129 
130  return VAL(hits_.front()).val;
131  }
132 
133 
134  template <class VAL> inline
135  typename VAL::value_type GroupedHitList<VAL>::last_value() const
136  {
137  check_empty();
138 
139  return VAL(hits_.back()).val;
140  }
141 
142 
143  template <class VAL> inline
144  typename VAL::value_type GroupedHitList<VAL>::extent() const
145  {
146  return last_value() - first_value();
147  }
148 
149 
150  template <class VAL> inline
151  HitList::const_iterator
153  {
154  return hits_.begin() + index;
155  }
156 
157 
158  template <class VAL> inline
160  {
161  return HitList(get_it(low(group)), get_it(high(group)));
162  }
163 
164 
165  template <class VAL> inline
167  {
168  return hits_;
169  }
170 
171 
172 #endif
173 
174 
175 }
176 
177 
178 #endif
std::vector< DAQHit > HitList
Definition: HitList.h:15
std::size_t low(unsigned group) const
OStream cerr
Definition: OStream.cxx:7
VAL::value_type extent() const
HitList::const_iterator get_it(size_t index) const
unsigned n_groups() const
std::size_t group_size(unsigned group) const
VAL::value_type first_value() const
std::vector< size_t > bound_list_
HitList const & get() const
assert(nhit_max >=nhit_nbins)
std::size_t high(unsigned group) const
VAL::value_type last_value() const