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,
106class DataSelector: public drain::BeanLike {
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
150 DataSelector(const DataSelector & selector);
151
152 virtual ~DataSelector();
153
154
156 // * - \c index - integer value, only changing the \c index member. ???
166 // Experimental. Raise to beanlike?
168
173 inline
174 bool consumeParameters(std::string & args){
175 if (args.empty()){
176 return false;
177 }
178 else {
179 setParameters(args);
180 args.clear();
181 return true;
182 }
183 }
184
185 template<typename ... TT>
186 inline
187 void setPathMatcher(TT... args){
188 pathMatcher.set(args...);
189 }
190
191 inline
192 const ODIMPathMatcher & getPathMatcher() const {
193 return pathMatcher;
194 }
195
197 inline
199 return pathMatcher.trimHead(true);
200 }
201
203
216 void setQuantities(const std::string & s);
217
218 // void setQuantityRegExp(const std::string & s); // todo: rename (here only) quantities?
219
220 inline
221 bool quantityIsSet() const {
222 return quantitySelector.isSet(); // || qualitySelector.isSet();
223 }
224
226
230 inline
231 const std::string & getQuantity() const {
232 return quantities;
233 }
234
235 inline
236 const QuantitySelector & getQuantitySelector() const {
237 return quantitySelector;
238 }
239
240
241 inline
242 void setMaxCount(unsigned int i){
243 count = i;
244 }
245
246 inline
247 unsigned int getMaxCount() const {
248 return count;
249 }
250
251
252 inline
253 void setPrf(const std::string & s){
254 this->prf = s;
255 this->prfSelector.set(s);
256 }
257
258 inline
259 void setPrf(Prf prf){
260 this->prfSelector.set(prf);
261 this->prf = this->prfSelector.str();
262 //this->updateBean();
263 }
264
265 template<typename ... TT>
266 inline
267 void setOrder(const TT &... args) {
268 this->order.set(args...);
269 }
270
271 inline
272 const DataOrder & getOrder() const {
273 return order;
274 }
275
276
278
281 // void selectPaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer) const;
282
283
284
286
289 void reset(); // bool flexible = true "inclusive"
290
291
293 // TODO: perhaps semantics unclear. Consider separating to updateParameters/ deriveImplicitParameters etc.
304
324 void getPaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer) const;
325
326
328
333 bool getPath(const Hi5Tree & src, ODIMPath & path) const;
334
335
336
339
341 bool getLastPath(const Hi5Tree & src, ODIMPath & path, ODIMPathElem::group_t group = ODIMPathElem::DATA ) const;
342
344 bool getNextPath(const Hi5Tree & src, ODIMPath & path, ODIMPathElem::group_t group = ODIMPathElem::DATA ) const;
345
346
347
348
350
358 static
359 void swapData(Hi5Tree & src,const ODIMPathElem &srcElem, Hi5Tree & dst);
360
362 static
363 void swapData(Hi5Tree & srcGroup, Hi5Tree & dst, ODIMPathElem::group_t groupType);
364
365 // TODO add filter, allowing ODIMPathElem::group_t == QUALITY
366 static
367 void getTimeMap(const Hi5Tree & srcRoot, ODIMPathElemMap & m);
368
370
375
376protected:
377
379
383 virtual
384 void updateBean() const override;
385
386
388
391 //mutable
392 std::string path; // temporary!
393
394 mutable
395 ODIMPathMatcher pathMatcher;
396
398 mutable
399 std::string quantities;
400
401 mutable
402 QuantitySelector quantitySelector;
403
404 //mutable
405 //drain::KeySelector qualitySelector;
406
407
409 unsigned int count;
410
411
414
415 mutable DataOrder order;
416
418 std::string prf;
419
420 mutable
422
425
427
436 void updateQuantities() const; // todo: rename (here only) quantities?
437 // void updateQuantities(const std::string & separators = ",") const ;
438
440 void init();
441
442
444
448 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;
449
450
452 void prunePaths(const Hi5Tree & src, std::list<ODIMPath> & pathContainer) const;
453
454};
455
456std::ostream & operator<<(std::ostream & ostr, const DataSelector &selector);
457
458
459
460// Experimental
462class DatasetSelector : public DataSelector {
463
464public:
465
467 drain::Logger mout(__FILE__, __FUNCTION__);
468 parameters.delink("path");
469 mout.experimental<LOG_NOTICE>("not resetting DATASET" );
470 //pathMatcher.setElems(ODIMPathElem::DATASET);
471 }
472
473};
474
475// Experimental
476/*
477class ImageSelector : public DataSelector {
478
479public:
480
481 ImageSelector() : DataSelector(ODIMPathElem::DATA | ODIMPathElem::QUALITY) {
482 parameters.link("path", dummy);
483 //parameters.delink("path");
484 // pathMatcher.setElems(ODIMPathElem::DATASET);
485 }
486
487
488 // Convert path and quantity strings to pathMatcher and quantity regexps, respectively.
489 virtual
490 void updateBean();
491
492private:
493
494 std::string dummy;
495
496};
497*/
498
499} // rack::
500
501
502DRAIN_ENUM_DICT(rack::DataOrder::Crit);
503DRAIN_ENUM_DICT(rack::DataOrder::Oper);
504DRAIN_ENUM_DICT(rack::DataSelector::Prf);
505
506// DRAIN_TYPENAME(rack::DataSelector);
507
508namespace drain {
509
510DRAIN_TYPENAME(rack::DataSelector);
511
512
513}
514
515#endif /* DATASELECTOR_H_ */
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:58
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition BeanLike.h:142
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:313
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:358
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:112
void init()
Sets the default values and sets references.
Definition DataSelector.cpp:135
Prf
Pulse repetition frequency mode.
Definition DataSelector.h:118
unsigned int count
The maximum length of the list of matching keys.
Definition DataSelector.h:396
virtual void updateBean() const
Updates member objects with their corresponding variable values .
Definition DataSelector.cpp:184
DataSelector(const ODIMPathElem &elem, const T &... args)
Inits pathmatcher.
Definition DataSelector.h:131
static void swapData(Hi5Tree &src, const ODIMPathElem &srcElem, Hi5Tree &dst)
Swap branches such that dst gets a /dataset or /data with a new index.
void setQuantities(const std::string &s)
Sets basic quantities and quality quantities. These sets are separated by '/'.
std::string prf
Reject or accept VRAD(VH)
Definition DataSelector.h:405
std::string path
Regular expression of accepted paths, for example ".*‍/data$". Deprecated.
Definition DataSelector.h:379
DataSelector(ODIMPathElem::group_t e, const T &... args)
Constructor initializing path matcher from group type(s).
Definition DataSelector.h:141
static void swapData(Hi5Tree &srcGroup, Hi5Tree &dst, ODIMPathElem::group_t groupType)
Like swapData(Hi5Tree & src,const ODIMPathElem &srcElem, Hi5Tree & dst), but src already at the level...
void updateQuantities() const
Continue path matching started with getMainPaths()
void getPaths(const Hi5Tree &src, std::list< ODIMPath > &pathContainer) const
Sets given parameters and implicitly determines missing parameters.
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.
bool consumeParameters(std::string &args)
Sets parameters in predefined order or sets specified parameters. (Python style calling alternatives....
Definition DataSelector.h:174
void trimPathMatcher()
"Drop leading slashes", ie. remove leading empty elements.
Definition DataSelector.h:198
virtual void updateBean() const override
Traverses the parameters and updates the corresponding member objects.
void ensureDataGroup()
In path, ensure trailing DATA or QUANTITY element.
drain::Range< int > timespan
Time in seconds, compared to nominal time.
Definition DataSelector.h:411
DataSelector(const std::string &parameters="")
Default constructor. Optionally takes a parameter string.
DataSelector(const DataSelector &selector)
Copy constructor.
bool getPath(const Hi5Tree &src, ODIMPath &path) const
Returns the first path encountered with selector attributes and given groupFilter .
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 .
void reset()
Collect paths with all the criteria: path, elevation(range), PRF, quantity...
const std::string & getQuantity() const
Retrieve quantity list and regular expression, if defined.
Definition DataSelector.h:231
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.
drain::Range< double > elangle
The minimum and maximum elevation angle (applicable with volume scan data only).
Definition DataSelector.h:400
bool collectPaths(const Hi5Tree &src, std::list< ODIMPath > &pathContainer, const ODIMPath &basepath=ODIMPath(), const std::string &parentQuantity="") const
Collect paths (only) with criteria: path, elevation(range), PRF, quantity.
Definition DataSelector.cpp:375
std::string quantities
Comma-separated list of conventional quantities, optionally followed by '/', and quality quantities.
Definition DataSelector.h:386
DOC: Add class description.
Definition DataSelector.h:452
DOC: Add class description.
Definition ODIMPath.h:82
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 DataSelector.cpp:1277
Definition DataSelector.cpp:44
std::map< std::string, ODIMPathElem > ODIMPathElemMap
Definition ODIMPath.h:474
DOC: Add class description.
Definition DataSelector.h:58
void set(const std::string s)
Expects <crit>[:<oper>].
Definition DataSelector.h:79