DP3
Step.h
Go to the documentation of this file.
1 // Step.h: Abstract base class for a DP3 step
2 // Copyright (C) 2023 ASTRON (Netherlands Institute for Radio Astronomy)
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 
8 
9 #ifndef DP3_STEPS_STEP_H_
10 #define DP3_STEPS_STEP_H_
11 
12 #include <iosfwd>
13 #include <memory>
14 #include <string>
15 
16 #include "base/DPBuffer.h"
17 #include "base/BdaBuffer.h"
18 #include "base/DPInfo.h"
19 #include "base/Direction.h"
20 
21 #include "common/Fields.h"
22 
23 namespace dp3 {
24 namespace steps {
25 
27 
51 
52 class Step {
53  public:
54  typedef std::shared_ptr<Step> ShPtr;
55 
57  enum class MsType { kRegular, kBda };
58 
59  // Predefined fields values, that can be OR'd together:
60  static constexpr dp3::common::Fields kDataField{
62  static constexpr dp3::common::Fields kFlagsField{
66  static constexpr dp3::common::Fields kUvwField{
68 
69  Step();
70  virtual ~Step();
71 
76  virtual bool process(std::unique_ptr<base::DPBuffer> buffer) {
77  throw std::runtime_error("Step does not support regular data processing.");
78  }
79 
83  virtual bool process(std::unique_ptr<base::BdaBuffer>) {
84  throw std::runtime_error("Step does not support BDA data processing.");
85  }
86 
88  virtual void finish() = 0;
89 
92 
97 
100  void setInfo(const base::DPInfo&);
101 
104  virtual void updateInfo(const base::DPInfo&);
105 
107  const base::DPInfo& getInfoIn() const { return input_info_; }
108 
110  const base::DPInfo& getInfoOut() const { return output_info_; }
111 
113  virtual void show(std::ostream&) const = 0;
114 
117  virtual void showCounts(std::ostream&) const;
118 
121  virtual void showTimings(std::ostream&, double duration) const;
122 
124  void setPrevStep(Step* prevStep) { previous_step_ = prevStep; }
125 
127  Step* getPrevStep() const { return previous_step_; }
128 
130  virtual void setNextStep(Step::ShPtr nextStep) {
131  next_step_ = std::move(nextStep);
132  next_step_->setPrevStep(this);
133  }
134 
136  const Step::ShPtr& getNextStep() const { return next_step_; }
137 
139  virtual MsType outputs() const { return MsType::kRegular; }
140 
142  virtual bool accepts(MsType dt) const { return dt == MsType::kRegular; }
143 
152  static void SetThreadingIsInitialized() { threading_is_initialized_ = true; }
153 
154  protected:
156  base::DPInfo& GetWritableInfoOut() { return output_info_; }
157 
160  virtual void addToMS(const std::string& msName);
161 
162  private:
163  std::shared_ptr<Step> next_step_;
164  Step* previous_step_ = nullptr;
166  base::DPInfo input_info_;
167  base::DPInfo output_info_;
168  inline static bool threading_is_initialized_ = false;
169 };
170 
172 class ModelDataStep : public Step {
173  public:
174  common::Fields getProvidedFields() const override { return kDataField; }
175 
177  virtual base::Direction GetFirstDirection() const = 0;
178 };
179 
180 } // namespace steps
181 } // namespace dp3
182 
183 #endif // DP3_STEPS_STEP_H_
Buffer holding baseline-dependently averaged (BDA) data.
Buffer holding the data of a timeslot/band.
General info about DP3 data processing attributes like averaging.
General info about DP3 data processing attributes like averaging.
Definition: DPInfo.h:35
Definition: Fields.h:16
@ kData
Is the visibility data needed?
@ kUvw
Are the uvw needed?
@ kWeights
Are the weights needed?
@ kFlags
Are the flags needed?
Common interface for steps that produce model data.
Definition: Step.h:172
common::Fields getProvidedFields() const override
Definition: Step.h:174
virtual base::Direction GetFirstDirection() const =0
Abstract base class for a DP3 step.
Definition: Step.h:52
virtual void updateInfo(const base::DPInfo &)
virtual void show(std::ostream &) const =0
Show the step parameters.
virtual bool process(std::unique_ptr< base::BdaBuffer >)
Definition: Step.h:83
virtual void addToMS(const std::string &msName)
virtual void finish()=0
Finish the processing of this step and subsequent steps.
void setInfo(const base::DPInfo &)
static constexpr dp3::common::Fields kWeightsField
Definition: Step.h:64
virtual dp3::common::Fields getProvidedFields() const =0
virtual bool process(std::unique_ptr< base::DPBuffer > buffer)
Definition: Step.h:76
std::shared_ptr< Step > ShPtr
Definition: Step.h:54
base::DPInfo & GetWritableInfoOut()
Definition: Step.h:156
static constexpr dp3::common::Fields kUvwField
Definition: Step.h:66
virtual dp3::common::Fields getRequiredFields() const =0
Get the fields required by the current step.
MsType
To check compatibility between steps before running.
Definition: Step.h:57
void setPrevStep(Step *prevStep)
Set the previous step.
Definition: Step.h:124
virtual void showTimings(std::ostream &, double duration) const
virtual bool accepts(MsType dt) const
Boolean if this step can process this type of data.
Definition: Step.h:142
const Step::ShPtr & getNextStep() const
Get the next step.
Definition: Step.h:136
const base::DPInfo & getInfoIn() const
Get access to the info of the input.
Definition: Step.h:107
virtual MsType outputs() const
Return which datatype this step outputs.
Definition: Step.h:139
virtual void setNextStep(Step::ShPtr nextStep)
Set the next step.
Definition: Step.h:130
static constexpr dp3::common::Fields kDataField
Definition: Step.h:60
static constexpr dp3::common::Fields kFlagsField
Definition: Step.h:62
virtual void showCounts(std::ostream &) const
const base::DPInfo & getInfoOut() const
Get access to the info of the output.
Definition: Step.h:110
static void SetThreadingIsInitialized()
Definition: Step.h:152
Step * getPrevStep() const
Get the previous step.
Definition: Step.h:127
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53
A direction on the celestial sphere.
Definition: Direction.h:15