UFO
ProfileChecker.cc
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2020, Met Office
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 <algorithm>
9 #include <set>
10 #include <utility>
11 
12 #include "eckit/exception/Exceptions.h"
13 
14 #include "oops/util/Logger.h"
15 
26 
28 
29 namespace ufo {
31  : options_(options),
32  checks_(options.Checks.value())
33  {
34  // Ensure basic checks are always performed first
35  auto it_checks = std::find(checks_.begin(), checks_.end(), "Basic");
36  if (it_checks == checks_.end()) {
37  // If "Basic" not present, insert at the start
38  checks_.insert(checks_.begin(), "Basic");
39  } else if (it_checks != checks_.begin()) {
40  // If "Basic" is present but not at the start, move it there
41  std::rotate(checks_.begin(), it_checks, it_checks + 1);
42  }
43 
44  // Produce check subgroups.
45  // A subgroup is the longest sequence of consecutive checks which have
46  // the same mode of operation.
47  bool isFirst = true; // First check considered; used to initialise checkMode.
48  bool checkMode = true; // Mode of operation of the current check.
49  std::vector <std::string> checkNames; // Filled anew for each subgroup.
50  // Also fill a set of any required GeoVaL names.
51  for (const auto& check : checks_) {
52  // Instantiate each check and check its mode of operation.
53  std::unique_ptr<ProfileCheckBase> profileCheck =
55  options_);
56  if (profileCheck) {
57  if (isFirst) {
58  checkMode = profileCheck->runOnEntireSample();
59  isFirst = false;
60  }
61  if (profileCheck->runOnEntireSample() == checkMode) {
62  checkNames.push_back(check);
63  } else {
64  checkSubgroups_.push_back({checkMode, checkNames});
65  checkNames.clear();
66  checkNames.push_back(check);
67  // Invert checkMode whenever a check with a different mode is reached.
68  checkMode = !checkMode;
69  }
70  GeoVaLNames_ += profileCheck->getGeoVaLNames();
71  validationGeoVaLNames_ += profileCheck->getValidationGeoVaLNames();
72  obsDiagNames_ += profileCheck->getObsDiagNames();
73  } else {
74  throw eckit::NotImplemented("Have not implemented a check for " + check, Here());
75  }
76  }
77  // Fill checkSubgroups with the final list to be produced.
78  checkSubgroups_.push_back({checkMode, checkNames});
79  }
80 
82  const CheckSubgroup &subGroupChecks)
83  {
84  // Run all checks requested
85  for (const auto& check : subGroupChecks.checkNames) {
86  std::unique_ptr<ProfileCheckBase> profileCheck =
88  options_);
89  if (profileCheck) {
90  // Ensure correct type of check has been requested.
91  if (profileCheck->runOnEntireSample() == subGroupChecks.runOnEntireSample) {
92  // For checks on the entire sample, reset profile indices
93  // prior to looping through the profiles
94  if (profileCheck->runOnEntireSample())
95  profileDataHandler.resetProfileIndices();
96  // Run check
97  profileCheck->runCheck(profileDataHandler);
98  // Actions taken if a single profile was processed.
99  if (!profileCheck->runOnEntireSample()) {
100  // Fill validation information if required
101  if (options_.compareWithOPS.value())
102  profileCheck->fillValidationData(profileDataHandler);
103  // Do not proceed if basic checks failed
104  if (!profileCheck->getResult() && check == "Basic") {
105  oops::Log::debug() << "Basic checks failed" << std::endl;
106  setBasicCheckResult(false);
107  break;
108  }
109  }
110  }
111  } else {
112  throw eckit::NotImplemented("Have not implemented a check for " + check, Here());
113  }
114  }
115  }
116 } // namespace ufo
Options controlling the operation of the ConventionalProfileProcessing filter.
oops::Parameter< bool > compareWithOPS
Compare with OPS values?
static std::unique_ptr< ProfileCheckBase > create(const std::string &, const ConventionalProfileProcessingParameters &)
void runChecks(ProfileDataHandler &profileDataHandler, const CheckSubgroup &subGroupChecks)
Run all checks requested.
const ConventionalProfileProcessingParameters & options_
Configurable parameters.
oops::Variables validationGeoVaLNames_
Names of all validation GeoVaLs.
oops::Variables obsDiagNames_
Names of all required obs diagnostics.
CheckSubgroupList checkSubgroups_
Subgroups of checks with the same mode of operation.
std::vector< std::string > checks_
Checks to perform.
void setBasicCheckResult(bool result)
Set basic check result.
ProfileChecker(const ConventionalProfileProcessingParameters &options)
oops::Variables GeoVaLNames_
Names of all required GeoVaLs.
Retrieve and store data for individual profiles. To do this, first the vector of values in the entire...
subroutine check(action, status)
Definition: RunCRTM.h:27
Information on each subgroup of checks.
std::vector< std::string > checkNames
checkNames contains the names of the checks in this subgroup.