18 #include <sys/types.h> 33 f_transform_flag(
"ESTIMATE" ),
35 f_wisdom_filename(
"wisdom_complexfft.fftw3" ),
36 f_enable_time_output( true ),
37 f_transform_flag_map(),
41 f_multithreaded_is_initialized( false )
52 LDEBUG(
plog,
"switching to frequency output only mode" );
58 LDEBUG(
plog,
"switching to frequency and time output mode" );
69 unsigned transform_flag = iter->second;
71 f_fftw_input = (fftw_complex*) fftw_malloc(
sizeof(fftw_complex) * f_fft_size);
72 f_fftw_output = (fftw_complex*) fftw_malloc(
sizeof(fftw_complex) * f_fft_size);
75 LDEBUG(
plog,
"Reading wisdom from file <" << f_wisdom_filename <<
">");
76 if (fftw_import_wisdom_from_filename(f_wisdom_filename.c_str()) == 0)
78 LWARN(
plog,
"Unable to read FFTW wisdom from file <" << f_wisdom_filename <<
">" );
86 fftw_plan_with_nthreads(FFTW_NTHREADS);
87 LDEBUG(
plog,
"Configuring FFTW to use up to " << FFTW_NTHREADS <<
" threads.");
98 if (fftw_export_wisdom_to_filename(f_wisdom_filename.c_str()) == 0)
100 LWARN(
plog,
"Unable to write FFTW wisdom to file<" << f_wisdom_filename <<
">");
103 LDEBUG(
plog,
"FFTW plan created; initialization complete" );
113 LDEBUG(
plog,
"Executing the frequency transformer" );
118 double fft_norm = sqrt(1. / (
double)f_fft_size);
122 LINFO(
plog,
"Starting main loop (frequency transform)" );
123 while (! is_canceled() )
128 LWARN(
plog,
"time output stream has stop condition" );
131 if (out_stream< 1 >().
get() == stream::s_stop)
133 LWARN(
plog,
"frequency output stream has stop condition" );
137 midge::enum_t in_cmd = stream::s_none;
138 in_cmd = in_stream< 0 >().
get();
139 if ( in_cmd == stream::s_none)
143 if ( in_cmd == stream::s_error )
145 LDEBUG(
plog,
"got an s_error on slot <" << in_stream< 0 >().get_current_index() <<
">" );
148 if ( in_cmd == stream::s_exit )
150 LDEBUG(
plog,
"got an s_exit on slot <" << in_stream< 0 >().get_current_index() <<
">" );
153 if ( in_cmd == stream::s_stop )
155 LDEBUG(
plog,
"got an s_stop on slot <" << in_stream< 0 >().get_current_index() <<
">" );
156 if (
f_enable_time_output && ! out_stream< 0 >().
set( stream::s_stop ) )
throw midge::node_nonfatal_error() <<
"Stream 0 error while stopping";
157 if ( ! out_stream< 1 >().
set( stream::s_stop ) )
throw midge::node_nonfatal_error() <<
"Stream 1 error while stopping";
160 if ( in_cmd == stream::s_start )
162 LDEBUG(
plog,
"got an s_start on slot <" << in_stream< 0 >().get_current_index() <<
">" );
163 if (
f_enable_time_output && ! out_stream< 0 >().
set( stream::s_start ) )
throw midge::node_nonfatal_error() <<
"Stream 0 error while starting";
164 if ( ! out_stream< 1 >().
set( stream::s_start ) )
throw midge::node_nonfatal_error() <<
"Stream 1 error while starting";
167 if ( in_cmd == stream::s_run )
169 LDEBUG(
plog,
"got an s_run on slot <" << in_stream< 0 >().get_current_index() <<
">" );
170 time_data_in = in_stream< 0 >().data();
175 time_data_out = out_stream< 0 >().data();
176 *time_data_out = *time_data_in;
179 freq_data_out = out_stream< 1 >().data();
182 LDEBUG(
plog,
"next steams acquired, doing FFT" );
186 for (
size_t i_bin=0; i_bin<f_fft_size; ++i_bin)
197 freq_data_out->set_pkt_in_session(time_data_in->get_pkt_in_session());
201 LERROR(
plog,
"frequency_transform error setting time output stream to s_run" );
204 if ( !out_stream< 1 >().
set( stream::s_run ) )
206 LERROR(
plog,
"frequency_transform error setting frequency output stream to s_run" );
217 LINFO(
plog,
"FREQUENCY TRANSFORM is exiting" );
220 LDEBUG(
plog,
"Stopping output streams" );
222 bool t_f_stop_ok = out_stream< 1 >().
set( stream::s_stop );
223 if( ! t_t_stop_ok && ! t_f_stop_ok)
return;
225 LDEBUG(
plog,
"Exiting output streams" );
226 out_stream< 0 >().
set( stream::s_exit );
227 out_stream< 1 >().
set( stream::s_exit );
233 if( a_midge ) a_midge->throw_ex( std::current_exception() );
279 LDEBUG(
plog,
"Configuring frequency_transform with:\n" << a_config );
280 a_node->set_time_length( a_config.get_value(
"time-length", a_node->get_time_length() ) );
281 a_node->set_freq_length( a_config.get_value(
"freq-length", a_node->get_freq_length() ) );
282 a_node->set_fft_size( a_config.get_value(
"fft-size", a_node->get_fft_size() ) );
283 a_node->set_transform_flag( a_config.get_value(
"transform-flag", a_node->get_transform_flag() ) );
284 a_node->set_use_wisdom( a_config.get_value(
"use-wisdom", a_node->get_use_wisdom() ) );
285 a_node->set_wisdom_filename( a_config.get_value(
"wisdom-filename", a_node->get_wisdom_filename() ) );
291 LDEBUG(
plog,
"Dumping frequency_transform configuration" );
292 a_config.add(
"time-length", scarab::param_value( a_node->get_time_length() ) );
293 a_config.add(
"freq-length", scarab::param_value( a_node->get_freq_length() ) );
294 a_config.add(
"fft-size", scarab::param_value( a_node->get_fft_size() ) );
295 a_config.add(
"transform-flag", scarab::param_value( a_node->get_transform_flag() ) );
296 a_config.add(
"use-wisdom", scarab::param_value( a_node->get_use_wisdom() ) );
297 a_config.add(
"wisdom-filename", scarab::param_value( a_node->get_wisdom_filename() ) );
303 if ( a_cmd ==
"freq-only" )
305 LDEBUG(
plog,
"should enable freq-only mode" );
309 else if ( a_cmd ==
"time-and-freq" )
311 LDEBUG(
plog,
"should enable time-and-freq mode" );
317 LWARN(
plog,
"unrecognized command: <" << a_cmd <<
">" );
void set_freq_not_time(bool a_flag)
static scarab::logger plog("batch_executor")
const iq_t * get_array() const
void set_pkt_in_batch(uint32_t a_pkt)
size_t get_array_size() const
uint32_t get_pkt_in_batch() const
REGISTER_NODE_AND_BUILDER(data_producer, "data-producer", data_producer_binding)
LOGGER(plog, "egg_writer")
const iq_t * get_array() const