12 #ifndef OOPS_GENERIC_LOCALIZATIONBASE_H_
13 #define OOPS_GENERIC_LOCALIZATIONBASE_H_
19 #include <boost/noncopyable.hpp>
24 #include "oops/util/Logger.h"
25 #include "oops/util/Printable.h"
42 template <
typename MODEL>
44 private boost::noncopyable {
60 template <
typename MODEL>
68 static std::unique_ptr<LocalizationBase<MODEL>>
create(
const Geometry_ &,
69 const eckit::Configuration & config);
75 virtual std::unique_ptr<LocalizationBase<MODEL>>
make(
const Geometry_ &,
76 const eckit::Configuration &) = 0;
77 static std::map < std::string, LocalizationFactory<MODEL> * > &
getMakers() {
78 static std::map < std::string, LocalizationFactory<MODEL> * > makers_;
86 template<
class MODEL,
class T>
89 std::unique_ptr<LocalizationBase<MODEL>>
make(
const Geometry_ & geometry,
90 const eckit::Configuration & conf)
override
91 {
return std::make_unique<T>(geometry, conf); }
98 template <
typename MODEL>
100 if (getMakers().find(name) != getMakers().end()) {
101 throw std::runtime_error(name +
" already registered in localization factory.");
103 getMakers()[name] =
this;
108 template <
typename MODEL>
109 std::unique_ptr<LocalizationBase<MODEL>>
111 const eckit::Configuration & conf) {
112 Log::trace() <<
"LocalizationBase<MODEL>::create starting" << std::endl;
113 const std::string
id = conf.getString(
"localization method");
114 typename std::map<std::string, LocalizationFactory<MODEL>*>::iterator
115 jloc = getMakers().find(
id);
116 if (jloc == getMakers().end()) {
117 Log::error() <<
id <<
" does not exist in localization factory." << std::endl;
118 Log::error() <<
"Obs Localization Factory has " << getMakers().size()
119 <<
" elements:" << std::endl;
121 jj = getMakers().begin(); jj != getMakers().end(); ++jj) {
122 Log::error() <<
"A " << jj->first <<
" Localization" << std::endl;
124 throw std::runtime_error(
id +
" does not exist in localization factory.");
126 std::unique_ptr<LocalizationBase<MODEL>> ptr(jloc->second->make(geometry, conf));
127 Log::trace() <<
"LocalizationBase<MODEL>::create done" << std::endl;
Geometry class used in oops; subclass of interface class interface::Geometry.
Increment class used in oops.
Base class for generic implementations of model-space localization. Use this class as a base class fo...
Increment< MODEL > Increment_
virtual void randomize(Increment_ &dx) const =0
Randomize dx and apply 3D localization.
LocalizationBase()=default
virtual void multiply(Increment_ &dx) const =0
Apply 3D localization to dx.
virtual ~LocalizationBase()=default
virtual ~LocalizationFactory()=default
LocalizationFactory(const std::string &name)
Register a maker able to create Localizations of type name.
static std::unique_ptr< LocalizationBase< MODEL > > create(const Geometry_ &, const eckit::Configuration &config)
Create and return a new Localization.
virtual std::unique_ptr< LocalizationBase< MODEL > > make(const Geometry_ &, const eckit::Configuration &)=0
Geometry< MODEL > Geometry_
static std::map< std::string, LocalizationFactory< MODEL > * > & getMakers()
A subclass of LocalizationFactory able to create instances of T (a concrete subclass of LocalizationB...
std::unique_ptr< LocalizationBase< MODEL > > make(const Geometry_ &geometry, const eckit::Configuration &conf) override
Geometry< MODEL > Geometry_
LocalizationMaker(const std::string &name)
The namespace for the main oops code.