HOPS
HOPS class reference
MHO_MK4StationInterface.hh
Go to the documentation of this file.
1 #ifndef MHO_MK4StationInterface_HH__
2 #define MHO_MK4StationInterface_HH__
3 
4 #include <cstdlib>
5 #include <cstring>
6 #include <map>
7 #include <set>
8 #include <string>
9 #include <vector>
10 
12 #include "MHO_MK4VexInterface.hh"
13 
14 #include "MHO_Message.hh"
15 
16 //forward declaration of mk4_corel and vex structs
17 //we do this to keep the mk4 structures from 'leaking' into the new code via includes,
18 //We want to make sure any interface to the old mk4 IO libraries is kept only
19 //within the MK4Interface library (and primarily in the .cc files).
20 #ifndef HOPS3_USE_CXX
21 extern "C"
22 {
23 #endif
27  struct mk4_sdata;
31  struct type_309;
32 #ifndef HOPS3_USE_CXX
33 }
34 #endif
35 
36 namespace hops
37 {
38 
48 {
49  public:
51  virtual ~MHO_MK4StationInterface();
52 
58  void SetVexFile(const std::string& vex) { fVexFile = vex; }
59 
65  void SetStationFile(const std::string& station) { fStationFile = station; }
66 
72  mk4_sdata* GetStationData() { return fStation; };
73 
80 
86  multitone_pcal_type* GetPCalObject() { return &fAllPCalData; }
87 
88  private:
96  std::string getstr(const char* char_array, std::size_t max_size)
97  {
98  return std::string(char_array, std::min(strlen(char_array), max_size));
99  }
100 
104  void ReadStationFile();
108  void ReadVexFile();
109 
110  //pcal stuff
117  void ExtractPCal(int n309, type_309** t309);
127  void FillPCalArray(const std::string& pol, int pol_idx, multitone_pcal_type* pc, int n309, type_309** t309);
128 
129  //builds a visibility channel axis from the ovex info for each pol
135  std::map< std::string, channel_axis_type > ConstructPerPolChannelAxis();
136 
142  std::map< std::string, std::vector< mho_json > > ConstructChannelInfo();
143 
144  //converts a mk4 channel id into its components, returns true if successful
155  bool ExtractChannelInfo(const std::string& ch_name, std::string& fgroup, std::string& sb, std::string& pol, int& index);
162  std::string FreqGroupFromMK4ChannelID(std::string id) const;
169  std::string PolFromMK4ChannelID(std::string id) const;
176  std::string SidebandFromMK4ChannelId(std::string id) const;
183  int IndexFromMK4ChannelId(std::string id) const;
184 
185  //converts uint32_t counts to complex double
195  std::complex< double > ComputePhasor(uint32_t real, uint32_t imag, double acc_period, double sample_period);
196 
197  //returns a vector of freq group codes found in the 309 data
198  std::vector< std::string > GetFreqGroups(int n309, type_309** t309);
199  //returns a vector of pols and tone-count for each pol found in 309 data
200  std::vector< std::pair< std::string, int > > GetFreqGroupPolInfo(int n309, type_309** t309, const std::string& fg,
201  bool& same_size);
202 
203  bool fHaveStation;
204  struct mk4_sdata* fStation;
205  std::string fStationName;
206  std::string fStationCode;
207  std::string fStationMK4ID;
208 
209  //all pcal data
210  multitone_pcal_type fAllPCalData;
211 
212  std::string fStationFile;
213  std::string fVexFile;
214  std::string fRootCode;
215  std::size_t fNCoeffs;
216  std::size_t fNIntervals;
217  std::size_t fNCoord;
218 
219  //vex info
220  bool fHaveVex;
221  mho_json fVex;
222 
223  //comparison predicate for sorting channel frequency info
224  struct ChannelLess
225  {
226  bool operator()(const mho_json& a, const mho_json& b) const
227  {
228  double a_freq = a["sky_freq"].get< double >();
229  double b_freq = b["sky_freq"].get< double >();
230  double a_bw = a["bandwidth"].get< double >();
231  double b_bw = b["bandwidth"].get< double >();
232  std::string a_sb = a["net_sideband"].get< std::string >();
233  std::string b_sb = b["net_sideband"].get< std::string >();
234 
235  double a_sgn = 0;
236  if(a_sb == "L")
237  {
238  a_sgn = -1.0;
239  }
240  if(a_sb == "U")
241  {
242  a_sgn = 1.0;
243  }
244 
245  double b_sgn = 0;
246  if(b_sb == "L")
247  {
248  b_sgn = -1.0;
249  }
250  if(b_sb == "U")
251  {
252  b_sgn = 1.0;
253  }
254 
255  double a_center_freq = a_freq + a_bw * a_sgn / 2.0;
256  double b_center_freq = b_freq + b_bw * b_sgn / 2.0;
257 
258  return a_center_freq < b_center_freq;
259  }
260  };
261 
262  ChannelLess fChannelPredicate;
263 };
264 
265 } // namespace hops
266 
267 #endif
nlohmann::json mho_json
Definition: MHO_JSONHeaderWrapper.hh:5
MHO_MK4StationInterface converts a mk4 station file (type_3xx) to HOPS4 format.
Definition: MHO_MK4StationInterface.hh:48
MHO_MK4StationInterface()
Definition: MHO_MK4StationInterface.cc:37
void SetVexFile(const std::string &vex)
Setter for vex file.
Definition: MHO_MK4StationInterface.hh:58
station_coord_type * ExtractStationFile()
Extracts station coordinate data from files and allocates memory for it.
Definition: MHO_MK4StationInterface.cc:69
mk4_sdata * GetStationData()
Getter for station data.
Definition: MHO_MK4StationInterface.hh:72
virtual ~MHO_MK4StationInterface()
Definition: MHO_MK4StationInterface.cc:47
void SetStationFile(const std::string &station)
Setter for station file.
Definition: MHO_MK4StationInterface.hh:65
multitone_pcal_type * GetPCalObject()
Getter for pcal object.
Definition: MHO_MK4StationInterface.hh:86
Class MHO_TableContainer.
Definition: MHO_TableContainer.hh:36
#define min(a, b)
Definition: max555.c:9
Definition: mk4_data.h:108
Definition: MHO_AdhocFlagging.hh:18
MHO_TableContainer< pcal_phasor_type, multitone_pcal_axis_type > multitone_pcal_type
Definition: MHO_StationContainers.hh:30
Definition: type_309.h:34
Definition: vex.h:28