Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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"
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 */
18namespace JSUPPORT {}
19namespace JPP { using namespace JSUPPORT; }
20
21namespace JSUPPORT {
22
23 using JLANG::JTypeList;
24 using JLANG::JNullType;
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
38 typedef typename JFileScanner_t<JNullType>::input_type input_type;
40
41
42 /**
43 * Default constructor.
44 */
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
100 typedef typename JFileScanner_t<JNullType>::input_type input_type;
102
103 using JParallelFileScanner<JHead_t, JFileScanner_t>::getFilename;
104 using JParallelFileScanner<JHead_t, JFileScanner_t>::getCounter;
105
106
107 /**
108 * Default constructor.
109 */
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 */
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 */
159
160
161 /**
162 * Get next element.
163 *
164 * \return multi-pointer to elements
165 */
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.
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 skip_type skip(const skip_type ns)
Skip items.
virtual void set(JClass_t *p) override
Set pointer.
Definition JPointer.hh:75
virtual void rewind()=0
Rewind.
JParallelFileScanner< JHead_t, JFileScanner_t >::input_type input_type
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
JParallelFileScanner< JHead_t, JFileScanner_t >::multi_pointer_type multi_pointer_type
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
virtual bool hasNext() override
Check availability of next element.
virtual const multi_pointer_type & next() override
Get 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.
JParallelFileScanner(const input_type &input)
Constructor.
JParallelFileScanner(const input_type &input, const JLimit &limit)
Constructor.
JFileScanner_t< JNullType >::input_type input_type
JParallelFileScanner()
Default constructor.
Object reading from a list of files.
counter_type getCounter() const
Get counter.
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
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).
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.
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