OOPS
ObsDataVector.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2018 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 
8 #ifndef OOPS_INTERFACE_OBSDATAVECTOR_H_
9 #define OOPS_INTERFACE_OBSDATAVECTOR_H_
10 
11 #include <memory>
12 #include <ostream>
13 #include <string>
14 
15 #include "oops/base/Variables.h"
17 #include "oops/util/Logger.h"
18 #include "oops/util/ObjectCounter.h"
19 #include "oops/util/Printable.h"
20 #include "oops/util/Timer.h"
21 
22 namespace oops {
23 
24 // -----------------------------------------------------------------------------
25 
26 template <typename OBS, typename DATATYPE>
27 class ObsDataVector : public util::Printable,
28  private util::ObjectCounter<ObsDataVector<OBS, DATATYPE> > {
29  typedef typename OBS::template ObsDataVector<DATATYPE> ObsDataVec_;
30 
31  public:
32  static const std::string classname() {return "oops::ObsDataVector";}
33 
34  ObsDataVector(const ObsSpace<OBS> &, const Variables &, const std::string name = "");
35  explicit ObsDataVector(const ObsDataVector &);
37 
38 /// Interfacing
40  const ObsDataVec_ & obsdatavector() const {return *data_;}
41 
42  std::shared_ptr<ObsDataVec_> obsdatavectorptr() {return data_;}
43  std::shared_ptr<const ObsDataVec_> obsdatavectorptr() const {return data_;}
44 
46 
47  void zero();
48  void mask(const ObsDataVector<OBS, int> &);
49  unsigned int nobs() const {return data_->nobs();}
50 
51 // I/O
52  void save(const std::string &) const;
53 
54  private:
55  void print(std::ostream &) const;
56  std::shared_ptr<ObsDataVec_> data_;
57 };
58 
59 // -----------------------------------------------------------------------------
60 template <typename OBS, typename DATATYPE>
62  const Variables & vars, const std::string name)
63  : data_()
64 {
65  Log::trace() << "ObsDataVector<OBS, DATATYPE>::ObsDataVector starting" << std::endl;
66  util::Timer timer(classname(), "ObsDataVector");
67  data_.reset(new ObsDataVec_(os.obsspace(), vars, name));
68  Log::trace() << "ObsDataVector<OBS, DATATYPE>::ObsDataVector done" << std::endl;
69 }
70 // -----------------------------------------------------------------------------
71 template <typename OBS, typename DATATYPE>
73  Log::trace() << "ObsDataVector<OBS, DATATYPE>::ObsDataVector starting" << std::endl;
74  util::Timer timer(classname(), "ObsDataVector");
75  data_.reset(new ObsDataVec_(*other.data_));
76  Log::trace() << "ObsDataVector<OBS, DATATYPE>::ObsDataVector done" << std::endl;
77 }
78 // -----------------------------------------------------------------------------
79 template <typename OBS, typename DATATYPE>
81  Log::trace() << "ObsDataVector<OBS, DATATYPE>::~ObsDataVector starting" << std::endl;
82  util::Timer timer(classname(), "~ObsDataVector");
83  data_.reset();
84  Log::trace() << "ObsDataVector<OBS, DATATYPE>::~ObsDataVector done" << std::endl;
85 }
86 // -----------------------------------------------------------------------------
87 template <typename OBS, typename DATATYPE> ObsDataVector<OBS, DATATYPE> &
89  Log::trace() << "ObsDataVector<OBS, DATATYPE>::operator= starting" << std::endl;
90  util::Timer timer(classname(), "operator=");
91  *data_ = *rhs.data_;
92  Log::trace() << "ObsDataVector<OBS, DATATYPE>::operator= done" << std::endl;
93  return *this;
94 }
95 // -----------------------------------------------------------------------------
96 template <typename OBS, typename DATATYPE>
98  Log::trace() << "ObsDataVector<OBS, DATATYPE>::zero starting" << std::endl;
99  util::Timer timer(classname(), "zero");
100  data_->zero();
101  Log::trace() << "ObsDataVector<OBS, DATATYPE>::zero done" << std::endl;
102 }
103 // -----------------------------------------------------------------------------
104 template <typename OBS, typename DATATYPE>
106  Log::trace() << "ObsDataVector<OBS>::mask starting" << std::endl;
107  util::Timer timer(classname(), "mask");
108  data_->mask(qc.obsdatavector());
109  Log::trace() << "ObsDataVector<OBS>::mask done" << std::endl;
110 }
111 // -----------------------------------------------------------------------------
112 template <typename OBS, typename DATATYPE>
113 void ObsDataVector<OBS, DATATYPE>::print(std::ostream & os) const {
114  Log::trace() << "ObsDataVector<OBS, DATATYPE>::print starting" << std::endl;
115  util::Timer timer(classname(), "print");
116  os << *data_;
117  Log::trace() << "ObsDataVector<OBS, DATATYPE>::print done" << std::endl;
118 }
119 // -----------------------------------------------------------------------------
120 template <typename OBS, typename DATATYPE>
121 void ObsDataVector<OBS, DATATYPE>::save(const std::string & name) const {
122  Log::trace() << "ObsDataVector<OBS, DATATYPE>::save starting " << name << std::endl;
123  util::Timer timer(classname(), "save");
124  data_->save(name);
125  Log::trace() << "ObsDataVector<OBS, DATATYPE>::save done" << std::endl;
126 }
127 // -----------------------------------------------------------------------------
128 
129 } // namespace oops
130 
131 #endif // OOPS_INTERFACE_OBSDATAVECTOR_H_
oops::ObsDataVector::~ObsDataVector
~ObsDataVector()
Definition: ObsDataVector.h:80
oops
The namespace for the main oops code.
Definition: ErrorCovarianceL95.cc:22
oops::ObsDataVector::data_
std::shared_ptr< ObsDataVec_ > data_
Definition: ObsDataVector.h:56
oops::ObsDataVector::ObsDataVector
ObsDataVector(const ObsSpace< OBS > &, const Variables &, const std::string name="")
Definition: ObsDataVector.h:61
oops::ObsSpace
Definition: oops/interface/ObsSpace.h:42
oops::ObsSpace::obsspace
ObsSpace_ & obsspace() const
Interfacing.
Definition: oops/interface/ObsSpace.h:61
oops::ObsDataVector::obsdatavectorptr
std::shared_ptr< ObsDataVec_ > obsdatavectorptr()
Definition: ObsDataVector.h:42
oops::ObsDataVector::print
void print(std::ostream &) const
Definition: ObsDataVector.h:113
oops::ObsDataVector::ObsDataVec_
OBS::template ObsDataVector< DATATYPE > ObsDataVec_
Definition: ObsDataVector.h:29
oops::ObsDataVector::operator=
ObsDataVector & operator=(const ObsDataVector &)
Definition: ObsDataVector.h:88
oops::ObsDataVector::save
void save(const std::string &) const
Definition: ObsDataVector.h:121
oops::ObsDataVector::nobs
unsigned int nobs() const
Definition: ObsDataVector.h:49
oops::ObsDataVector::obsdatavector
ObsDataVec_ & obsdatavector()
Interfacing.
Definition: ObsDataVector.h:39
oops::ObsDataVector::classname
static const std::string classname()
Definition: ObsDataVector.h:32
ObsSpace.h
oops::ObsDataVector
Definition: ObsDataVector.h:28
oops::ObsDataVector::obsdatavectorptr
std::shared_ptr< const ObsDataVec_ > obsdatavectorptr() const
Definition: ObsDataVector.h:43
oops::ObsDataVector::mask
void mask(const ObsDataVector< OBS, int > &)
Definition: ObsDataVector.h:105
oops::Variables
Definition: oops/base/Variables.h:23
oops::ObsDataVector::obsdatavector
const ObsDataVec_ & obsdatavector() const
Definition: ObsDataVector.h:40
oops::ObsDataVector::zero
void zero()
Definition: ObsDataVector.h:97
Variables.h