Loading...
Searching...
No Matches
ProductBase.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 * ProductOp.h
33 *
34 * Created on: Mar 7, 2011
35 * Author: mpeura
36 */
37
38#ifndef RACK_BASE
39#define RACK_BASE "ProductBase"
40
41#include <drain/Log.h>
42#include <stdexcept>
43#include <iostream>
44#include <list>
45#include <map>
46#include <set>
47#include <string>
48
49#include <drain/RegExp.h>
50#include <drain/util/SmartMap.h>
51#include <drain/util/TreeOrdered.h>
52
53#include "hi5/Hi5.h"
54#include "data/Data.h"
55#include "data/DataSelector.h"
56#include "data/ODIM.h"
57#include "data/ODIMPath.h"
58#include "data/ProductConf.h"
59
60namespace rack {
61
62using namespace drain::image;
63
64
66
81//template <class TS, class TD>
82class ProductBase : public ProductConf, public drain::BeanLike {
83
84protected:
85
87 inline
88 ProductBase(const std::string &name, const std::string & description) : drain::BeanLike(name, description){
89 dataSelector.setPathMatcher(ODIMPathElem::DATASET);
90 // dataSelector.updateBean();
91 }
92
93 inline
94 ProductBase(const ProductBase & product) : ProductConf(product), drain::BeanLike(product){
95 }
96
97 inline
98 void storeLastArguments(const std::string & p) override {
99 lastArguments = p;
100 };
101
102 std::string lastArguments;
103
104public:
105
106 inline
107 const std::string & getLastArguments() const{
108 return lastArguments;
109 };
110
111
113 virtual
115
116
118 inline
119 void setDataSelector(const DataSelector & selector){ dataSelector.setParameters(selector.getParameters()); };
120
122 inline
123 const DataSelector & getDataSelector() const { return dataSelector; };
124
126 inline
127 DataSelector & getDataSelector(){ return dataSelector; };
128
130 void help(std::ostream &ostr = std::cout, bool showDescription = true) const;
131
132
134 inline
136
137
139
143 virtual
144 inline
145 void setEncodingRequest(const std::string &p) {
146
147 drain::Logger mout(__FILE__, __FUNCTION__); //REPL name+"(ProductOp)", __FUNCTION__);
148
149 try {
150 mout.debug2("Checking if these are allowed" );
151 allowedEncoding.setValues(p); // may throw?
152 }
153 catch (std::exception & e) {
154 drain::Logger mout(__FILE__, __FUNCTION__);
155 mout.warn(" unsupported parameters in: '" , p , "', use: " , allowedEncoding.getKeys() );
156 return;
157 }
158
159 // assign.
160 targetEncoding = p;
161 }
162
163 // under construction
164 void setAllowedEncoding(const std::string & keys);
165
167
171 static
172 void completeEncoding(ODIM & productODIM, const std::string & targetEncoding);
173
174
175
177
182 static
183 void applyODIM(ODIM & productODIM, const ODIM & srcODIM, bool applyDefaults = false);
184
185
186 static
187 void setRackVersion(drain::VariableMap & metadata);
188
189protected:
190
192 static
193 void setODIMspecials(ODIM & productODIM);
194
196
206
207
208};
209
210
211
212inline
213std::ostream & operator<<(std::ostream & ostr, const rack::ProductBase &op){
214 op.help(ostr); // todo: name & params only
215 return ostr;
216}
217
218
219
220
221} // namespace rack
222
223
224#endif // RACK_PRODUCT_O
Something which has a name, a description and possibly some parameters of varying type.
Definition BeanLike.h:60
void setParameters(std::initializer_list< Variable::init_pair_t > args)
Grants access to (if above hidden)
Definition BeanLike.h:144
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:676
Definition ReferenceMap.h:207
void setValues(const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
Sets values. If strictness==STRICTLY_CLOSED, throws exception if tries to assign a non-existing entry...
Definition SmartMap.h:311
A map of Variables.
Definition VariableMap.h:61
Tool for selecting datasets based on paths, quantities and min/max elevations.
Definition DataSelector.h:112
static const group_t DATASET
First level group, /dataset + digit .
Definition ODIMPath.h:106
ODIM metadata (quantity, gain, offset, undetect, nodata, date, time)
Definition ODIM.h:79
Base class for radar data processors. Input can be in polar or Cartesian coordinates.
Definition ProductBase.h:82
virtual ~ProductBase()
Destructor.
Definition ProductBase.h:114
void help(std::ostream &ostr=std::cout, bool showDescription=true) const
Dumps the help of this operator.
Definition ProductBase.cpp:62
static void setODIMspecials(ODIM &productODIM)
Sets target encoding.
Definition ProductBase.cpp:264
const drain::ReferenceMap & getAllowedEncoding() const
Returns a map of encoding parameters that can be changed by the user.
Definition ProductBase.h:135
void storeLastArguments(const std::string &p) override
Called after setParameters()
Definition ProductBase.h:98
static void applyODIM(ODIM &productODIM, const ODIM &srcODIM, bool applyDefaults=false)
Sets target quantity and encoding, if unset. If input odim.
Definition ProductBase.cpp:117
DataSelector & getDataSelector()
Returns the data selector of this operator.
Definition ProductBase.h:127
static void completeEncoding(ODIM &productODIM, const std::string &targetEncoding)
Modifies encoding. If type is changed, resets scaling first.
Definition ProductBase.cpp:183
void setDataSelector(const DataSelector &selector)
Copies the conditions of another selector.
Definition ProductBase.h:119
virtual void setEncodingRequest(const std::string &p)
Set encoding parameters for the result: type,gain,offset,undetect,nodata.
Definition ProductBase.h:145
drain::ReferenceMap allowedEncoding
Defines which encoding parameters can be changed by the user from command line.
Definition ProductBase.h:205
const DataSelector & getDataSelector() const
Returns the data selector of this operator.
Definition ProductBase.h:123
ProductBase(const std::string &name, const std::string &description)
Default constructor.
Definition ProductBase.h:88
Shared properties for meteorological products and Cartesian products (composites and single-radar ima...
Definition ProductConf.h:64
std::string targetEncoding
How the (main) output is encoded.
Definition ProductConf.h:83
Namespace for images and image processing tools.
Definition AccumulationArray.cpp:45
Definition DataSelector.cpp:1277
Definition DataSelector.cpp:44