UFO
PredictorBase.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 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 
9 
10 #include <map>
11 
12 #include "eckit/config/LocalConfiguration.h"
13 
14 #include "oops/util/abor1_cpp.h"
15 #include "oops/util/Logger.h"
16 
17 namespace ufo {
18 
19 // -----------------------------------------------------------------------------
20 
22  const oops::Variables & vars)
23  : func_name_(parameters.name),
24  geovars_(), hdiags_(), vars_(vars) {
25 }
26 
27 // -----------------------------------------------------------------------------
28 
29 PredictorFactory::PredictorFactory(const std::string & name) {
30  if (predictorExists(name)) {
31  oops::Log::error() << name << " already registered in ufo::PredictorFactory."
32  << std::endl;
33  ABORT("Element already registered in ufo::PredictorFactory.");
34  }
35  getMakers()[name] = this;
36 }
37 
38 // -----------------------------------------------------------------------------
39 
40 std::unique_ptr<PredictorBase> PredictorFactory::create(const PredictorParametersBase & parameters,
41  const oops::Variables & vars) {
42  oops::Log::trace() << "PredictorBase::create starting" << std::endl;
43  const std::string name = parameters.name;
44  if (!predictorExists(name)) {
45  oops::Log::error() << name << " does not exist in ufo::PredictorFactory."
46  << std::endl;
47  ABORT("Element does not exist in ufo::PredictorFactory.");
48  }
49  typename std::map<std::string, PredictorFactory*>::iterator jloc =
50  getMakers().find(name);
51  std::unique_ptr<PredictorBase> ptr = jloc->second->make(parameters, vars);
52  oops::Log::trace() << "PredictorBase::create done" << std::endl;
53  return ptr;
54 }
55 
56 // -----------------------------------------------------------------------------
57 
58 std::unique_ptr<PredictorParametersBase> PredictorFactory::createParameters(
59  const std::string &name) {
60  typename std::map<std::string, PredictorFactory*>::iterator it =
61  getMakers().find(name);
62  if (it == getMakers().end()) {
63  throw std::runtime_error(name + " does not exist in ufo::PredictorFactory");
64  }
65  return it->second->makeParameters();
66 }
67 
68 // -----------------------------------------------------------------------------
69 
70 bool PredictorFactory::predictorExists(const std::string & name) {
71  return (getMakers().find(name) != getMakers().end());
72 }
73 
74 // -----------------------------------------------------------------------------
75 
76 } // namespace ufo
PredictorBase(const PredictorParametersBase &, const oops::Variables &)
static std::unique_ptr< PredictorBase > create(const PredictorParametersBase &parameters, const oops::Variables &vars)
Create and return a new predictor.
PredictorFactory(const std::string &name)
Register a maker able to create predictors of type name.
static bool predictorExists(const std::string &name)
Return true if a maker has been registered for a predictor of type name.
static std::map< std::string, PredictorFactory * > & getMakers()
static std::unique_ptr< PredictorParametersBase > createParameters(const std::string &name)
Create and return an instance of the subclass of PredictorParametersBase storing parameters of predic...
Base class for predictor parameters.
Definition: PredictorBase.h:37
oops::RequiredParameter< std::string > name
Predictor name.
Definition: PredictorBase.h:42
Definition: RunCRTM.h:27