HOPS
HOPS class reference
MHO_AdhocFlagging.hh
Go to the documentation of this file.
1 #ifndef MHO_AdhocFlagging_HH__
2 #define MHO_AdhocFlagging_HH__
3 
4 #include <array>
5 #include <cstdint>
6 #include <string>
7 #include <vector>
8 
9 #include "MHO_Clock.hh"
10 #include "MHO_Message.hh"
11 
13 #include "MHO_ParameterStore.hh"
14 #include "MHO_TableContainer.hh"
15 #include "MHO_UnaryOperator.hh"
16 
17 namespace hops
18 {
19 
53 class MHO_AdhocFlagging: public MHO_UnaryOperator< weight_type >
54 {
55  public:
57  virtual ~MHO_AdhocFlagging();
58 
63  void SetRefFlagFile(const std::string& filename) { fFlagFile[0] = filename; }
64 
69  void SetRemFlagFile(const std::string& filename) { fFlagFile[1] = filename; }
70 
74  const std::string& GetRefFlagFile() const { return fFlagFile[0]; }
75 
79  const std::string& GetRemFlagFile() const { return fFlagFile[1]; }
80 
85  void SetParameterStore(MHO_ParameterStore* pstore) { fParameterStore = pstore; }
86 
87  protected:
88  virtual bool InitializeInPlace(weight_type* in) override;
89  virtual bool InitializeOutOfPlace(const weight_type* in, weight_type* out) override;
90  virtual bool ExecuteInPlace(weight_type* in) override;
91 
92  private:
93  // Maximum number of frequency channels encoded per flag file row.
94  static constexpr std::size_t MAX_FLAG_FREQS = 64;
95 
96  // Bit masks for USB/LSB channel retention checks.
97  //
98  // NOTE: These follow the *legacy fourfit (adhoc_flag.c) convention*,
99  // where the C variable names are inverted relative to the flag-file
100  // bit-assignment documentation:
101  // doc bit layout (msb->lsb): USB-RL,LSB-RL,USB-LR,LSB-LR,USB-RR,LSB-RR,USB-LL,LSB-LL
102  // doc USB bits: 0xAA (bits 7,5,3,1), doc LSB bits: 0x55 (bits 6,4,2,0)
103  //
104  // However in the legacy code:
105  // usb_flag = ref & rem & 0x55 (tests the doc-LSB bits to gate USB data)
106  // lsb_flag = ref & rem & 0xAA (tests the doc-USB bits to gate LSB data)
107  //
108  // We preserve this inversion so that existing flag files, which were
109  // written to match the legacy tool's behavior, continue to work correctly.
110  //
111  // Practical effect: a flag byte of 0x80 zeros USB channels and retains LSB,
112  // even though bit 7 is labelled "USB-RL" in the documentation.
113  static constexpr uint8_t USB_MASK = 0x55u; // legacy "usb_flag" mask
114  static constexpr uint8_t LSB_MASK = 0xAAu; // legacy "lsb_flag" mask
115 
116  struct FlagTableRow
117  {
118  double time_fpday;
119  std::array< uint8_t, MAX_FLAG_FREQS > bytes;
120  };
121 
132  static void DecodeHexToken(const char* hex_token, std::array< uint8_t, MAX_FLAG_FREQS >& bytes);
133 
140  bool LoadFlagFile(std::size_t stn_idx);
141 
154  const uint8_t* LookupFlagBytes(std::size_t stn_idx, double ap_center_fpday) const;
155 
156  // Optional parameter store for updating /fringe/total_summed_weights
157  MHO_ParameterStore* fParameterStore;
158 
159  // Flag file paths: [0] = ref, [1] = rem
160  std::string fFlagFile[2];
161 
162  // Parsed flag tables: [0] = ref, [1] = rem
163  std::vector< FlagTableRow > fFlagTable[2];
164 
165  // Scan timing (filled during InitializeInPlace)
166  double fScanStartFpDay; // scan start as fractional days since BOY
167  int fScanYear; // year of scan start
168  double fAccPeriod; // accumulation period in seconds
169 
170  // Metadata key names
171  std::string fStartKey; // "start"
172  std::string fSidebandKey; // "net_sideband"
173 };
174 
175 } // namespace hops
176 
177 #endif
Port of the legacy fourfit adhoc_flag() capability into the HOPS4 calibration operator framework.
Definition: MHO_AdhocFlagging.hh:54
void SetParameterStore(MHO_ParameterStore *pstore)
Provide a parameter store so the operator can update /fringe/total_summed_weights after zeroing flagg...
Definition: MHO_AdhocFlagging.hh:85
virtual bool InitializeOutOfPlace(const weight_type *in, weight_type *out) override
Definition: MHO_AdhocFlagging.cc:252
virtual ~MHO_AdhocFlagging()
Definition: MHO_AdhocFlagging.cc:41
MHO_AdhocFlagging()
Definition: MHO_AdhocFlagging.cc:29
void SetRemFlagFile(const std::string &filename)
Set the flag file for the remote station.
Definition: MHO_AdhocFlagging.hh:69
const std::string & GetRemFlagFile() const
Get the flag file path for the remote station.
Definition: MHO_AdhocFlagging.hh:79
virtual bool ExecuteInPlace(weight_type *in) override
Definition: MHO_AdhocFlagging.cc:262
const std::string & GetRefFlagFile() const
Get the flag file path for the reference station.
Definition: MHO_AdhocFlagging.hh:74
virtual bool InitializeInPlace(weight_type *in) override
Definition: MHO_AdhocFlagging.cc:204
void SetRefFlagFile(const std::string &filename)
Set the flag file for the reference station.
Definition: MHO_AdhocFlagging.hh:63
Class MHO_ParameterStore.
Definition: MHO_ParameterStore.hh:52
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_AdhocFlagging.hh:18