Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
16 namespace JSUPPORT {}
17 namespace JPP { using namespace JSUPPORT; }
18 
19 namespace JSUPPORT {
20 
22  using JLANG::JNullType;
23 
24 
25  /**
26  * Auxiliary interface for direct access of elements in ROOT TChain.
27  *
28  * The optional second template argument is used to the determine the value of an element
29  * which defines the apparent order the elements in the TChain.
30  */
31  template<class T, class JEvaluator_t = JNullType>
33 
34 
35  /**
36  * Specialiation of interface JTreeScannerInterface for unordered direct access of elements in ROOT TChain.
37  *
38  * This interface provives for STD compatible iterators.\n
39  * Note that a pointer to the parent JTreeScannerInterface is used for the iteration.
40  * The user should therefore make separate copies of the read data when multiple iterators are simultaneously used.
41  *
42  * This interface extends the JLANG::JRewindableObjectIterator interface and the JSUPPORT::JLimit class.
43  */
44  template<class JClass_t>
45  struct JTreeScannerInterface<JClass_t, JNullType> :
46  public JRewindableObjectIterator<JClass_t>,
47  public JLimit
48  {
49  private:
50  /**
51  * Base class for STD compatible iterator.
52  */
53  template<class T>
54  struct basic_iterator :
55  public JLANG::JEquals<T>,
57  {
58  /**
59  * Equality of iterator.
60  *
61  * \param cursor iterator
62  * \return true if equal; else false
63  */
64  virtual bool equals(const T& cursor) const
65  {
66  return index == cursor.index;
67  }
68 
69 
70  /**
71  * Increment iterator.
72  *
73  * \return true if valid; else false
74  */
75  virtual bool increment()
76  {
77  return ++index < pTreeScanner->getEntries();
78  }
79 
80 
81  /**
82  * Decrement iterator.
83  *
84  * \return true if valid; else false
85  */
86  virtual bool decrement()
87  {
88  return --index >= 0;
89  }
90 
91 
92  /**
93  * Increment iterator.
94  *
95  * \param offset offset
96  * \return true if incremented; else false
97  */
98  virtual bool increment(const size_t offset)
99  {
100  return (index += offset) < pTreeScanner->getEntries();
101  }
102 
103 
104  /**
105  * Decrement iterator.
106  *
107  * \param offset offset
108  * \return true if decremented; else false
109  */
110  virtual bool decrement(const size_t offset)
111  {
112  return (index -= offset) >= 0;
113  }
114 
115  protected:
116  /**
117  * Default constructor.
118  */
120  pTreeScanner(NULL),
121  index(-1)
122  {}
123 
124 
125  /**
126  * Constructor.
127  *
128  * \param p pointer to tree scanner interface
129  * \param i start index
130  */
132  pTreeScanner(p),
133  index(i)
134  {}
135 
138  };
139 
140  public:
141 
142  typedef JClass_t data_type;
144 
145 
146  /**
147  * Configure.
148  *
149  * \param file_list file list
150  * \param limit limit
151  */
152  virtual void configure(const JMultipleFileScanner_t& file_list, const JLimit& limit) = 0;
153 
154 
155  /**
156  * Configure.
157  *
158  * \param file_list file list
159  */
160  void configure(const JMultipleFileScanner_t& file_list)
161  {
162  this->configure(file_list, JLimit());
163  }
164 
165 
166  /**
167  * Get number of entries.
168  *
169  * \return number of entries
170  */
171  virtual Long64_t getEntries() const = 0;
172 
173 
174  /**
175  * Get entry at given index.
176  *
177  * \param index index
178  * \return pointer to object (may be NULL)
179  */
180  virtual JClass_t* getEntry(Long64_t index) = 0;
181 
182 
183  /**
184  * Get internal counter.
185  *
186  * \return counter
187  */
188  virtual counter_type getCounter() const = 0;
189 
190 
191  /**
192  * Get actual class name.
193  *
194  * \return class name
195  */
196  virtual const char* getClassName() const
197  {
198  return JClass_t::Class_Name();
199  }
200 
201 
202  /**
203  * STD compatible iterator.
204  */
205  struct iterator :
206  public basic_iterator<iterator>
207  {
208  friend class JTreeScannerInterface;
209 
210  /**
211  * Default constructor.
212  */
214  {}
215 
216 
217  /**
218  * Smart pointer operator.
219  *
220  * \return pointer to object
221  */
223  {
224  return this->pTreeScanner->getEntry(this->index);
225  }
226 
227 
228  /**
229  * Dereference operator.
230  *
231  * \return reference to object
232  */
234  {
235  return *(this->pTreeScanner->getEntry(this->index));
236  }
237 
238  private:
239  /**
240  * Constructor.
241  *
242  * \param p pointer to tree scanner interface
243  * \param i start index
244  */
246  basic_iterator<iterator>(p, i)
247  {}
248  };
249 
250 
251  /**
252  * STD compatible reverse iterator.
253  */
254  struct reverse_iterator :
255  public basic_iterator<reverse_iterator>
256  {
257  friend class JTreeScannerInterface;
258 
259  /**
260  * Default constructor.
261  */
263  {}
264 
265 
266  /**
267  * Smart pointer operator.
268  *
269  * \return pointer to object
270  */
272  {
273  return (this->pTreeScanner->getEntry(this->pTreeScanner->getEntries() - this->index - 1));
274  }
275 
276 
277  /**
278  * Dereference operator.
279  *
280  * \return reference to object
281  */
283  {
284  return *(this->pTreeScanner->getEntry(this->pTreeScanner->getEntries() - this->index - 1));
285  }
286 
287  private:
288  /**
289  * Constructor.
290  *
291  * \param p pointer to tree scanner interface
292  * \param i start index
293  */
295  basic_iterator<reverse_iterator>(p, i)
296  {}
297  };
298 
299 
300  /**
301  * Check emptyness.
302  *
303  * \return true if empty; else false
304  */
305  bool empty() const
306  {
307  return getEntries() == 0;
308  }
309 
310 
311  /**
312  * Get iterator to begin of data.
313  *
314  * \return iterator
315  */
317  {
318  return iterator(this, this->getLowerLimit());
319  }
320 
321 
322  /**
323  * Get iterator to end of data.
324  *
325  * \return iterator
326  */
328  {
329  return iterator(this, this->getUpperLimit() < this->getEntries() ? this->getUpperLimit() : this->getEntries());
330  }
331 
332 
333  /**
334  * Get reverse iterator to begin of data.
335  *
336  * \return reverse iterator
337  */
338  reverse_iterator rbegin()
339  {
340  return reverse_iterator(this, this->getLowerLimit());
341  }
342 
343 
344  /**
345  * Get reverse iterator to end of data.
346  *
347  * \return reverse iterator
348  */
349  reverse_iterator rend()
350  {
351  return reverse_iterator(this, this->getUpperLimit() < this->getEntries() ? this->getUpperLimit() : this->getEntries());
352  }
353  };
354 
355 
356  /**
357  * Specialiation of interface JTreeScannerInterface for ordered direct access of elements in ROOT TChain.
358  *
359  * This interface extends the JTreeScannerInterface<JClass_t, JNullType> interface by
360  * defining the additional interface method to find a corresponding entry in the ROOT TChain.
361  */
362  template<class JClass_t, class JEvaluator_t>
363  struct JTreeScannerInterface :
364  public virtual JTreeScannerInterface<JClass_t>
365  {
366  /**
367  * Constructor.
368  *
369  * \param evaluator evaluator
370  */
371  JTreeScannerInterface(const JEvaluator_t& evaluator = JEvaluator_t()) :
372  getValue(evaluator)
373  {}
374 
375 
376  /**
377  * Find index of element that is closest in value to given value.
378  *
379  * \param value value
380  * \return index (-1 in case of error)
381  */
382  virtual Long64_t find(const double value) const = 0;
383 
384 
385  /**
386  * Find index of element that is closest in value to given object.
387  *
388  * \param object object
389  * \return index (-1 in case of error)
390  */
391  template<class T>
392  Long64_t find(const T& object) const
393  {
394  return this->find(getValue(object));
395  }
396 
397 
398  /**
399  * Get evaluator.
400  *
401  * \return evaluator
402  */
403  const JEvaluator_t& getEvaluator() const
404  {
405  return getValue;
406  }
407 
408 
409  protected:
410  JEvaluator_t getValue;
411  };
412 }
413 
414 #endif
virtual bool equals(const T &cursor) const
Equality of iterator.
Interface for object iteration with rewinding.
virtual bool decrement(const size_t offset)
Decrement iterator.
void configure(const JMultipleFileScanner_t &file_list)
Configure.
reverse_iterator rbegin()
Get reverse iterator to begin of data.
reverse_iterator rend()
Get reverse iterator to end of data.
Long64_t counter_type
Type definition for counter.
virtual Long64_t find(const double value) const =0
Find index of element that is closest in value to given value.
Auxiliary interface for direct access of elements in ROOT TChain.
basic_iterator(JTreeScannerInterface *p, const counter_type i)
Constructor.
virtual const char * getClassName() const
Get actual class name.
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:41
Template interface for method bool decrement().
iterator(JTreeScannerInterface *p, const counter_type i)
Constructor.
JRewindableObjectIterator< JClass_t >::pointer_type pointer_type
do set_variable OUTPUT_DIRECTORY $WORKDIR T
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
Auxiliary class for no type definition.
Definition: JNullType.hh:19
virtual bool increment(const size_t offset)
Increment iterator.
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Auxiliary base class for list of file names.
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
JTreeScannerInterface(const JEvaluator_t &evaluator=JEvaluator_t())
Constructor.
reverse_iterator(JTreeScannerInterface *p, const counter_type i)
Constructor.
Long64_t find(const T &object) const
Find index of element that is closest in value to given object.
Auxiliaries for defining the range of iterations of objects.
const JEvaluator_t & getEvaluator() const
Get evaluator.