Loading...
Searching...
No Matches
DataSelector.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25 */
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31
32#ifndef RACK_DATASELECTOR
33#define RACK_DATASELECTOR
34
35#include <data/QuantitySelector.h>
36#include <list>
37
38#include <drain/util/BeanLike.h>
39#include <drain/util/Range.h>
40#include <drain/util/ReferenceMap.h>
41//#include <drain/util/Variable.h>
42
43#include "ODIM.h"
44#include "ODIMPathTools.h"
45#include "ODIMPathMatcher.h"
46
47
48namespace rack {
49
50
52struct DataOrder { //: public drain::BeanLike {
53
54 enum Crit {DATA, ELANGLE, TIME}; // ALTITUDE
55 enum Oper {MIN, MAX};
56
57 const char separator = ':';
58
60 CritFlagger criterion;
61
63 OperFlagger operation;
64
65 template<typename ... TT>
66 void set(Crit crit, const TT &... args) {
67 criterion = crit;
68 set(args...);
69 }
70
71 template<typename ... TT>
72 void set(Oper oper, const TT &... args) {
73 operation = oper;
74 set(args...);
75 }
76
78 inline
79 void set(const std::string s) {
80 std::string s1, s2;
81 drain::StringTools::split2(s, s1, s2, separator);
82 criterion.set(s1);
83 operation.set(s2);
84 set();
85 };
86
87 void set(){
88 str = criterion.str() + separator + operation.str();
89 }
90
91 std::string str;
92
93};
94
95
96inline
97std::ostream & operator<<(std::ostream & ostr, const DataOrder & order){
98 ostr << order.str;
99 return ostr;
100}
101
103 // QuantitySelector,
107public:
108
109 friend class drain::ReferenceMap;
110
112 enum Prf {SINGLE=1, DOUBLE=2, ANY=3};
113
114 // TODO: string => ODIMPath
116 DataSelector(const std::string & path, const std::string & quantity,
117 unsigned int count = 1000, drain::Range<double> elangle = {-90.0, 90.0},
118 DataSelector::Prf prf=Prf::ANY //int dualPRF = 0,
119 //drain::Range<int> timespan={0,0}
120 );
121 // double elangleMin = -90.0, double elangleMax = 90.0);
122
124 DataSelector(const std::string & parameters = "");
125
127 // DataSelector(ODIMPathElem::group_t e, ODIMPathElem::group_t e2=ODIMPathElem::ROOT, ODIMPathElem::group_t e3=ODIMPathElem::ROOT);
128
130 template<typename ... T>
131 DataSelector(const ODIMPathElem & elem, const T &... args): BeanLike(__FUNCTION__){ //, orderFlags(orderDict,':') {
132 init();
133 //pathMatcher.setElems(elem, rest...);
134 pathMatcher.set(elem, args...);
135 updateBean();
136 }
137
138 // Either this or previous is unneeded?
140 template<typename ... T>
141 DataSelector(ODIMPathElem::group_t e, const T &... args): BeanLike(__FUNCTION__){ // , orderFlags(orderDict,':') {
142 init();
143 //pathMatcher.setElems(e, rest...);
144 pathMatcher.set(e, args...);
145 updateBean();
146 }
147
148
151
152 virtual ~DataSelector();
153
154
156 // * - \c index - integer value, only changing the \c index member. ???
165 // Experimental. Raise to beanlike?
167
172 inline
173 bool consumeParameters(std::string & args){
174 if (args.empty()){
175 return false;
176 }
177 else {
178 setParameters(args);
179 args.clear();
180 return true;
181 }
182 }
183
184 template<typename ... TT>
185 inline
186 void setPathMatcher(TT... args){
187 pathMatcher.set(args...);
188 }
189
190 inline
191 const ODIMPathMatcher & getPathMatcher() const {
192 return pathMatcher;
193 }
194
196 inline
198 return pathMatcher.trimHead(true);
199 }
200
202
215 void setQuantities(const std::string & s);
216
217 // void setQuantityRegExp(const std::string & s); // todo: rename (here only) quantities?
218
219 inline
220 bool quantityIsSet() const {
221 return quantitySelector.isSet(); // || qualitySelector.isSet();
222 }
223
225
229 inline
230 const std::string & getQuantity() const {
231 return quantities;
232 }
233
234 inline
235 const QuantitySelector & getQuantitySelector() const {
236 return quantitySelector;
237 }
238
239
240 inline
241 void setMaxCount(unsigned int i){
242 count = i;
243 }
244
245 inline
246 unsigned int getMaxCount() const {
247 return count;
248 }
249
250
251 inline
252 void setPrf(const std::string & s){
253 this->prf = s;
254 this->prfSelector.set(s);
255 }
256
257 inline
258 void setPrf(Prf prf){
259 this->prfSelector.set(prf);
260 this->prf = this->prfSelector.str();
261 //this->updateBean();
262 }
263
264 template<typename ... TT>
265 inline
266 void setOrder(const TT &... args) {
267 this->order.set(args...);
268 }
269
270 inline
271 const DataOrder & getOrder() const {
272 return order;
273 }
274
275
277
280 // void selectPaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer) const;
281
282
283
285
288 void reset(); // bool flexible = true "inclusive"
289
290
292 // TODO: perhaps semantics unclear. Consider separating to updateParameters/ deriveImplicitParameters etc.
303
317 void getPaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer) const;
318
319
321
326 bool getPath(const Hi5Tree & src, ODIMPath & path) const;
327
328
329
332
334 bool getLastPath(const Hi5Tree & src, ODIMPath & path, ODIMPathElem::group_t group = ODIMPathElem::DATA ) const;
335
337 bool getNextPath(const Hi5Tree & src, ODIMPath & path, ODIMPathElem::group_t group = ODIMPathElem::DATA ) const;
338
339
340
341
343
351 static
352 void swapData(Hi5Tree & src,const ODIMPathElem &srcElem, Hi5Tree & dst);
353
355 static
356 void swapData(Hi5Tree & srcGroup, Hi5Tree & dst, ODIMPathElem::group_t groupType);
357
358 // TODO add filter, allowing ODIMPathElem::group_t == QUALITY
359 static
360 void getTimeMap(const Hi5Tree & srcRoot, ODIMPathElemMap & m);
361
363
367 void ensureDataGroup();
368
369protected:
370
372
376 virtual
377 void updateBean() const override;
378
379
381
384 //mutable
385 std::string path; // temporary!
386
387 mutable
388 ODIMPathMatcher pathMatcher;
389
391 mutable
392 std::string quantities;
393
394 mutable
395 QuantitySelector quantitySelector;
396
397 //mutable
398 //drain::KeySelector qualitySelector;
399
400
402 unsigned int count;
403
404
407
408 mutable DataOrder order;
409
411 std::string prf;
412
413 mutable
415
418
420
426 // template <class T>
427 // bool getSubPathsFOO(const Hi5Tree & src, T & pathContainer, const ODIMPath & path) const;
428
429 void updateQuantities() const; // todo: rename (here only) quantities?
430 // void updateQuantities(const std::string & separators = ",") const ;
431
433 void init();
434
435
437
441 bool collectPaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer, const ODIMPath & basepath = ODIMPath(), const std::string & parentQuantity="", ODIMPathElem::group_t filter = ODIMPathElem::ALL_GROUPS) const;
442
443
445 void prunePaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer) const;
446
447};
448
449std::ostream & operator<<(std::ostream & ostr, const DataSelector &selector);
450
451
452
453// Experimental
456
457public:
458
461 parameters.delink("path");
462 mout.experimental<LOG_NOTICE>("not resetting DATASET" );
463 //pathMatcher.setElems(ODIMPathElem::DATASET);
464 }
465
466};
467
468// Experimental
469/*
470class ImageSelector : public DataSelector {
471
472public:
473
474 ImageSelector() : DataSelector(ODIMPathElem::DATA | ODIMPathElem::QUALITY) {
475 parameters.link("path", dummy);
476 //parameters.delink("path");
477 // pathMatcher.setElems(ODIMPathElem::DATASET);
478 }
479
480
481 // Convert path and quantity strings to pathMatcher and quantity regexps, respectively.
482 virtual
483 void updateBean();
484
485private:
486
487 std::string dummy;
488
489};
490*/
491
492} // rack::
493
494
495DRAIN_ENUM_DICT(rack::DataOrder::Crit);
496DRAIN_ENUM_DICT(rack::DataOrder::Oper);
497DRAIN_ENUM_DICT(rack::DataSelector::Prf);
498
499// DRAIN_TYPENAME(rack::DataSelector);
500
501namespace drain {
502
503DRAIN_TYPENAME(rack::DataSelector);
504
505
506}
507
508#endif /* DATASELECTOR_H_ */
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:58
map_t parameters
Parameters (name -> linked variable), typically linked to member variables of the derived class.
Definition BeanLike.h:313
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition BeanLike.h:157
Flagger accepting values of enum type E.
Definition EnumFlagger.h:56
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Definition Path.h:135
void trimHead(bool COMPLETE=false)
Removes leading empty elements. The resulting string presentation will not start with the separator.
Definition Path.h:373
Definition Range.h:52
Definition ReferenceMap.h:215
void delink(const std::string &key)
Removes an entry from the map.
Definition ReferenceMap.h:355
virtual const key_t & str() const override
String corresponding the current value. Returns empty, if not found.
Definition Flags.h:155
static bool split2(const std::string &s, T1 &first, T2 &second, const C &separators, const std::string &trimChars=" \t\n")
Splits and trims a given std::string to a std Sequence.
Tool for selecting datasets based on paths, quantities and min/max elevations.
Definition DataSelector.h:106
void init()
Sets the default values and sets references.
Definition DataSelector.cpp:140
Prf
Pulse repetition frequency mode.
Definition DataSelector.h:112
unsigned int count
The maximum length of the list of matching keys.
Definition DataSelector.h:402
DataSelector(const ODIMPathElem &elem, const T &... args)
Inits pathmatcher.
Definition DataSelector.h:131
void setQuantities(const std::string &s)
Sets basic quantities and quality quantities. These sets are separated by '/'.
Definition DataSelector.cpp:299
std::string prf
Reject or accept VRAD(VH)
Definition DataSelector.h:411
std::string path
Regular expression of accepted paths, for example ".*‍/data$". Deprecated.
Definition DataSelector.h:385
DataSelector(ODIMPathElem::group_t e, const T &... args)
Constructor initializing path matcher from group type(s).
Definition DataSelector.h:141
void updateQuantities() const
Continue path matching started with getMainPaths()
Definition DataSelector.cpp:307
void getPaths(const Hi5Tree &src, std::list< ODIMPath > &pathContainer) const
Sets given parameters and implicitly determines missing parameters.
Definition DataSelector.cpp:725
bool getNextPath(const Hi5Tree &src, ODIMPath &path, ODIMPathElem::group_t group=ODIMPathElem::DATA) const
Returns the a path with index one greater than the retrieved last path.
Definition DataSelector.cpp:836
bool collectPaths(const Hi5Tree &src, std::list< ODIMPath > &pathContainer, const ODIMPath &basepath=ODIMPath(), const std::string &parentQuantity="", ODIMPathElem::group_t filter=ODIMPathElem::ALL_GROUPS) const
Collect paths (only) with criteria: path, elevation(range), PRF, quantity.
Definition DataSelector.cpp:339
virtual void updateBean() const override
Traverses the parameters and updates the corresponding member objects.
Definition DataSelector.cpp:199
bool consumeParameters(std::string &args)
Sets parameters in predefined order or sets specified parameters. (Python style calling alternatives....
Definition DataSelector.h:173
static void swapData(Hi5Tree &src, const ODIMPathElem &srcElem, Hi5Tree &dst)
Swap branches such that dst gets a /dataset or /data with a new index.
Definition DataSelector.cpp:862
void trimPathMatcher()
"Drop leading slashes", ie. remove leading empty elements.
Definition DataSelector.h:197
void ensureDataGroup()
In path, ensure trailing DATA or QUANTITY element.
Definition DataSelector.cpp:245
bool getPath(const Hi5Tree &src, ODIMPath &path) const
Returns the first path encountered with selector attributes and given groupFilter .
Definition DataSelector.cpp:738
bool getLastPath(const Hi5Tree &src, ODIMPath &path, ODIMPathElem::group_t group=ODIMPathElem::DATA) const
Returns the last path encountered with selector attributes and given groupFilter .
Definition DataSelector.cpp:795
void reset()
Collect paths with all the criteria: path, elevation(range), PRF, quantity...
Definition DataSelector.cpp:166
const std::string & getQuantity() const
Retrieve quantity list and regular expression, if defined.
Definition DataSelector.h:230
void prunePaths(const Hi5Tree &src, std::list< ODIMPath > &pathContainer) const
Use DataOrder::criterion DATA , TIME or ELANGLE and #DataOrder::order MIN or MAX to sort paths.
Definition DataSelector.cpp:562
drain::Range< int > timespan
Time in seconds, compared to nominal time.
Definition DataSelector.h:417
drain::Range< double > elangle
The minimum and maximum elevation angle (applicable with volume scan data only).
Definition DataSelector.h:406
std::string quantities
Comma-separated list of conventional quantities, optionally followed by '/', and quality quantities.
Definition DataSelector.h:392
A map of radar data, indexed by quantity code (DBZH, VRAD, etc).
Definition Data.h:1293
DOC: Add class description.
Definition DataSelector.h:455
DOC: Add class description.
Definition ODIMPath.h:82
static const group_t DATASET
First level group, /dataset + digit .
Definition ODIMPath.h:106
unsigned int group_t
In H5, "groups" correspond to directories or folders in file system.
Definition ODIMPath.h:92
static const group_t ALL_GROUPS
User defined group, name stored as a separate string. Index allowed, but only catenated in the string...
Definition ODIMPath.h:140
static const group_t DATA
Second level group, /data + digit .
Definition ODIMPath.h:109
Structure for testing if a path matches a given sequence of path elements.
Definition ODIMPathMatcher.h:190
Definition Data.h:1473
Definition AltitudeOp.cpp:42
std::map< std::string, ODIMPathElem > ODIMPathElemMap
Definition ODIMPath.h:474
std::ostream & operator<<(std::ostream &ostr, const PlainData< DT > &d)
Definition Data.h:631
DOC: Add class description.
Definition DataSelector.h:52
void set(const std::string s)
Expects crit[:oper].
Definition DataSelector.h:79