IODA Bundle
Transforms/TransformBuilder.cpp
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 NOAA/NWS/NCEP/EMC
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 #include "TransformBuilder.h"
9 
10 #include "eckit/exception/Exceptions.h"
11 
12 #include "ScalingTransform.h"
13 #include "OffsetTransform.h"
14 
15 
16 static const char* TRANSFORMS_SECTION = "transforms";
17 static const char* OFFSET_KEY = "offset";
18 static const char* SCALE_KEY = "scale";
19 
20 namespace Ingester
21 {
22  std::shared_ptr<Transform> TransformBuilder::makeTransform(const eckit::Configuration& conf)
23  {
24  std::shared_ptr <Transform> transform;
25  if (conf.has(OFFSET_KEY))
26  {
27  transform = std::make_shared<OffsetTransform>(conf.getFloat(OFFSET_KEY));
28  }
29  else if (conf.has(SCALE_KEY))
30  {
31  transform = std::make_shared<ScalingTransform>(conf.getFloat(SCALE_KEY));
32  }
33  else
34  {
35  throw eckit::BadParameter("Tried to create unknown export transform type. "
36  "Check your configuration.");
37  }
38 
39  return transform;
40  }
41 
42  Transforms TransformBuilder::makeTransforms(const eckit::Configuration& conf)
43  {
44  Transforms transforms;
45  if (conf.has(TRANSFORMS_SECTION))
46  {
47  for (const auto& transformConf : conf.getSubConfigurations(TRANSFORMS_SECTION))
48  {
49  transforms.push_back(makeTransform(transformConf));
50  }
51  }
52 
53  return transforms;
54  }
55 } // namespace Ingester
static const char * TRANSFORMS_SECTION
static const char * OFFSET_KEY
static const char * SCALE_KEY
static std::shared_ptr< Transform > makeTransform(const eckit::Configuration &conf)
Create transform given the configuration.
static Transforms makeTransforms(const eckit::Configuration &conf)
Uses makeTransform to loop through the list of transforms in the configuration.
std::vector< std::shared_ptr< Transform > > Transforms