Jpp  19.1.0
the software that should make you happy
JParallelFileScanner.hh
Go to the documentation of this file.
1 #ifndef __JSUPPORT__JPARALLELFILESCANNER__
2 #define __JSUPPORT__JPARALLELFILESCANNER__
3 
4 #include "JLang/JTypeList.hh"
5 #include "JLang/JNullType.hh"
6 #include "JLang/JMultiPointer.hh"
7 #include "JLang/JException.hh"
8 
11 
12 
13 /**
14  * \file
15  * Parallel scanning of objects from a single file or multiple files according a format that follows from the file name extension.
16  * \author mdejong
17  */
18 namespace JSUPPORT {}
19 namespace JPP { using namespace JSUPPORT; }
20 
21 namespace JSUPPORT {
22 
23  using JLANG::JTypeList;
24  using JLANG::JNullType;
26  using JLANG::JException;
27 
28 
29  /**
30  * General purpose class for parallel reading of objects from a single file or multiple files.
31  */
32  template<class T, template<class> class JFileScanner_t = JSingleFileScanner>
34  public JFileScanner_t<T>
35  {
36  public:
37 
40 
41 
42  /**
43  * Default constructor.
44  */
46  {}
47 
48 
49  /**
50  * Constructor.
51  *
52  * \param input input
53  */
55  {
56  this->configure(input, JLimit());
57  }
58 
59 
60  /**
61  * Constructor.
62  *
63  * \param input input
64  * \param limit limit
65  */
66  JParallelFileScanner(const input_type& input, const JLimit& limit)
67  {
68  this->configure(input, limit);
69  }
70 
71 
72  /**
73  * Get next element.
74  *
75  * \return multi-pointer to element
76  */
77  virtual const multi_pointer_type& next() override
78  {
79  ps.set(JFileScanner_t<T>::next());
80 
81  return ps;
82  }
83 
84  private:
86  using JFileScanner_t<T>::next;
87  };
88 
89 
90  /**
91  * Template specialisation of JParallelFileScanner for multiple data types.
92  */
93  template<class JHead_t, class JTail_t, template<class> class JFileScanner_t>
94  class JParallelFileScanner<JTypeList<JHead_t, JTail_t>, JFileScanner_t> :
95  public JParallelFileScanner<JHead_t, JFileScanner_t>,
96  public JParallelFileScanner<JTail_t, JFileScanner_t>
97  {
98  public:
99 
102 
105 
106 
107  /**
108  * Default constructor.
109  */
111  {}
112 
113 
114  /**
115  * Constructor.
116  *
117  * \param input input
118  */
120  {
121  this->configure(input, JLimit());
122  }
123 
124 
125  /**
126  * Constructor.
127  *
128  * \param input input
129  * \param limit limit
130  */
131  JParallelFileScanner(const input_type& input, const JLimit& limit)
132  {
133  this->configure(input, limit);
134  }
135 
136 
137  /**
138  * Rewind.\n
139  * This method rewinds the JParallelFileScanner for each data type.
140  */
141  virtual void rewind() override
142  {
145  }
146 
147 
148  /**
149  * Check availability of next element.\n
150  * Note that the availability of the next element is tested for each data type.
151  *
152  * \return true if each iteration has more elements; else false
153  */
154  virtual bool hasNext() override
155  {
158  }
159 
160 
161  /**
162  * Get next element.
163  *
164  * \return multi-pointer to elements
165  */
166  virtual const multi_pointer_type& next() override
167  {
170 
171  return ps;
172  }
173 
174 
175  /**
176  * Skip items.
177  *
178  * \param ns number of items to skip
179  * \return number of items skipped
180  */
181  virtual skip_type skip(const skip_type ns) override
182  {
185 
186  if (n1 == n2)
187  return n1;
188  else
189  THROW(JException, "JParallelFileScanner<>::skip(): inconsistency.");
190  }
191 
192  private:
194  };
195 
196 
197  /**
198  * Terminator class of recursive JParallelFileScanner class.
199  */
200  template<class JHead_t, template<class> class JFileScanner_t>
201  class JParallelFileScanner<JTypeList<JHead_t, JNullType>, JFileScanner_t> :
202  public JParallelFileScanner<JHead_t, JFileScanner_t>
203  {
204  public:
205 
208 
209 
210  /**
211  * Default constructor.
212  */
214  JParallelFileScanner<JHead_t, JFileScanner_t>()
215  {}
216 
217 
218  /**
219  * Constructor.
220  *
221  * \param input input
222  */
224  {
225  this->configure(input, JLimit());
226  }
227 
228 
229  /**
230  * Constructor.
231  *
232  * \param input input
233  * \param limit limit
234  */
235  JParallelFileScanner(const input_type& input, const JLimit& limit)
236  {
237  this->configure(input, limit);
238  }
239  };
240 }
241 
242 #endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:712
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Scanning of objects from a single file according a format that follows from the extension of each fil...
General exception.
Definition: JException.hh:24
virtual void set(JClass_t *p) override
Set pointer.
Definition: JPointer.hh:75
JParallelFileScanner< JHead_t, JFileScanner_t >::multi_pointer_type multi_pointer_type
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
JParallelFileScanner< JHead_t, JFileScanner_t >::input_type input_type
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
virtual const multi_pointer_type & next() override
Get next element.
virtual bool hasNext() override
Check availability of next element.
General purpose class for parallel reading of objects from a single file or multiple files.
virtual const multi_pointer_type & next() override
Get next element.
JFileScanner_t< JNullType >::input_type input_type
JParallelFileScanner(const input_type &input)
Constructor.
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
JParallelFileScanner()
Default constructor.
Object reading from a list of files.
virtual void rewind() override
Rewind.
virtual skip_type skip(const skip_type ns) override
Skip items.
unsigned int skip_type
Type definition for number of objects to skip.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JLANG::JSTDObjectReader< const event_type > input_type
Definition: JPerth.cc:83
std::vector< size_t > ns
Support classes and methods for experiment specific I/O.
Definition: JDataWriter.cc:38
void configure(const T &value, const JAbstractCollection< JAbscissa_t > &bounds, JBool< false > option)
Configuration of value.
Implementation of multiple pointers for multiple data types.
General purpose class for multiple pointers.
void reset(const JMultiPointer< JClass_t > &pointer)
Reset multi-pointer.
Auxiliary class for no type definition.
Definition: JNullType.hh:19
Type list.
Definition: JTypeList.hh:23
Auxiliary class for defining the range of iterations of objects.
Definition: JLimit.hh:45