Psyllid  v1.12.4
Project 8 Data Acquisisition Software
frequency_mask_trigger.hh
Go to the documentation of this file.
1 /*
2  * frequency_mask_trigger.hh
3  *
4  * Created on: Feb 8, 2016
5  * Author: nsoblath
6  */
7 
8 #ifndef PSYLLID_FREQUENCY_MASK_TRIGGER_HH_
9 #define PSYLLID_FREQUENCY_MASK_TRIGGER_HH_
10 
11 #include "transformer.hh"
12 
13 #include "freq_data.hh"
14 #include "node_builder.hh"
15 #include "trigger_flag.hh"
16 
17 #include "member_variables.hh"
18 
19 #include <mutex>
20 #include <vector>
21 
22 #include <cmath>
23 
24 namespace psyllid
25 {
26 
84  public midge::_transformer< midge::type_list< freq_data >, midge::type_list< trigger_flag > >
85  {
86  public:
87  enum class status_t
88  {
91  };
92 
93  enum class trigger_mode_t
94  {
95  single_level,
96  two_level
97  };
98  static uint32_t trigger_mode_to_uint( trigger_mode_t a_trigger_mode );
99  static trigger_mode_t uint_to_trigger_mode( uint32_t a_trigger_mode_uint );
100  static std::string trigger_mode_to_string( trigger_mode_t a_trigger_mode );
101  static trigger_mode_t string_to_trigger_mode( const std::string& a_trigger_mode );
102 
103  enum class threshold_t:uint32_t
104  {
105  snr,
106  sigma
107  };
108  static uint32_t threshold_to_uint( threshold_t a_threshold );
109  static threshold_t uint_to_threshold( uint32_t a_threshold_uint );
110  static std::string threshold_to_string( threshold_t a_threshold );
111  static threshold_t string_to_threshold( const std::string& a_threshold_string );
112 
113 
114  public:
116  virtual ~frequency_mask_trigger();
117 
118  void set_n_packets_for_mask( unsigned a_n_pkts );
119 
120  void set_threshold_ampl_snr( double a_ampl_snr );
121  void set_threshold_power_snr( double a_power_snr );
122  void set_threshold_power_snr_high( double a_power_snr);
123  void set_threshold_power_sigma( double a_power_sigma );
124  void set_threshold_power_sigma_high( double a_power_sigma);
125  void set_threshold_dB( double a_dB );
126  void set_trigger_mode( const std::string& a_trigger_mode );
127  void set_threshold_type( const std::string& a_threshold_type );
128  std::string get_trigger_mode_str() const;
129  std::string get_threshold_type_str() const;
130 
131  void calculate_snr_mask_spline_points(std::vector< double >& t_x_vals, std::vector< double >& t_y_vals, double threshold);
132  void calculate_sigma_mask_spline_points(std::vector< double >& t_x_vals, std::vector< double >& t_y_vals, double threshold);
133 
134  void set_mask_parameters_from_node( const scarab::param_node& a_mask_and_data_values );
135 
136  mv_accessible( uint64_t, length );
137  mv_accessible_noset( unsigned, n_packets_for_mask );
138  mv_accessible( double, threshold_snr );
139  mv_accessible( double, threshold_snr_high);
140  mv_accessible( double, threshold_sigma );
141  mv_accessible( double, threshold_sigma_high);
142  mv_accessible( threshold_t, threshold_type);
143  mv_accessible( unsigned, n_spline_points );
144  mv_accessible_noset( status_t, status );
145  mv_accessible( trigger_mode_t, trigger_mode );
146  mv_accessible( unsigned, n_excluded_bins );
147 
148  public:
149  void switch_to_update_mask();
151 
152  void write_mask( const std::string& a_filename );
153 
154  void initialize();
155  void execute( midge::diptera* a_midge = nullptr );
156  void finalize();
157 
158  private:
160  {
161  midge::diptera* f_midge;
163  midge::enum_t f_in_command;
164  };
165 
166  void exe_apply_threshold( exe_func_context& a_ctx );
168  void exe_add_to_mask( exe_func_context& a_ctx );
169 
171  std::mutex f_exe_func_mutex;
172  std::atomic< bool > f_break_exe_func;
173 
174  private:
175  std::vector< double > f_mask;
176  std::vector< double > f_mask2;
177  std::vector< double > f_average_data;
178  std::vector< double > f_variance_data;
179  unsigned f_n_summed;
180 
181  std::mutex f_mask_mutex;
182 
183  };
184 
186  {
187  return static_cast< uint32_t >( a_trigger_mode );
188  }
190  {
191  return static_cast< frequency_mask_trigger::trigger_mode_t >( a_trigger_mode_uint );
192  }
193 
195  {
196  return static_cast< uint32_t >( a_threshold );
197  }
199  {
200  return static_cast< frequency_mask_trigger::threshold_t >( a_threshold_uint );
201  }
202 
203  inline void frequency_mask_trigger::set_trigger_mode( const std::string& a_trigger_mode )
204  {
205  set_trigger_mode( string_to_trigger_mode( a_trigger_mode ) );
206  }
207 
208  inline void frequency_mask_trigger::set_threshold_type( const std::string& a_threshold_type )
209  {
210  set_threshold_type( string_to_threshold( a_threshold_type ) );
211  }
212 
214  {
215  return trigger_mode_to_string( f_trigger_mode );
216  }
217 
219  {
220  return threshold_to_string( f_threshold_type );
221  }
222 
223  class frequency_mask_trigger_binding : public _node_binding< frequency_mask_trigger, frequency_mask_trigger_binding >
224  {
225  public:
228 
229  private:
230  virtual void do_apply_config( frequency_mask_trigger* a_node, const scarab::param_node& a_config ) const;
231  virtual void do_dump_config( const frequency_mask_trigger* a_node, scarab::param_node& a_config ) const;
232 
233  virtual bool do_run_command( frequency_mask_trigger* a_node, const std::string& a_cmd, const scarab::param_node& a_args ) const;
234  };
235 
236 
237 } /* namespace psyllid */
238 
239 #endif /* PSYLLID_FREQUENCY_MASK_TRIGGER_HH_ */
void calculate_sigma_mask_spline_points(std::vector< double > &t_x_vals, std::vector< double > &t_y_vals, double threshold)
static threshold_t uint_to_threshold(uint32_t a_threshold_uint)
static uint32_t threshold_to_uint(threshold_t a_threshold)
void exe_add_to_mask(exe_func_context &a_ctx)
void set_threshold_power_sigma_high(double a_power_sigma)
static std::string trigger_mode_to_string(trigger_mode_t a_trigger_mode)
static uint32_t trigger_mode_to_uint(trigger_mode_t a_trigger_mode)
void set_threshold_ampl_snr(double a_ampl_snr)
static trigger_mode_t uint_to_trigger_mode(uint32_t a_trigger_mode_uint)
void set_mask_parameters_from_node(const scarab::param_node &a_mask_and_data_values)
void write_mask(const std::string &a_filename)
void set_threshold_power_snr_high(double a_power_snr)
void(frequency_mask_trigger::* f_exe_func)(exe_func_context &a_ctx)
static std::string threshold_to_string(threshold_t a_threshold)
void set_n_packets_for_mask(unsigned a_n_pkts)
static trigger_mode_t string_to_trigger_mode(const std::string &a_trigger_mode)
void exe_apply_threshold(exe_func_context &a_ctx)
void set_threshold_power_snr(double a_power_snr)
void calculate_snr_mask_spline_points(std::vector< double > &t_x_vals, std::vector< double > &t_y_vals, double threshold)
void set_threshold_type(const std::string &a_threshold_type)
static threshold_t string_to_threshold(const std::string &a_threshold_string)
void set_trigger_mode(const std::string &a_trigger_mode)
void exe_apply_two_thresholds(exe_func_context &a_ctx)
void set_threshold_power_sigma(double a_power_sigma)
void execute(midge::diptera *a_midge=nullptr)