resources.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 // # pragma once
33 #ifndef RACK_RESOURCES_H_
34 #define RACK_RESOURCES_H_
35 
36 #include <string>
37 
38 #include <drain/RegExp.h>
39 #include <drain/image/Image.h>
40 #include <drain/imageops/ImageModifierPack.h>
41 #include <drain/imageops/PaletteOp.h>
42 #include <drain/prog/CommandBankUtils.h>
43 #include <drain/util/Rectangle.h>
44 #include <drain/util/StatusFlags.h>
45 #include <drain/util/TreeOrdered.h>
46 //#include <drain/util/Variable.h>
47 
48 #include "hi5/Hi5.h"
49 #include "hi5/Hi5Read.h"
50 #include "data/DataSelector.h"
51 #include "data/PolarODIM.h"
52 #include "data/ProductConf.h"
53 #include "data/VariableFormatterODIM.h"
54 #include "radar/Composite.h"
55 #include "radar/RadarAccumulator.h"
56 
57 #include "resources-base.h"
58 
59 namespace rack {
60 
61 
62 
64 
67 class RackContext : public ProductConf, public drain::SmartContext, public ImageContext, public AndreContext, public Hdf5Context {
68 
69 public:
70 
71 
72 
74  RackContext();
75 
77  RackContext(const RackContext & ctx);
78 
79  virtual
80  ~RackContext(){};
81 
82 
83  static
84  RackContext & getSharedContext(){
86  }
87 
88  // static
89  // const std::string validVariableChars;
90 
91  // Consider validVariableRE as general init parameter?
92  static
94 
95  // DataSelector superSelector;
96 
97  //static
98  //const drain::RegExp variableMapperSyntax;inputFilter
99  //drain::SingleFlagger<Reader::Mode>
100  // drain::SingleFlagger<hi5::Reader::Mode>
101  hi5::Reader::ModeFlagger inputFilter;
102 
104  std::string inputPrefix;
105 
107  std::string outputPrefix;
108 
109 
111  /*
112  std::string targetEncoding; // consider encodingRequest !
113  ODIMPathElem appendResults;
115  int outputDataVerbosity;
116  */
117 
118  // Accumulator for data in Cartesian coordinates
120 
121  // Experimental
122  bool guessDatasetGroup(const Hi5Tree & src, ODIMPathElem & pathElem) const;
123 
124  bool guessDatasetGroup(ODIMPathElem & pathElem){
125  Hi5Tree & src = getHi5(CURRENT);
126  return guessDatasetGroup(src, pathElem);
127  }
128 
129 
130 
135  //inline
136  //Hi5Tree & getHi5(h5_role::value_t filter);
137  // return getHi5Full(filter);
138  // }
139 
144  template <typename T, typename ...TT>
145  Hi5Tree & getHi5(const T &filter, const TT &... filters){
146 
147  T f(filter);
148  Hi5Tree & dst = getHi5Full(f);
149  if (f != 0)
150  return dst;
151  else
152  return getHi5(filters...);
153  }
154 
155 
156 
157  Hi5Tree & getHi5Full(h5_role::ivalue_t & filter);
158 
159  inline
160  Hi5Tree & getHi5(){
161  return empty; // or current?
162  }
163 
170  Composite & getComposite(h5_role::ivalue_t filter);
171 
172 
173  // Experimental
174  // ODIMPath currentPath;
175 
177  //static
178  ODIMPath findImage(const DataSelector & imageSelector);
179 
180  // static
181  ODIMPath findImage();
182 
184  // sstatic
185  const drain::image::Image & getCurrentGrayImage(); //RackContext & ctx);
186 
188  const drain::image::Image & getCurrentImage(); //RackContext & ctx);
189 
190 
192 
196  const drain::image::Image & updateCurrentImage(); //RackContext & ctx);
197 
199  drain::image::Image & getModifiableImage(); // (RackContext & ctx); // const DataSelector & selector
200 
201  void convertGrayImage(const drain::image::Image & srcImage); // RackContext & ctx,
202 
203  /*
204  virtual inline
205  drain::VariableMap & getStatusMap(bool update=true){
206  if (update){
207  Context::updateStatus(); // check if this should be moved under this->updateStatus() ? So this function could be removed.
208  updateStatus();
209  }
210  return statusMap;
211  };
212  */
213 
214  static
215  const VariableFormatterODIM<drain::Variable> variableFormatter;
216 
217  static
218  const VariableFormatterODIM<drain::FlexibleVariable> flexVariableFormatter;
219 
220 //private:
221 protected:
222 
223  virtual
224  void updateStatus() const final;
225  // Keep this class-specific.
226  //void updateStatus();
227 
228  // typedef drain::Cloner<Context,RackContext> ctx_cloner_t;
229 
230  // EXPERIMENTAL
231  static inline
232  RackContext & baseCtx() {
233  //return getContextCloner().getSourceOrig();
234  return drain::Static::get<RackContext>();
235  }
236 
237  /*
238  static inline
239  ctx_cloner_t & getContextCloner(){
240  return getCloner<RackContext>();
241  }
242  */
243 
244 };
245 
247 
250 class RackResources : public drain::SuperContextual<RackContext> {
251 
252 public:
253 
254  RackResources(); // : inputOk(true), dataOk(true), currentHi5(&inputHi5), currentPolarHi5(&inputHi5), currentImage(NULL), currentGrayImage(NULL) {};
255 
256  // Accumulator for data in polar coordinates
258 
259 
260 };
261 
264 
265 
266 
267 
268 } /* namespace rack */
269 
270 #endif /* RACKLET_H_ */
271 
272 // Rack
Definition: Context.h:204
A tool for expanding variables embedded in a std::string to literals.
Definition: StringMapper.h:275
Adds class-specific convenience functions.
Definition: Context.h:318
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition: Image.h:184
Definition: resources-base.h:153
Cartesian composite (mosaic) of data from several radars.
Definition: Composite.h:105
Definition: resources-base.h:173
Definition: resources-base.h:53
Definition: ODIMPath.h:82
Shared properties for meteorological products and Cartesian products (composites and single-radar ima...
Definition: ProductConf.h:63
Resources provided separately for each thread.
Definition: resources.h:67
static const drain::StringMapper variableMapper
Definition: resources.h:93
drain::image::Image & getModifiableImage()
Return current image, if modifiable. Else, copy (convert).
Definition: resources.cpp:410
const drain::image::Image & getCurrentGrayImage()
Light and lazy.
Definition: resources.cpp:177
Composite composite
TODO: inherit from ProductBase.
Definition: resources.h:119
RackContext()
Initializes data and image pointers to default targets or NULL.
Definition: resources.cpp:42
const drain::image::Image & getCurrentImage()
Light and lazy.
Definition: resources.cpp:195
Hi5Tree & getHi5(const T &filter, const TT &... filters)
Definition: resources.h:145
std::string inputPrefix
Path prefix for input files. Move to resources?
Definition: resources.h:104
virtual void updateStatus() const final
Definition: resources.cpp:492
void convertGrayImage(const drain::image::Image &srcImage)
Definition: resources.cpp:374
const drain::image::Image & updateCurrentImage()
Ensures current image.
Definition: resources.cpp:314
Composite & getComposite(h5_role::ivalue_t filter)
Definition: resources.cpp:139
std::string outputPrefix
Path prefix for output files. Move to resources?
Definition: resources.h:107
A container for shared resources applied by RackLets.
Definition: resources.h:250
Data array for creating composites and accumulated polar products (Surface rain fall or cluttermaps)
Definition: RadarAccumulator.h:61
Definition: DataSelector.cpp:44
RackResources & getResources()
Default instance.
Definition: resources.cpp:545