Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JTreeScannerInterface.hh
Go to the documentation of this file.
1#ifndef __JSUPPORT__JTREESCANNERINTERFACE__
2#define __JSUPPORT__JTREESCANNERINTERFACE__
3
5#include "JLang/JNullType.hh"
6#include "JLang/JEquals.hh"
9#include "JSupport/JLimit.hh"
10
11
12/**
13 * \author mdejong
14 */
15
16namespace JSUPPORT {}
17namespace JPP { using namespace JSUPPORT; }
18
19namespace JSUPPORT {
20
21 using JLANG::JEquals;
24 using JLANG::JNullType;
25
26
27 /**
28 * Auxiliary interface for direct access of elements in ROOT TChain.
29 *
30 * The optional second template argument is used to the determine the value of an element
31 * which defines the apparent order the elements in the TChain.
32 */
33 template<class T, class JEvaluator_t = JNullType>
35
36
37 /**
38 * Specialiation of interface JTreeScannerInterface for unordered direct access of elements in ROOT TChain.
39 *
40 * This interface provives for STD compatible iterators.\n
41 * Note that a pointer to the parent JTreeScannerInterface is used for the iteration.
42 * The user should therefore make separate copies of the read data when data are modified or multiple iterators are simultaneously used.
43 *
44 * This interface extends the JLANG::JRewindableObjectIterator interface and the JSUPPORT::JLimit class.
45 */
46 template<class JClass_t>
48 public JRewindableObjectIterator<JClass_t>,
49 public JLimit
50 {
51 private:
52 /**
53 * Base class for STD compatible iterator.
54 */
55 template<class T>
57 public JEquals<T>,
59 {
60 /**
61 * Equality of iterator.
62 *
63 * \param cursor iterator
64 * \return true if equal; else false
65 */
66 virtual bool equals(const T& cursor) const
67 {
68 return index == cursor.index;
69 }
70
71
72 /**
73 * Increment iterator.
74 *
75 * \return true if valid; else false
76 */
77 virtual bool increment() override
78 {
79 return ++index < pTreeScanner->getEntries();
80 }
81
82
83 /**
84 * Decrement iterator.
85 *
86 * \return true if valid; else false
87 */
88 virtual bool decrement() override
89 {
90 return --index >= 0;
91 }
92
93
94 /**
95 * Increment iterator.
96 *
97 * \param offset offset
98 * \return true if incremented; else false
99 */
100 virtual bool increment(const size_t offset) override
101 {
102 return (index += offset) < pTreeScanner->getEntries();
103 }
104
105
106 /**
107 * Decrement iterator.
108 *
109 * \param offset offset
110 * \return true if decremented; else false
111 */
112 virtual bool decrement(const size_t offset) override
113 {
114 return (index -= offset) >= 0;
115 }
116
117
118 /**
119 * Get index.
120 *
121 * \return index
122 */
124 {
125 return index;
126 }
127
128 protected:
129 /**
130 * Default constructor.
131 */
133 pTreeScanner(NULL),
134 index(-1)
135 {}
136
137
138 /**
139 * Constructor.
140 *
141 * \param p pointer to tree scanner interface
142 * \param i start index
143 */
145 pTreeScanner(p),
146 index(i)
147 {}
148
151 };
152
153 public:
154
155 typedef JClass_t data_type;
157
158
159 /**
160 * Configure.
161 *
162 * \param file_list file list
163 * \param limit limit
164 */
165 virtual void configure(const JMultipleFileScanner_t& file_list, const JLimit& limit) = 0;
166
167
168 /**
169 * Configure.
170 *
171 * \param file_list file list
172 */
173 void configure(const JMultipleFileScanner_t& file_list)
174 {
175 this->configure(file_list, JLimit());
176 }
177
178
179 /**
180 * Get number of entries.
181 *
182 * \return number of entries
183 */
184 virtual Long64_t getEntries() const = 0;
185
186
187 /**
188 * Get entry at given index.
189 *
190 * \param index index
191 * \return pointer to object (may be NULL)
192 */
193 virtual JClass_t* getEntry(Long64_t index) = 0;
194
195
196 /**
197 * Get internal counter.
198 *
199 * \return counter
200 */
201 virtual counter_type getCounter() const = 0;
202
203
204 /**
205 * Get actual class name.
206 *
207 * \return class name
208 */
209 virtual const char* getClassName() const
210 {
211 return JClass_t::Class_Name();
212 }
213
214
215 /**
216 * STD compatible iterator.
217 */
218 struct iterator :
219 public basic_iterator<iterator>
220 {
222
224
225 /**
226 * Default constructor.
227 */
229 {}
230
231
232 /**
233 * Smart pointer operator.
234 *
235 * \return pointer to object
236 */
238 {
239 return this->pTreeScanner->getEntry(this->index);
240 }
241
242
243 /**
244 * Dereference operator.
245 *
246 * \return reference to object
247 */
249 {
250 return *(this->pTreeScanner->getEntry(this->index));
251 }
252
253
254 /**
255 * Get distance between two iterators.
256 *
257 * \param first first iterator
258 * \param second second iterator
259 * \return distance
260 */
261 friend inline difference_type distance(const iterator& first,
262 const iterator& second)
263 {
264 return second.index - first.index;
265 }
266
267
268 private:
269 /**
270 * Constructor.
271 *
272 * \param p pointer to tree scanner interface
273 * \param i start index
274 */
278 };
279
280
281 /**
282 * STD compatible reverse iterator.
283 */
285 public basic_iterator<reverse_iterator>
286 {
288
290
291 /**
292 * Default constructor.
293 */
296
297
298 /**
299 * Smart pointer operator.
300 *
301 * \return pointer to object
302 */
304 {
305 return (this->pTreeScanner->getEntry(this->pTreeScanner->getEntries() - this->index - 1));
306 }
307
308
309 /**
310 * Dereference operator.
311 *
312 * \return reference to object
313 */
315 {
316 return *(this->pTreeScanner->getEntry(this->pTreeScanner->getEntries() - this->index - 1));
317 }
318
319
320 /**
321 * Get distance between two iterators.
322 *
323 * \param first first iterator
324 * \param second second iterator
325 * \return distance
326 */
327 friend inline difference_type distance(const reverse_iterator& first,
328 const reverse_iterator& second)
329 {
330 return second.index - first.index;
331 }
332
333
334 private:
335 /**
336 * Constructor.
337 *
338 * \param p pointer to tree scanner interface
339 * \param i start index
340 */
344 };
345
346
347 /**
348 * Check emptyness.
349 *
350 * \return true if empty; else false
351 */
352 bool empty() const
353 {
354 return getEntries() == 0;
355 }
356
357
358 /**
359 * Get iterator to begin of data.
360 *
361 * \return iterator
362 */
364 {
365 return iterator(this, this->getLowerLimit());
366 }
367
368
369 /**
370 * Get iterator to end of data.
371 *
372 * \return iterator
373 */
375 {
376 return iterator(this, this->getUpperLimit() < this->getEntries() ? this->getUpperLimit() : this->getEntries());
377 }
378
379
380 /**
381 * Get reverse iterator to begin of data.
382 *
383 * \return reverse iterator
384 */
386 {
387 return reverse_iterator(this, this->getLowerLimit());
388 }
389
390
391 /**
392 * Get reverse iterator to end of data.
393 *
394 * \return reverse iterator
395 */
397 {
398 return reverse_iterator(this, this->getUpperLimit() < this->getEntries() ? this->getUpperLimit() : this->getEntries());
399 }
400 };
401
402
403 /**
404 * Specialiation of interface JTreeScannerInterface for ordered direct access of elements in ROOT TChain.
405 *
406 * This interface extends the JTreeScannerInterface<JClass_t, JNullType> interface
407 * with the additional interface method to find a corresponding entry in the ROOT TChain.
408 */
409 template<class JClass_t, class JEvaluator_t>
411 public virtual JTreeScannerInterface<JClass_t>
412 {
413 public:
414 /**
415 * Type definition of time value.
416 */
417 typedef typename JEvaluator_t::value_type value_type;
418
419
420 /**
421 * Constructor.
422 *
423 * \param evaluator evaluator
424 */
425 JTreeScannerInterface(const JEvaluator_t& evaluator = JEvaluator_t()) :
426 getValue(evaluator)
427 {}
428
429
430 /**
431 * Find index of element that is closest in value to given value.
432 *
433 * \param value value
434 * \return index (-1 in case of error)
435 */
436 virtual Long64_t find(const value_type value) const = 0;
437
438
439 /**
440 * Find index of element that is closest in value to given object.
441 *
442 * \param object object
443 * \return index (-1 in case of error)
444 */
445 template<class T>
446 Long64_t find(const T& object) const
447 {
448 return this->find(getValue(object));
449 }
450
451
452 /**
453 * Get evaluator.
454 *
455 * \return evaluator
456 */
457 const JEvaluator_t& getEvaluator() const
458 {
459 return getValue;
460 }
461
462
463 protected:
464 JEvaluator_t getValue;
465 };
466}
467
468#endif
Auxiliaries for defining the range of iterations of objects.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Template interface for method bool decrement().
Interface for object iteration with rewinding.
virtual void configure(const JMultipleFileScanner_t &file_list, const JLimit &limit)=0
Configure.
virtual const char * getClassName() const
Get actual class name.
void configure(const JMultipleFileScanner_t &file_list)
Configure.
JRewindableObjectIterator< JClass_t >::pointer_type pointer_type
virtual Long64_t getEntries() const =0
Get number of entries.
reverse_iterator rend()
Get reverse iterator to end of data.
virtual JClass_t * getEntry(Long64_t index)=0
Get entry at given index.
virtual counter_type getCounter() const =0
Get internal counter.
reverse_iterator rbegin()
Get reverse iterator to begin of data.
Auxiliary interface for direct access of elements in ROOT TChain.
virtual Long64_t find(const value_type value) const =0
Find index of element that is closest in value to given value.
JEvaluator_t::value_type value_type
Type definition of time value.
const JEvaluator_t & getEvaluator() const
Get evaluator.
Long64_t find(const T &object) const
Find index of element that is closest in value to given object.
JTreeScannerInterface(const JEvaluator_t &evaluator=JEvaluator_t())
Constructor.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Long64_t counter_type
Type definition for counter.
Support classes and methods for experiment specific I/O.
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
Template definition of auxiliary base class for comparison of data structures.
Definition JEquals.hh:84
Auxiliary class for no type definition.
Definition JNullType.hh:19
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
Auxiliary base class for list of file names.
virtual bool decrement(const size_t offset) override
Decrement iterator.
virtual bool increment(const size_t offset) override
Increment iterator.
virtual bool equals(const T &cursor) const
Equality of iterator.
basic_iterator(JTreeScannerInterface *p, const counter_type i)
Constructor.
friend difference_type distance(const iterator &first, const iterator &second)
Get distance between two iterators.
iterator(JTreeScannerInterface *p, const counter_type i)
Constructor.
reverse_iterator(JTreeScannerInterface *p, const counter_type i)
Constructor.
friend difference_type distance(const reverse_iterator &first, const reverse_iterator &second)
Get distance between two iterators.