Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JClone.hh
Go to the documentation of this file.
1#ifndef __JTRIGGER__JCLONE__
2#define __JTRIGGER__JCLONE__
3
4#include <algorithm>
5
6#include "JLang/JClass.hh"
8
9
10/**
11 * \author mdejong
12 */
13
14namespace JTRIGGER {}
15namespace JPP { using namespace JTRIGGER; }
16
17namespace JTRIGGER {
18
19 /**
20 * Clone of a container.
21 *
22 * A JClone object contains a reference to container data and can be used as any normal container.
23 * It comprises in addition an internal iterator which is implemented as mutable data member.
24 *
25 * The methods
26 * - JClone::is_valid,
27 * - JClone::rewind,
28 * - JClone::next,
29 * - JClone::lower_bound,
30 * - JClone::fast_forward and
31 * - JClone::get
32 *
33 * can be used to check, set and access the internal iterator.
34 *
35 * The data in the original container should have been terminated with an appriopriate end marker.
36 */
37 template<class JContainer_t>
38 class JClone :
39 public JHitToolkit<typename JContainer_t::value_type>
40 {
41 public:
42
43 typedef typename JContainer_t::value_type value_type;
45 typedef typename JContainer_t::const_iterator const_iterator;
46 typedef typename JContainer_t::const_iterator iterator;
47
52
53
54 /**
55 * Default constructor.
56 */
59 __begin(),
60 __end (),
61 __i ()
62 {}
63
64
65 /**
66 * Constructor.
67 *
68 * \param input input
69 */
70 JClone(const JContainer_t& input) :
72 __begin(input.begin()),
73 __end (input.end ()),
74 __i (input.begin())
75 {}
76
77
78 /**
79 * Get begin of data.
80 *
81 * \return begin of data
82 */
83 iterator begin() const
84 {
85 return __begin;
86 }
87
88
89 /**
90 * Get end of data.
91 *
92 * \return end of data
93 */
94 iterator end() const
95 {
96 return __end;
97 }
98
99
100 /**
101 * Get size of data.
102 *
103 * \return size of data
104 */
105 inline unsigned int size() const
106 {
107 return std::distance(__begin, __end);
108 }
109
110
111 /**
112 * Check size of data.
113 *
114 * \return true if empty; else false
115 */
116 inline bool empty() const
117 {
118 return __begin == __end;
119 }
120
121
122 /**
123 * Rewind internal iterator.
124 */
125 inline void rewind() const
126 {
127 __i = __begin;
128 }
129
130
131 /**
132 * Check internal iterator.
133 *
134 * \return true if internal iterator not yet at end; else false
135 */
136 inline bool is_valid() const
137 {
138 return __i != __end;
139 }
140
141
142 /**
143 * Increment internal iterator.
144 */
145 inline void next() const
146 {
147 ++__i;
148 }
149
150
151 /**
152 * Get internal iterator.
153 *
154 * \return internal operator
155 */
156 inline iterator get() const
157 {
158 return __i;
159 }
160
161
162 /**
163 * Get time of internal iterator.
164 *
165 * \return time of internal iterator [ns]
166 */
167 inline double getT() const
168 {
169 return getT(*__i);
170 }
171
172
173 /**
174 * Get time-over-threshold of internal iterator.
175 *
176 * \return time-over-threshold of hit [ns]
177 */
178 inline double getToT() const
179 {
180 return getToT(*__i);
181 }
182
183
184 /**
185 * Construct JHit from internal iterator.
186 *
187 * \return hit
188 */
189 inline JHit getJHit() const
190 {
191 return getJHit(*__i);
192 }
193
194
195 /**
196 * Get time difference with respect to given hits.
197 *
198 * \param hit hit
199 * \return time of internal iterator - time hit [ns]
200 */
201 inline double getTimeDifference(argument_type hit) const
202 {
203 return getTimeDifference(hit, *__i);
204 }
205
206
207 /**
208 * Set the internal iterator to the lower bound corresponding to the time of the given hit.
209 *
210 * \param hit hit
211 * \return internal operator
212 */
214 {
215 return (__i = std::lower_bound(__begin, __end, hit, this->getToolkit()));
216 }
217
218
219 /**
220 * Increment the internal iterator until the lower bound corresponding to the time of the given hit.
221 *
222 * \param hit hit
223 * \return internal operator
224 */
226 {
229 ++__i;
230 }
231
232 return __i;
233 }
234
235
236 protected:
239 mutable iterator __i;
240 };
241}
242
243#endif
Tools for handling different hit types.
Clone of a container.
Definition JClone.hh:40
iterator __end
Definition JClone.hh:238
bool is_valid() const
Check internal iterator.
Definition JClone.hh:136
iterator fast_forward(argument_type hit) const
Increment the internal iterator until the lower bound corresponding to the time of the given hit.
Definition JClone.hh:225
iterator __begin
Definition JClone.hh:237
void next() const
Increment internal iterator.
Definition JClone.hh:145
double getT() const
Get time of internal iterator.
Definition JClone.hh:167
unsigned int size() const
Get size of data.
Definition JClone.hh:105
JClone()
Default constructor.
Definition JClone.hh:57
double getToT() const
Get time-over-threshold of internal iterator.
Definition JClone.hh:178
JContainer_t::const_iterator const_iterator
Definition JClone.hh:45
bool empty() const
Check size of data.
Definition JClone.hh:116
JLANG::JClass< value_type >::argument_type argument_type
Definition JClone.hh:44
iterator begin() const
Get begin of data.
Definition JClone.hh:83
double getTimeDifference(argument_type hit) const
Get time difference with respect to given hits.
Definition JClone.hh:201
JContainer_t::value_type value_type
Definition JClone.hh:43
iterator end() const
Get end of data.
Definition JClone.hh:94
JHit getJHit() const
Construct JHit from internal iterator.
Definition JClone.hh:189
JClone(const JContainer_t &input)
Constructor.
Definition JClone.hh:70
iterator __i
Definition JClone.hh:239
iterator lower_bound(argument_type hit) const
Set the internal iterator to the lower bound corresponding to the time of the given hit.
Definition JClone.hh:213
JContainer_t::const_iterator iterator
Definition JClone.hh:46
iterator get() const
Get internal iterator.
Definition JClone.hh:156
void rewind() const
Rewind internal iterator.
Definition JClone.hh:125
Hit data structure.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for triggering.
JArgument< T >::argument_type argument_type
Definition JClass.hh:82
Template definition of hit toolkit.