UFO
ObsFunctionBase.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UCAR
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #ifndef UFO_FILTERS_OBSFUNCTIONS_OBSFUNCTIONBASE_H_
9 #define UFO_FILTERS_OBSFUNCTIONS_OBSFUNCTIONBASE_H_
10 
11 #include <map>
12 #include <string>
13 
14 #include <boost/noncopyable.hpp>
15 
16 #include "ioda/ObsDataVector.h"
18 
19 namespace ufo {
20 
21 class Variables;
22 
23 // -----------------------------------------------------------------------------
24 /// Base class for computing functions on observation data
25 ///
26 /// \tparam FunctionValue
27 /// Type of the values produced by the function. Must be `float`, `int`, `std::string`
28 /// or `util::DateTime`.
29 template <typename FunctionValue>
30 class ObsFunctionBase : private boost::noncopyable {
31  public:
32  /// Type of the values produced by the function.
33  typedef FunctionValue Value_;
34 
35  explicit ObsFunctionBase(const eckit::LocalConfiguration conf = eckit::LocalConfiguration()) {}
36  virtual ~ObsFunctionBase() {}
37 
38 /// compute the result of the function
39  virtual void compute(const ObsFilterData &,
41 
42 /// geovals required to compute the function
43  virtual const ufo::Variables & requiredVariables() const = 0;
44 };
45 
46 // -----------------------------------------------------------------------------
47 
48 /// \brief Common properties of ObsFunctions producing values of type `FunctionValue`.
49 template <typename FunctionValue>
51 
52 template <>
53 struct ObsFunctionTraits<float>{
54  /// Name of the type of values produced by subclasses of ObsFunctionBase<float>.
55  static const char *valueTypeName;
56  /// Name of the group identifying ObsFunctions producing floats.
57  static const char *groupName;
58 };
59 
60 template <>
61 struct ObsFunctionTraits<int>{
62  /// Name of the type of values produced by subclasses of ObsFunctionBase<int>.
63  static const char *valueTypeName;
64  /// Name of the group identifying ObsFunctions producing ints.
65  static const char *groupName;
66 };
67 
68 template <>
69 struct ObsFunctionTraits<std::string>{
70  /// Name of the type of values produced by subclasses of ObsFunctionBase<std::string>.
71  static const char *valueTypeName;
72  /// Name of the group identifying ObsFunctions producing strings.
73  static const char *groupName;
74 };
75 
76 template <>
77 struct ObsFunctionTraits<util::DateTime>{
78  /// Name of the type of values produced by subclasses of ObsFunctionBase<util::DateTime>.
79  static const char *valueTypeName;
80  /// Name of the group identifying ObsFunctions producing datetimes.
81  static const char *groupName;
82 };
83 
84 // -----------------------------------------------------------------------------
85 
86 /// Factory of ObsFunctions producing values of type `FunctionValue`.
87 template <typename FunctionValue>
89  public:
91  virtual ~ObsFunctionFactory() = default;
92  static bool functionExists(const std::string &);
93  protected:
94  explicit ObsFunctionFactory(const std::string &);
95  private:
96  virtual ObsFunctionBase<FunctionValue> * make(const eckit::LocalConfiguration conf) = 0;
97  static std::map < std::string, ObsFunctionFactory * > & getMakers() {
98  static std::map < std::string, ObsFunctionFactory * > makers_;
99  return makers_;
100  }
101 };
102 
103 // -----------------------------------------------------------------------------
104 
105 template <class T>
106 class ObsFunctionMaker : public ObsFunctionFactory<typename T::Value_> {
107  typedef typename T::Value_ Value_;
109 
110  virtual ObsFunctionBase<Value_> * make(const eckit::LocalConfiguration conf)
111  { return new T(conf); }
112  public:
113  explicit ObsFunctionMaker(const std::string & name)
114  : Factory_(name) {}
115 };
116 
117 // -----------------------------------------------------------------------------
118 
119 } // namespace ufo
120 
121 #endif // UFO_FILTERS_OBSFUNCTIONS_OBSFUNCTIONBASE_H_
ObsFilterData provides access to all data related to an ObsFilter.
virtual const ufo::Variables & requiredVariables() const =0
geovals required to compute the function
ObsFunctionBase(const eckit::LocalConfiguration conf=eckit::LocalConfiguration())
virtual void compute(const ObsFilterData &, ioda::ObsDataVector< FunctionValue > &) const =0
compute the result of the function
FunctionValue Value_
Type of the values produced by the function.
Factory of ObsFunctions producing values of type FunctionValue.
virtual ~ObsFunctionFactory()=default
virtual ObsFunctionBase< FunctionValue > * make(const eckit::LocalConfiguration conf)=0
static bool functionExists(const std::string &)
ObsFunctionFactory(const std::string &)
static std::map< std::string, ObsFunctionFactory * > & getMakers()
static ObsFunctionBase< FunctionValue > * create(const Variable &)
ObsFunctionFactory< Value_ > Factory_
virtual ObsFunctionBase< Value_ > * make(const eckit::LocalConfiguration conf)
ObsFunctionMaker(const std::string &name)
Definition: RunCRTM.h:27
static const char * valueTypeName
Name of the type of values produced by subclasses of ObsFunctionBase<float>.
static const char * groupName
Name of the group identifying ObsFunctions producing floats.
static const char * valueTypeName
Name of the type of values produced by subclasses of ObsFunctionBase<int>.
static const char * groupName
Name of the group identifying ObsFunctions producing ints.
static const char * valueTypeName
Name of the type of values produced by subclasses of ObsFunctionBase<std::string>.
static const char * groupName
Name of the group identifying ObsFunctions producing strings.
Common properties of ObsFunctions producing values of type FunctionValue.