IODA Bundle
oops/src/oops/interface/ObsSpace.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2009-2016 ECMWF.
3  * (C) Copyright 2017-2019 UCAR.
4  *
5  * This software is licensed under the terms of the Apache Licence Version 2.0
6  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7  * In applying this licence, ECMWF does not waive the privileges and immunities
8  * granted to it by virtue of its status as an intergovernmental organisation nor
9  * does it submit to any jurisdiction.
10  */
11 
12 #ifndef OOPS_INTERFACE_OBSSPACE_H_
13 #define OOPS_INTERFACE_OBSSPACE_H_
14 
15 #include <memory>
16 #include <ostream>
17 #include <string>
18 
19 #include "eckit/geometry/Point2.h"
20 #include "eckit/system/ResourceUsage.h"
21 
22 #include "oops/base/Variables.h"
24 #include "oops/mpi/mpi.h"
25 #include "oops/util/Logger.h"
26 #include "oops/util/ObjectCounter.h"
27 #include "oops/util/Printable.h"
28 #include "oops/util/Timer.h"
29 
30 namespace eckit {
31  class Configuration;
32 }
33 
34 namespace util {
35  class DateTime;
36 }
37 
38 namespace oops {
39 
40 // -----------------------------------------------------------------------------
41 
42 template <typename OBS>
43 class ObsSpace : public util::Printable,
44  private util::ObjectCounter<ObsSpace<OBS> > {
45  typedef typename OBS::ObsSpace ObsSpace_;
47 
48  public:
49  static const std::string classname() {return "oops::ObsSpace";}
50 
51  ObsSpace(const eckit::Configuration &, const eckit::mpi::Comm &,
52  const util::DateTime &, const util::DateTime &,
53  const eckit::mpi::Comm & time = oops::mpi::myself());
54  ~ObsSpace();
55 
56  ObsSpace(const ObsSpace &) = delete;
57 
58 /// Interfacing
59  ObsSpace_ & obsspace() const {return *obsdb_;} // const problem? YT
60 
61 /// Assimilation window
62  const util::DateTime & windowStart() const {return obsdb_->windowStart();}
63  const util::DateTime & windowEnd() const {return obsdb_->windowEnd();}
64 
65  const Variables & obsvariables() const;
66 
67 // Other
68  const std::string & obsname() const {return obsdb_->obsname();}
69 
70  /// Iterator to the first observation
71  ObsIterator_ begin() const;
72  /// Iterator to the past-the-end observation (after last)
73  ObsIterator_ end() const;
74 
75  const eckit::mpi::Comm & timeComm() const {return time_;}
76 
77 // Save to file
78  void save() const;
79 
80  private:
81  void print(std::ostream &) const;
82 
83  std::unique_ptr<ObsSpace_> obsdb_;
84  const eckit::mpi::Comm & time_;
85 };
86 
87 // -----------------------------------------------------------------------------
88 
89 template <typename OBS>
90 ObsSpace<OBS>::ObsSpace(const eckit::Configuration & conf,
91  const eckit::mpi::Comm & comm,
92  const util::DateTime & bgn,
93  const util::DateTime & end,
94  const eckit::mpi::Comm & time) : obsdb_(), time_(time) {
95  Log::trace() << "ObsSpace<OBS>::ObsSpace starting" << std::endl;
96  util::Timer timer(classname(), "ObsSpace");
97  size_t init = eckit::system::ResourceUsage().maxResidentSetSize();
98  obsdb_.reset(new ObsSpace_(conf, comm, bgn, end, time));
99  size_t current = eckit::system::ResourceUsage().maxResidentSetSize();
100  this->setObjectSize(current - init);
101  Log::trace() << "ObsSpace<OBS>::ObsSpace done" << std::endl;
102 }
103 
104 // -----------------------------------------------------------------------------
105 
106 template <typename OBS>
108  Log::trace() << "ObsSpace<OBS>::~ObsSpace starting" << std::endl;
109  util::Timer timer(classname(), "~ObsSpace");
110  obsdb_.reset();
111  Log::trace() << "ObsSpace<OBS>::~ObsSpace done" << std::endl;
112 }
113 
114 // -----------------------------------------------------------------------------
115 
116 template <typename OBS>
117 void ObsSpace<OBS>::save() const {
118  Log::trace() << "ObsSpace<OBS>::save starting" << std::endl;
119  util::Timer timer(classname(), "save");
120  obsdb_->save();
121  Log::trace() << "ObsSpace<OBS>::save done" << std::endl;
122 }
123 
124 // -----------------------------------------------------------------------------
125 
126 template <typename OBS>
127 void ObsSpace<OBS>::print(std::ostream & os) const {
128  Log::trace() << "ObsSpace<OBS>::print starting" << std::endl;
129  util::Timer timer(classname(), "print");
130  os << *obsdb_;
131  Log::trace() << "ObsSpace<OBS>::print done" << std::endl;
132 }
133 
134 // -----------------------------------------------------------------------------
135 
136 template <typename OBS>
138  Log::trace() << "ObsSpace<OBS>::obsvariables starting" << std::endl;
139  util::Timer timer(classname(), "obsvariables");
140  return obsdb_->obsvariables();
141 }
142 
143 // -----------------------------------------------------------------------------
144 
145 template <typename OBS>
147  Log::trace() << "ObsSpace<OBS>::begin starting" << std::endl;
148  util::Timer timer(classname(), "begin");
149  Log::trace() << "ObsSpace<OBS>::begin done" << std::endl;
150  return ObsIterator_(obsdb_->begin());
151 }
152 
153 // -----------------------------------------------------------------------------
154 
155 template <typename OBS>
157  Log::trace() << "ObsSpace<OBS>::end starting" << std::endl;
158  util::Timer timer(classname(), "end");
159  Log::trace() << "ObsSpace<OBS>::end done" << std::endl;
160  return ObsIterator_(obsdb_->end());
161 }
162 
163 // -----------------------------------------------------------------------------
164 
165 } // namespace oops
166 
167 #endif // OOPS_INTERFACE_OBSSPACE_H_
std::unique_ptr< ObsSpace_ > obsdb_
void print(std::ostream &) const
ObsIterator_ end() const
Iterator to the past-the-end observation (after last)
ObsSpace(const ObsSpace &)=delete
ObsIterator_ begin() const
Iterator to the first observation.
ObsSpace(const eckit::Configuration &, const eckit::mpi::Comm &, const util::DateTime &, const util::DateTime &, const eckit::mpi::Comm &time=oops::mpi::myself())
ObsSpace_ & obsspace() const
Interfacing.
static const std::string classname()
const eckit::mpi::Comm & time_
const std::string & obsname() const
const util::DateTime & windowStart() const
Assimilation window.
const eckit::mpi::Comm & timeComm() const
const Variables & obsvariables() const
GeometryIterator< OBS > ObsIterator_
const util::DateTime & windowEnd() const
const eckit::mpi::Comm & myself()
Default communicator with each MPI task by itself.
Definition: oops/mpi/mpi.cc:90
The namespace for the main oops code.