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  using JLANG::JEquals;
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 the internal iterator is used during iteration;
42  * one may therefore need to rewind the object before using
43  * the methods of the JLANG::JObjectIterator interface.
44  *
45  * This interface extends the JLANG::JRewindableObjectIterator interface and
46  * the JSUPPORT::JLimit class.
47  */
48  template<class JClass_t>
49  struct JTreeScannerInterface<JClass_t, JNullType> :
50  public JRewindableObjectIterator<JClass_t>,
51  public JLimit
52  {
53  typedef JClass_t data_type;
55 
56  /**
57  * Configure.
58  *
59  * \param file_list file list
60  * \param limit limit
61  */
62  virtual void configure(const JMultipleFileScanner_t& file_list, const JLimit& limit) = 0;
63 
64 
65  /**
66  * Configure.
67  *
68  * \param file_list file list
69  */
70  void configure(const JMultipleFileScanner_t& file_list)
71  {
72  this->configure(file_list, JLimit());
73  }
74 
75 
76  /**
77  * Get number of entries.
78  *
79  * \return number of entries
80  */
81  virtual Long64_t getEntries() const = 0;
82 
83 
84  /**
85  * Get entry at given index.
86  *
87  * \param index index
88  * \return pointer to object (may be NULL)
89  */
90  virtual JClass_t* getEntry(Long64_t index) = 0;
91 
92 
93  /**
94  * Get internal counter.
95  *
96  * \return counter
97  */
98  virtual counter_type getCounter() const = 0;
99 
100 
101  /**
102  * Get actual class name.
103  *
104  * \return class name
105  */
106  virtual const char* getClassName() const
107  {
108  return JClass_t::Class_Name();
109  }
110 
111 
112  /**
113  * STD compatible iterator.
114  */
115  struct iterator :
116  public JLANG::JEquals <iterator>,
117  public JLANG::JBidirectionalIterator<iterator>
118  {
119  friend class JTreeScannerInterface;
120 
121  /**
122  * Default constructor.
123  */
125  pTreeScanner(NULL),
126  index (-1)
127  {}
128 
129 
130  /**
131  * Smart pointer operator.
132  *
133  * \return pointer to object
134  */
136  {
137  return pTreeScanner->getEntry(index);
138  }
139 
140 
141  /**
142  * Dereference operator.
143  *
144  * \return reference to object
145  */
147  {
148  return *(pTreeScanner->getEntry(index));
149  }
150 
151 
152  /**
153  * Equality of iterator.
154  *
155  * \param cursor iterator
156  * \return true if equal; else false
157  */
158  virtual bool equals(const iterator& cursor) const
159  {
160  return index == cursor.index;
161  }
162 
163 
164  /**
165  * Increment iterator.
166  *
167  * \return true if valid; else false
168  */
169  virtual bool increment()
170  {
171  return ++index < pTreeScanner->getEntries();
172  }
173 
174 
175  /**
176  * Decrement iterator.
177  *
178  * \return true if valid; else false
179  */
180  virtual bool decrement()
181  {
182  return --index >= 0;
183  }
184 
185 
186  private:
187  /**
188  * Constructor.
189  *
190  * \param __p pointer to tree scanner
191  * \param __i start index
192  */
194  pTreeScanner(__p),
195  index (__i)
196  {}
197 
200  };
201 
202 
203  /**
204  * STD compatible reverse iterator.
205  */
206  struct reverse_iterator :
207  public JLANG::JEquals <reverse_iterator>,
208  public JLANG::JBidirectionalIterator<reverse_iterator>
209  {
210  friend class JTreeScannerInterface;
211 
212  /**
213  * Default constructor.
214  */
216  pTreeScanner(NULL),
217  index (-1)
218  {}
219 
220 
221  /**
222  * Smart pointer operator.
223  *
224  * \return pointer to object
225  */
227  {
228  return (this->pTreeScanner->getEntry(this->pTreeScanner->getEntries() - this->index - 1));
229  }
230 
231 
232  /**
233  * Dereference operator.
234  *
235  * \return reference to object
236  */
238  {
239  return *(this->pTreeScanner->getEntry(this->pTreeScanner->getEntries() - this->index - 1));
240  }
241 
242 
243  /**
244  * Equality of iterator.
245  *
246  * \param cursor iterator
247  * \return true if equal; else false
248  */
249  virtual bool equals(const reverse_iterator& cursor) const
250  {
251  return index == cursor.index;
252  }
253 
254 
255  /**
256  * Increment iterator.
257  *
258  * \return true if valid; else false
259  */
260  virtual bool increment()
261  {
262  return ++index < pTreeScanner->getEntries();
263  }
264 
265 
266  /**
267  * Decrement iterator.
268  *
269  * \return true if valid; else false
270  */
271  virtual bool decrement()
272  {
273  return --index >= 0;
274  }
275 
276 
277  private:
278  /**
279  * Constructor.
280  *
281  * \param __p pointer to tree scanner
282  * \param __i start index
283  */
285  pTreeScanner(__p),
286  index (__i)
287  {}
288 
291  };
292 
293 
294  /**
295  * Get iterator to begin of data.
296  *
297  * \return iterator
298  */
299  iterator begin()
300  {
301  return iterator(this, this->getLowerLimit());
302  }
303 
304 
305  /**
306  * Get iterator to end of data.
307  *
308  * \return iterator
309  */
310  iterator end()
311  {
312  return iterator(this, this->getUpperLimit() < this->getEntries() ? this->getUpperLimit() : this->getEntries());
313  }
314 
315 
316  /**
317  * Get reverse iterator to begin of data.
318  *
319  * \return reverse iterator
320  */
321  reverse_iterator rbegin()
322  {
323  return reverse_iterator(this, this->getLowerLimit());
324  }
325 
326 
327  /**
328  * Get reverse iterator to end of data.
329  *
330  * \return reverse iterator
331  */
332  reverse_iterator rend()
333  {
334  return reverse_iterator(this, this->getUpperLimit() < this->getEntries() ? this->getUpperLimit() : this->getEntries());
335  }
336  };
337 
338 
339  /**
340  * Specialiation of interface JTreeScannerInterface for ordered direct access of elements in ROOT TChain.
341  *
342  * This interface extends the JTreeScannerInterface<JClass_t, JNullType> interface by
343  * defining the additional interface method to find a corresponding entry in the ROOT TChain.
344  */
345  template<class JClass_t, class JEvaluator_t>
346  struct JTreeScannerInterface :
347  public virtual JTreeScannerInterface<JClass_t>
348  {
349  /**
350  * Constructor.
351  *
352  * \param evaluator evaluator
353  */
354  JTreeScannerInterface(const JEvaluator_t& evaluator = JEvaluator_t()) :
355  getValue(evaluator)
356  {}
357 
358 
359  /**
360  * Find index of element that is closest in value to given value.
361  *
362  * \param value value
363  * \return index (-1 in case of error)
364  */
365  virtual Long64_t find(const double value) const = 0;
366 
367 
368  /**
369  * Find index of element that is closest in value to given object.
370  *
371  * \param object object
372  * \return index (-1 in case of error)
373  */
374  template<class T>
375  Long64_t find(const T& object) const
376  {
377  return this->find(getValue(object));
378  }
379 
380 
381  /**
382  * Get evaluator.
383  *
384  * \return evaluator
385  */
386  const JEvaluator_t& getEvaluator() const
387  {
388  return getValue;
389  }
390 
391 
392  protected:
393  JEvaluator_t getValue;
394  };
395 }
396 
397 #endif
Interface for object iteration with rewinding.
void configure(const JMultipleFileScanner_t &file_list)
Configure.
iterator(JTreeScannerInterface *__p, const counter_type __i)
Constructor.
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.
Definition: JCounter.hh:24
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.
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().
JRewindableObjectIterator< JClass_t >::pointer_type pointer_type
reverse_iterator(JTreeScannerInterface *__p, const counter_type __i)
Constructor.
Template definition of auxiliary base class for comparison of data structures.
Definition: JEquals.hh:24
virtual bool equals(const iterator &cursor) const
Equality of iterator.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
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.
virtual bool equals(const reverse_iterator &cursor) const
Equality of iterator.
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.