DP3
DPBuffer.h
Go to the documentation of this file.
1 // DPBuffer.h: Buffer holding the data of a timeslot/band
2 // Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 
8 
9 #ifndef DP3_BASE_DPBUFFER_H_
10 #define DP3_BASE_DPBUFFER_H_
11 
12 #include <array>
13 #include <map>
14 #include <vector>
15 
16 #include <xtensor/containers/xtensor.hpp>
17 
18 #include <casacore/casa/Arrays/Vector.h>
19 #include <aocommon/xt/utensor.h>
20 
21 #include "common/Fields.h"
22 #include "common/Types.h"
23 
24 namespace dp3 {
25 namespace base {
26 
28 
92 class DPBuffer {
93  public:
94  // Return types for Get* functions.
95  using DataType = aocommon::xt::UTensor<std::complex<float>, 3>;
96  using WeightsType = xt::xtensor<float, 3>;
97  using FlagsType = xt::xtensor<bool, 3>;
98  using UvwType = xt::xtensor<double, 2>;
100  using SolutionType = std::vector<std::vector<std::complex<double>>>;
101 
103  explicit DPBuffer(double time = 0.0, double exposure = 0.0);
104 
107  DPBuffer(const DPBuffer&) = default;
108 
111 
115  DPBuffer(const DPBuffer& that, const common::Fields& fields);
116 
120 
123 
129  void Copy(const DPBuffer& that, const common::Fields& fields,
130  const bool extra_data = false);
131 
136  void AddData(const std::string& name);
137 
141  void RemoveData(const std::string& name = "");
142 
147  bool HasData(const std::string& name = "") const {
148  return name.empty() || (extra_data_.find(name) != extra_data_.end());
149  }
150 
152  std::vector<std::string> GetDataNames() const {
153  std::vector<std::string> names;
154  names.reserve(1 + extra_data_.size());
155  names.push_back("");
156  for (const auto& name_vector : extra_data_) {
157  names.push_back(name_vector.first);
158  }
159  return names;
160  }
161 
168  const DataType& GetData(const std::string& name = "") const {
169  if (name.empty()) {
170  return data_;
171  } else {
172  auto found = extra_data_.find(name);
173  if (found == extra_data_.end()) {
174  throw std::runtime_error("No data named '" + name +
175  "' is found in the current DPBuffer");
176  }
177 
178  return found->second;
179  }
180  }
181  DataType& GetData(const std::string& name = "") {
182  if (name.empty()) {
183  return data_;
184  } else {
185  auto found = extra_data_.find(name);
186  if (found == extra_data_.end()) {
187  throw std::runtime_error("No data named '" + name +
188  "' is found in the current DPBuffer");
189  }
190  return found->second;
191  }
192  }
193 
200  DataType result;
201  std::swap(result, data_);
202  return result;
203  }
204 
211  void CopyData(const DPBuffer& source, const std::string& source_name,
212  const std::string& target_name);
213 
220  void MoveData(DPBuffer& source, const std::string& source_name,
221  const std::string& target_name);
222 
227  const FlagsType& GetFlags() const { return flags_; }
228  FlagsType& GetFlags() { return flags_; }
229 
234  const WeightsType& GetWeights() const { return weights_; }
235  WeightsType& GetWeights() { return weights_; }
236 
243  WeightsType result;
244  std::swap(result, weights_);
245  return result;
246  }
247 
249  void SetTime(double time) { time_ = time; }
250  double GetTime() const { return time_; }
251 
253  void SetExposure(double exposure) { exposure_ = exposure; }
254  double GetExposure() const { return exposure_; }
255 
258  void SetRowNumbers(const casacore::Vector<common::rownr_t>& rownrs) {
259  row_numbers_.reference(rownrs);
260  }
261  const casacore::Vector<common::rownr_t>& GetRowNumbers() const {
262  return row_numbers_;
263  }
264 
269  const UvwType& GetUvw() const { return uvw_; }
270  UvwType& GetUvw() { return uvw_; }
271 
272  void SetSolution(const SolutionType& solution) { solution_ = solution; }
273  const SolutionType& GetSolution() const { return solution_; }
274 
275  private:
276  double time_;
277  double exposure_;
278  casacore::Vector<common::rownr_t> row_numbers_;
279 
281  DataType data_;
283  std::map<std::string, DataType> extra_data_;
284 
286  FlagsType flags_;
288  WeightsType weights_;
290  UvwType uvw_;
291 
293  SolutionType solution_;
294 };
295 
296 } // namespace base
297 } // namespace dp3
298 
299 #endif // DP3_BASE_DPBUFFER_H_
Define common types.
Buffer holding the data of a timeslot/band.
Definition: DPBuffer.h:92
WeightsType & GetWeights()
Definition: DPBuffer.h:235
void MoveData(DPBuffer &source, const std::string &source_name, const std::string &target_name)
WeightsType TakeWeights()
Definition: DPBuffer.h:242
xt::xtensor< double, 2 > UvwType
Definition: DPBuffer.h:98
const SolutionType & GetSolution() const
Definition: DPBuffer.h:273
void SetSolution(const SolutionType &solution)
Definition: DPBuffer.h:272
const casacore::Vector< common::rownr_t > & GetRowNumbers() const
Definition: DPBuffer.h:261
double GetTime() const
Definition: DPBuffer.h:250
double GetExposure() const
Definition: DPBuffer.h:254
const WeightsType & GetWeights() const
Definition: DPBuffer.h:234
xt::xtensor< bool, 3 > FlagsType
Definition: DPBuffer.h:97
DPBuffer & operator=(const DPBuffer &)
void RemoveData(const std::string &name="")
const DataType & GetData(const std::string &name="") const
Definition: DPBuffer.h:168
void SetRowNumbers(const casacore::Vector< common::rownr_t > &rownrs)
Definition: DPBuffer.h:258
DPBuffer(const DPBuffer &)=default
void Copy(const DPBuffer &that, const common::Fields &fields, const bool extra_data=false)
DPBuffer(const DPBuffer &that, const common::Fields &fields)
const FlagsType & GetFlags() const
Definition: DPBuffer.h:227
xt::xtensor< float, 3 > WeightsType
Definition: DPBuffer.h:96
std::vector< std::vector< std::complex< double > >> SolutionType
For every channel, contains n_antennas x n_polarizations solutions.
Definition: DPBuffer.h:100
void CopyData(const DPBuffer &source, const std::string &source_name, const std::string &target_name)
DPBuffer(double time=0.0, double exposure=0.0)
Construct object with empty arrays.
DataType TakeData()
Definition: DPBuffer.h:199
void SetExposure(double exposure)
Get or set the exposure.
Definition: DPBuffer.h:253
bool HasData(const std::string &name="") const
Definition: DPBuffer.h:147
FlagsType & GetFlags()
Definition: DPBuffer.h:228
UvwType & GetUvw()
Definition: DPBuffer.h:270
void SetTime(double time)
Get or set the time.
Definition: DPBuffer.h:249
aocommon::xt::UTensor< std::complex< float >, 3 > DataType
Definition: DPBuffer.h:95
DPBuffer(DPBuffer &&)
The move constructor moves all data without using reference semantics.
DPBuffer & operator=(DPBuffer &&)
Move assignment moves all data without using reference semantics.
void AddData(const std::string &name)
const UvwType & GetUvw() const
Definition: DPBuffer.h:269
std::vector< std::string > GetDataNames() const
Definition: DPBuffer.h:152
DataType & GetData(const std::string &name="")
Definition: DPBuffer.h:181
Definition: Fields.h:16
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53