5 #ifndef NDS2_CLIENT_NDS_ITERATE_HANDLERS_HH
6 #define NDS2_CLIENT_NDS_ITERATE_HANDLERS_HH
37 template <
typename T >
41 static const T max_val = std::numeric_limits< T >::max( );
42 if ( val2 >= max_val - val1 )
52 auto parent =
conn( );
55 throw std::runtime_error(
"Connection object is null" );
57 parent->next_raw_buffer( output );
61 gps_stop_ = safe_add< NDS::buffer::gps_second_type >(
64 parent->request_end_time( gps_stop_ );
66 if ( !output.empty( ) )
72 parent->cycle_nds1_connection( );
78 buffer::gps_second_type gps_start,
79 buffer::gps_second_type gps_stop,
80 buffer::gps_second_type stride,
81 const connection::channel_names_type& channel_names,
82 std::shared_ptr< NDS::detail::conn_p_type >&& parent )
87 buffer::gps_second_type stop_time =
88 ( parent->protocol == NDS::connection::PROTOCOL_ONE &&
92 parent->issue_iterate(
93 gps_start_, stop_time, stride, channel_names );
148 typedef std::vector< NDS::channel >::const_iterator
166 std::unique_ptr< NDS::detail::delayed_gap_handler > >
176 buffer::gps_second_type gps_time,
177 buffer::gps_second_type stride )
179 if (
bufs_.size( ) != channel_list.size( ) )
181 bufs_.resize( channel_list.size( ) );
184 for (
int i = 0; i < channel_list.size( ); ++i )
186 const NDS::channel& cur_ch = channel_list[ i ];
187 NDS::buffer& cur_buf =
bufs_[ i ];
189 cur_buf.reset_channel_info( cur_ch, gps_time, 0 );
190 if ( cur_ch.Type( ) &
191 NDS::channel::CHANNEL_TYPE_MTREND )
195 static_cast< buffer::size_type >( 60 ) );
199 cur_buf.resize( stride *
200 static_cast< buffer::size_type >(
201 cur_ch.SampleRate( ) ) );
218 if (
bufs_.size( ) == 0 )
241 if (
bufs_.size( ) > 0 )
263 buffer::gps_second_type
273 buffer::gps_second_type
276 if (
bufs_.size( ) == 0 )
280 return bufs_.front( ).Start( );
289 buffer::gps_second_type
292 if (
bufs_.size( ) == 0 )
321 buffer::gps_second_type
328 if ( other.
cur( ) !=
cur( ) )
332 buffer::gps_second_type secs_appended =
333 std::min< buffer::gps_second_type >(
336 buffer::gps_second_type src_offset_sec =
338 buffer::gps_second_type dest_offset_sec =
cur( ) -
start( );
340 for ( buffers_type::size_type i = 0; i <
bufs_.size( );
343 NDS::buffer& src_buf = other.
bufs_[ i ];
344 NDS::buffer& dest_buf =
bufs_[ i ];
346 auto src =
const_cast< char*
>(
347 reinterpret_cast< const char*
>(
348 src_buf.cbegin<
void >( ) ) );
349 src += src_buf.samples_to_bytes(
350 src_buf.seconds_to_samples( src_offset_sec, 0 ) );
351 auto dest =
const_cast< char*
>(
352 reinterpret_cast< const char*
>(
353 dest_buf.cbegin<
void >( ) ) );
354 dest += dest_buf.samples_to_bytes(
355 dest_buf.seconds_to_samples( dest_offset_sec, 0 ) );
357 buffer::size_type copy_bytes = src_buf.samples_to_bytes(
358 src_buf.seconds_to_samples( secs_appended, 0 ) );
359 std::copy( src, src + copy_bytes, dest );
362 other.
advance( secs_appended );
363 return secs_appended;
375 buffer::gps_second_type gps_stop )
377 if ( gps_stop <=
cur_ )
381 buffer::gps_second_type start_time =
start( );
382 if ( gps_stop > start_time +
stride_ )
384 gps_stop = start_time +
stride_;
387 for ( buffers_type::iterator cur_buf =
bufs_.begin( );
388 cur_buf !=
bufs_.end( );
391 std::unique_ptr< detail::delayed_gap_handler >
394 cur_buf->seconds_to_samples(
cur_ -
396 cur_buf->seconds_to_samples( gps_stop -
398 if ( delayed_handler )
400 delay_.push_back( std::move( delayed_handler ) );
409 for ( std::vector< std::unique_ptr<
438 buffer::gps_second_type gps_start,
439 buffer::gps_second_type gps_stop,
440 buffer::gps_second_type stride,
441 const connection::channel_names_type& channel_names,
442 std::shared_ptr< NDS::detail::conn_p_type >&& parent,
443 std::unique_ptr< detail::gap_handler > ghandler )
458 stride_ = parent->calculate_stride(
474 auto parent =
conn( );
477 throw std::out_of_range(
"No Next" );
483 throw std::runtime_error(
484 "Impossible condition triggered, gap "
485 "handled iterator went beyond "
523 parent->next_raw_buffer( tmp );
590 simple_segment_list_type::value_type cur_segment =
594 << cur_segment.gps_start <<
"-"
595 << cur_segment.gps_stop << std::endl;
596 if (
cur_gps_ <= cur_segment.gps_start )
599 buffer::gps_second_type delta =
600 cur_segment.gps_stop - cur_segment.gps_start;
601 buffer::gps_second_type stride =
604 << cur_segment.gps_stop <<
" "
605 << stride << std::endl;
607 cur_segment.gps_stop,
611 else if (
cur_gps_ == cur_segment.gps_stop )
620 simple_segment_list_type::value_type new_segment =
623 buffer::gps_second_type delta =
624 new_segment.gps_stop - new_segment.gps_start;
625 buffer::gps_second_type stride =
628 << new_segment.gps_stop <<
" "
631 new_segment.gps_stop,
643 buffer::gps_second_type gps_start,
644 buffer::gps_second_type gps_stop,
645 buffer::gps_second_type stride,
646 const channel::channel_names_type& channel_names,
647 std::shared_ptr< NDS::detail::conn_p_type >&& parent )
653 if ( parent->protocol == connection::PROTOCOL_ONE ||
658 parent->issue_iterate(
659 gps_start, gps_stop, stride, channel_names );
665 retval.resize( channel_names.size( ) );
666 parent->plan_fetches(
672 throw connection::daq_error(
674 "The requested channels have "
675 "different/non-identical gaps." );
690 auto parent =
conn( );
723 auto parent =
conn( );
726 throw( std::out_of_range(
"No Next" ) );
728 parent->next_raw_buffer( retval );
729 if ( retval.empty( ) )
731 throw( std::out_of_range(
"No Next" ) );
738 output.swap( retval );
766 buffer::gps_second_type gps_start,
767 buffer::gps_second_type gps_stop,
768 buffer::gps_second_type stride,
769 const channel::channel_names_type& channel_names,
772 std::shared_ptr< NDS::detail::conn_p_type >&& parent )
815 auto parent =
conn( );
818 throw std::out_of_range(
"No next buffer" );
824 parent->next_raw_buffer( retval );
829 <<
"Disabling request in progress in order to fetch"
831 parent->request_in_progress(
false );
833 buffer::gps_second_type start =
cur_gps_;
836 buffer::gps_second_type stop = start + stride;
841 stride = stop - start;
845 << stop <<
" ... ) " << std::endl;
860 "request_in_progres enabled"
862 parent->request_in_progress(
true );
865 output.swap( retval );
871 #endif // NDS2_CLIENT_NDS_ITERATE_HANDLERS_HH
virtual DLL_EXPORT std::unique_ptr< delayed_gap_handler > fill_gap(buffer &cur_buffer, buffer::size_type start_sample_offset, buffer::size_type end_sample_offset) const =0
buffer::gps_second_type gps_stride_
Definition: nds_iterate_handlers.hh:758
void advance()
Definition: nds_iterate_handlers.hh:784
void advance(buffer::gps_second_type delta)
Definition: nds_iterate_handlers.hh:304
iterate_available_handler(buffer::gps_second_type gps_start, buffer::gps_second_type gps_stop, buffer::gps_second_type stride, const channel::channel_names_type &channel_names, std::shared_ptr< NDS::detail::conn_p_type > &&parent)
Definition: nds_iterate_handlers.hh:642
Definition: nds_iterate_handler.hh:19
T safe_add(T val1, T val2)
Definition: nds_iterate_handlers.hh:39
indexed_buffers()
Definition: nds_iterate_handlers.hh:169
Definition: nds_iterate_handlers.hh:27
void initialize(const std::vector< NDS::channel > &channel_list, buffer::gps_second_type gps_time, buffer::gps_second_type stride)
Definition: nds_iterate_handlers.hh:175
void next(buffers_type &output) override
Definition: nds_iterate_handlers.hh:809
iterate_handler_with_simple_gaps(buffer::gps_second_type gps_start, buffer::gps_second_type gps_stop, buffer::gps_second_type stride, const connection::channel_names_type &channel_names, std::shared_ptr< NDS::detail::conn_p_type > &&parent, std::unique_ptr< detail::gap_handler > ghandler)
Definition: nds_iterate_handlers.hh:437
std::vector< NDS::channel >::const_iterator ch_vec_const_iter
Definition: nds_iterate_handlers.hh:149
void next(buffers_type &output) override
Definition: nds_iterate_handlers.hh:472
#define DAQD_NOT_FOUND
Definition: daqc_response.h:62
buffers_type bufs_
Definition: nds_iterate_handlers.hh:162
std::ostream & dout()
Definition: debug_stream.cc:23
channels_type channels_
Definition: nds_iterate_handlers.hh:761
buffer::gps_second_type stride_
Definition: nds_iterate_handlers.hh:164
buffer::gps_second_type gps_start_
Definition: nds_iterate_handlers.hh:566
void next(buffers_type &output) override
Definition: nds_iterate_handlers.hh:713
Definition: nds_iterate_handlers.hh:754
buffers_type & bufs()
Definition: nds_iterate_handlers.hh:254
channel::channel_names_type names_
Definition: nds_iterate_handlers.hh:569
~iterate_fast_handler() override=default
void apply_delayed_handlers()
Definition: nds_iterate_handlers.hh:407
buffer::gps_second_type cur_gps_
Definition: nds_iterate_handlers.hh:759
iterate_fast_handler(buffer::gps_second_type gps_start, buffer::gps_second_type gps_stop, buffer::gps_second_type stride, const connection::channel_names_type &channel_names, std::shared_ptr< NDS::detail::conn_p_type > &&parent)
Definition: nds_iterate_handlers.hh:77
buffer::gps_second_type cur_gps_
Definition: nds_iterate_handlers.hh:30
bool online_
Definition: nds_iterate_handlers.hh:34
~iterate_full_handler() override=default
void next(buffers_type &output) override
Definition: nds_iterate_handlers.hh:120
buffer::gps_second_type cur() const
Definition: nds_iterate_handlers.hh:264
buffer::gps_second_type append_data_from(indexed_buffers &other)
Definition: nds_iterate_handlers.hh:322
buffer::gps_second_type gps_stop_
Definition: nds_iterate_handlers.hh:757
std::vector< request_fragment > request_fragments_type
Definition: nds_request_fragment.hh:36
buffer::gps_second_type stride_
Definition: nds_iterate_handlers.hh:33
bool has_next() override
Definition: nds_iterate_handlers.hh:98
iterate_full_handler(buffer::gps_second_type gps_start, buffer::gps_second_type gps_stop, buffer::gps_second_type stride, const channel::channel_names_type &channel_names, epoch prev_epoch, const channels_type &channel_list, std::shared_ptr< NDS::detail::conn_p_type > &&parent)
Definition: nds_iterate_handlers.hh:765
buffer::gps_second_type gps_stop_
Definition: nds_iterate_handlers.hh:32
buffer::gps_second_type gps_start_
Definition: nds_iterate_handlers.hh:425
buffer::gps_second_type gps_stop_
Definition: nds_iterate_handlers.hh:567
Definition: nds_gap_handler.hh:16
std::vector< NDS::channel >::iterator ch_vec_iter
Definition: nds_iterate_handlers.hh:147
bool has_next() override
Definition: nds_iterate_handlers.hh:466
void reset(buffers_type &other)
Definition: nds_iterate_handlers.hh:236
buffers_type next_entry_
Definition: nds_iterate_handlers.hh:570
detail::request_fragments_type fragment_list_
Definition: nds_iterate_handlers.hh:563
void setup_next_step(NDS::detail::conn_p_type &parent)
Definition: nds_iterate_handlers.hh:573
buffer::gps_second_type start() const
Definition: nds_iterate_handlers.hh:274
indexed_buffers current_buffer_
Definition: nds_iterate_handlers.hh:431
epoch prev_epoch_
Definition: nds_iterate_handlers.hh:762
Definition: nds_gap_handler.hh:28
void apply_gap_handler(detail::gap_handler &handler, buffer::gps_second_type gps_stop)
Definition: nds_iterate_handlers.hh:374
buffer::gps_second_type cur_
Definition: nds_iterate_handlers.hh:163
NDS::detail::conn_p_type * conn()
Definition: nds_iterate_handler.hh:48
buffer::gps_second_type max_stride_
Definition: nds_iterate_handlers.hh:568
std::vector< channel > channels_type
Definition: nds_channel.hh:298
bool is_more_data_available_
Definition: nds_iterate_handlers.hh:434
Definition: nds_iterate_handlers.hh:145
indexed_buffers pending_buffer_
Definition: nds_iterate_handlers.hh:432
bool done() override
Definition: nds_iterate_handlers.hh:789
Definition: nds_iterate_handlers.hh:561
bool has_next() override
Definition: nds_iterate_handlers.hh:684
buffer::gps_second_type stride_
Definition: nds_iterate_handlers.hh:427
buffers_type next_entry_
Definition: nds_iterate_handlers.hh:35
void issue_iterate(buffer::gps_second_type gps_start, buffer::gps_second_type gps_stop, buffer::gps_second_type stride, const connection::channel_names_type &channel_names, std::vector< NDS::channel > *final_channel_list=nullptr)
Definition: nds_connection_ptype.cc:1612
std::unique_ptr< detail::gap_handler > gap_handler_
Definition: nds_iterate_handlers.hh:428
std::vector< buffer > buffers_type
Definition: nds_buffer.hh:356
bool valid() const
Definition: nds_iterate_handlers.hh:216
buffer::gps_second_type gps_stop_
Definition: nds_iterate_handlers.hh:426
~iterate_available_handler() override=default
Definition: nds_connection_ptype.hh:148
buffer::gps_second_type gps_start_
Definition: nds_iterate_handlers.hh:31
std::vector< std::unique_ptr< NDS::detail::delayed_gap_handler > > delay_
Definition: nds_iterate_handlers.hh:167
~iterate_handler_with_simple_gaps() override=default
bool has_next() override
Definition: nds_iterate_handlers.hh:795
void get_next_block(buffers_type &output)
Definition: nds_iterate_handlers.hh:50
buffer::gps_second_type cur_gps_
Definition: nds_iterate_handlers.hh:424
Definition: nds_iterate_handlers.hh:159
channel::channel_names_type names_
Definition: nds_iterate_handlers.hh:760
buffer::size_type cur_segment_
Definition: nds_iterate_handlers.hh:564
std::vector< NDS::channel > channel_list_
Definition: nds_iterate_handlers.hh:429
buffer::gps_second_type cur_gps_
Definition: nds_iterate_handlers.hh:565
buffer::gps_second_type remaining() const
Definition: nds_iterate_handlers.hh:290
buffer::gps_second_type gps_start_
Definition: nds_iterate_handlers.hh:756