ProductBase.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood 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 
60 namespace rack {
61 
62 using namespace drain::image;
63 
64 
66 
81 //template <class TS, class TD>
82 class ProductBase : public ProductConf, public drain::BeanLike {
83 
84 protected:
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 
104 public:
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
135  const drain::ReferenceMap & getAllowedEncoding() const { return allowedEncoding; };
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 
189 protected:
190 
192  static
193  void setODIMspecials(ODIM & productODIM);
194 
196 
206 
207 
208 };
209 
210 
211 
212 inline
213 std::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
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
Definition: ReferenceMap.h:207
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:103
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
const DataSelector & getDataSelector() const
Returns the data selector of this operator.
Definition: ProductBase.h:123
DataSelector & getDataSelector()
Returns the data selector of this operator.
Definition: ProductBase.h:127
void storeLastArguments(const std::string &p) override
Called after setParameters()
Definition: ProductBase.h:98
void setDataSelector(const DataSelector &selector)
Copies the conditions of another selector.
Definition: ProductBase.h:119
const drain::ReferenceMap & getAllowedEncoding() const
Returns a map of encoding parameters that can be changed by the user.
Definition: ProductBase.h:135
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
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:63
Namespace for images and image processing tools.
Definition: AccumulationArray.cpp:45
Definition: DataSelector.cpp:1277
Definition: DataSelector.cpp:44