HOPS
HOPS class reference
MHO_DoubleSidebandChannelLabeler.hh
Go to the documentation of this file.
1 #ifndef MHO_DoubleSidebandChannelLabeler_HH__
2 #define MHO_DoubleSidebandChannelLabeler_HH__
3 
4 #include <map>
5 #include <stack>
6 #include <string>
7 
8 #include "MHO_Message.hh"
9 
10 #include "MHO_EncodeDecodeValue.hh"
11 
13 #include "MHO_TableContainer.hh"
14 #include "MHO_UnaryOperator.hh"
15 
16 namespace hops
17 {
18 
32 template< typename XArrayType > class MHO_DoubleSidebandChannelLabeler: public MHO_UnaryOperator< XArrayType >
33 {
34  public:
36  {
37  fEps = 1e-6; //tolerance (MHz) when checking if channels share a sky freq
38  };
39 
41 
42  //allow channel freq association to use a difference tolerance
48  void SetTolerance(double tol) { fEps = tol; }
49 
50  protected:
58  virtual bool InitializeInPlace(XArrayType* in) override { return true; }
59 
68  virtual bool InitializeOutOfPlace(const XArrayType* , XArrayType* ) override { return true; }
69 
77  virtual bool ExecuteInPlace(XArrayType* in) override
78  {
79  if(in != nullptr)
80  {
81  //need to use the user provided frequency <-> channel label map
82  auto chan_ax = &(std::get< CHANNEL_AXIS >(*in));
83  std::size_t nchans = chan_ax->GetSize();
84 
85  int double_sideband_pair_counter = 0; //count unique double-sideband pairs
86  for(std::size_t ch = 0; ch < nchans - 1; ch++)
87  {
88  std::size_t next_ch = ch + 1;
89  double f1 = chan_ax->at(ch);
90  double f2 = chan_ax->at(next_ch);
91 
92  double bw1 = 0;
93  double bw2 = 0;
94  bool bw1_present = chan_ax->RetrieveIndexLabelKeyValue(ch, "bandwidth", bw1);
95  bool bw2_present = chan_ax->RetrieveIndexLabelKeyValue(next_ch, "bandwidth", bw2);
96 
97  if(std::abs(f1 - f2) < fEps && std::abs(bw1 - bw2) < fEps)
98  {
99  //sky frequencies of these two channels are the same
100  //now check if they are a LSB/USB pair
101  std::string nsb1 = "";
102  std::string nsb2 = "";
103  bool nsb1_present = chan_ax->RetrieveIndexLabelKeyValue(ch, "net_sideband", nsb1);
104  bool nsb2_present = chan_ax->RetrieveIndexLabelKeyValue(next_ch, "net_sideband", nsb2);
105 
106  if(nsb1_present && nsb2_present)
107  {
108  //1st channel is LSB, 2nd channel is USB --> we have a 'double-sideband' channel
109  //note: we ignore the oddball case where U and L are inverted
110  if(nsb1 == "L" && nsb2 == "U")
111  {
112  bool value = true;
113  chan_ax->InsertIntervalLabelKeyValue(ch, next_ch, "double_sideband", value);
114 
115  //make sure each channel has a reference to index of the other via a RELATIVE offset
116  chan_ax->InsertIndexLabelKeyValue(ch, "dsb_partner", 1);
117  chan_ax->InsertIndexLabelKeyValue(next_ch, "dsb_partner", -1);
118  }
119  double_sideband_pair_counter++;
120  }
121  }
122  }
123  return true;
124  }
125  return false;
126  }
127 
136  virtual bool ExecuteOutOfPlace(const XArrayType* in, XArrayType* out) override
137  {
138  out->Copy(*in);
139  return ExecuteInPlace(out);
140  }
141 
142  private:
143  double fEps;
144 };
145 
146 } // namespace hops
147 
148 #endif
Class MHO_DoubleSidebandChannelLabeler.
Definition: MHO_DoubleSidebandChannelLabeler.hh:33
virtual bool InitializeOutOfPlace(const XArrayType *, XArrayType *) override
Initializes output array in-place from input array.
Definition: MHO_DoubleSidebandChannelLabeler.hh:68
virtual ~MHO_DoubleSidebandChannelLabeler()
Definition: MHO_DoubleSidebandChannelLabeler.hh:40
void SetTolerance(double tol)
Setter for tolerance - in (MHz) when checking if channels share a sky freq.
Definition: MHO_DoubleSidebandChannelLabeler.hh:48
virtual bool InitializeInPlace(XArrayType *in) override
Initializes XArrayType in-place and returns success.
Definition: MHO_DoubleSidebandChannelLabeler.hh:58
virtual bool ExecuteOutOfPlace(const XArrayType *in, XArrayType *out) override
Copies input array to output and executes in-place operation on output.
Definition: MHO_DoubleSidebandChannelLabeler.hh:136
virtual bool ExecuteInPlace(XArrayType *in) override
Function ExecuteInPlace labels LSB/USB channel pairs as "double sideband" channels if they share and ...
Definition: MHO_DoubleSidebandChannelLabeler.hh:77
MHO_DoubleSidebandChannelLabeler()
Definition: MHO_DoubleSidebandChannelLabeler.hh:35
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_ChannelLabeler.hh:17
Definition: vex.h:175