HOPS
HOPS class reference
MHO_PolarizationRelabeler.hh
Go to the documentation of this file.
1 #ifndef MHO_PolarizationRelabeler_HH__
2 #define MHO_PolarizationRelabeler_HH__
3 
4 #include <map>
5 #include <stack>
6 #include <string>
7 
8 #include "MHO_Message.hh"
9 
11 #include "MHO_TableContainer.hh"
12 #include "MHO_UnaryOperator.hh"
13 
14 namespace hops
15 {
16 
28 template< typename XArrayType > class MHO_PolarizationRelabeler: public MHO_UnaryOperator< XArrayType >
29 {
30  public:
32  {
33  fStationKey = "station_code";
34  fStationMk4IDKey = "station_mk4id";
35  fPol1 = "";
36  fPol2 = "";
37  fValid = false;
38  };
39 
41 
42  void SetPolarizationSwapPair(std::string pol1, std::string pol2)
43  {
44  //set the polarization labels to swap, all instances of pol1 will be replaced by pol2
45  //and all instances of pol2 will be replaced with pol1
46  if(pol1.size() == 1 && pol2.size() == 1)
47  {
48  fPol1 = pol1;
49  fPol2 = pol2;
50  fValid = true;
51  }
52  else
53  {
54  fValid = false;
55  msg_error("calibration",
56  "MHO_PolarizationRelabeler, only single character polarization labels are supported, ignoring."
57  << eom);
58  }
59  }
60 
69  void SetStationIdentifier(const std::string& id) { fStationIdentities = {id}; }
70 
71  void SetStationIdentifiers(const std::vector< std::string >& ids) { fStationIdentities = ids; }
72 
73  std::string GetStationIdentifier() const
74  {
75  return fStationIdentities.empty() ? std::string("") : fStationIdentities[0];
76  }
77 
78  protected:
86  virtual bool ExecuteInPlace(XArrayType* in) override
87  {
88  if(in != nullptr)
89  {
90  //need to use the user provided frequency <-> channel label map
91  auto pol_axis_ptr = &(std::get< MTPCAL_POL_AXIS >(*in));
92  std::size_t npols = pol_axis_ptr->GetSize();
93  if(IsApplicable(in))
94  {
95  for(std::size_t i = 0; i < npols; i++)
96  {
97  //swap any instances of pol1 <-> pol2
98  std::string pol = pol_axis_ptr->at(i);
99  if(pol == fPol1)
100  {
101  pol = fPol2;
102  }
103  else if(pol == fPol2)
104  {
105  pol = fPol1;
106  }
107  pol_axis_ptr->at(i) = pol;
108  }
109  }
110  }
111  return false;
112  }
113 
114  private:
115  //keys for tag retrieval
116  std::string fStationKey;
117  std::string fStationMk4IDKey;
118 
119  //data
120  std::vector< std::string > fStationIdentities;
121  std::string fPol1;
122  std::string fPol2;
123  bool fValid;
124 
125  //determines if to apply the pol relabelling to this pcal data container
126  bool IsApplicable(const XArrayType* in)
127  {
128  std::string mk4id_val, code_val;
129  in->Retrieve(fStationMk4IDKey, mk4id_val);
130  in->Retrieve(fStationKey, code_val);
131 
132  for(const auto& id : fStationIdentities)
133  {
134  if(id.size() > 2)
135  {
136  msg_error("calibration",
137  "station identity: " << id << " is not a recognizable mark4 or 2-character code" << eom);
138  continue;
139  }
140  if(id.size() == 1 && (id == mk4id_val || id == "?"))
141  {
142  return true;
143  }
144  if(id.size() == 2 && (id == code_val || id == "??"))
145  {
146  return true;
147  }
148  }
149  return false;
150  }
151 };
152 
153 } // namespace hops
154 
155 #endif
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_PolarizationRelabeler.
Definition: MHO_PolarizationRelabeler.hh:29
MHO_PolarizationRelabeler()
Definition: MHO_PolarizationRelabeler.hh:31
void SetStationIdentifier(const std::string &id)
Setter for station identifier.
Definition: MHO_PolarizationRelabeler.hh:69
virtual ~MHO_PolarizationRelabeler()
Definition: MHO_PolarizationRelabeler.hh:40
std::string GetStationIdentifier() const
Definition: MHO_PolarizationRelabeler.hh:73
void SetStationIdentifiers(const std::vector< std::string > &ids)
Definition: MHO_PolarizationRelabeler.hh:71
void SetPolarizationSwapPair(std::string pol1, std::string pol2)
Definition: MHO_PolarizationRelabeler.hh:42
virtual bool ExecuteInPlace(XArrayType *in) override
Function ExecuteInPlace - attaches channel labels based on sky frequency or user specified map.
Definition: MHO_PolarizationRelabeler.hh:86
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_AdhocFlagging.hh:18