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 >(
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 )
190 if ( cur_ch.
Type( ) &
191 NDS::channel::CHANNEL_TYPE_MTREND )
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( );
346 auto src =
const_cast< char*
>(
347 reinterpret_cast< const char*
>(
348 src_buf.
cbegin<
void >( ) ) );
351 auto dest =
const_cast< char*
>(
352 reinterpret_cast< const char*
>(
353 dest_buf.
cbegin<
void >( ) ) );
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 );
A buffer holds the data contents of a channel.
Definition nds_buffer.hh:28
DLL_EXPORT size_type seconds_to_samples(gps_second_type offset_seconds, gps_nanosecond_type offset_nano=0) const
Convert relative second offsets to relative sample offsets.
Definition nds_buffer.hh:404
const T * cbegin() const
Return a constant data iterator for this buffer, that references the beginning of the data.
Definition nds_buffer.hh:170
DLL_EXPORT size_type samples_to_bytes(size_type offset_samples) const
Convert relative sample offsets to relative byte offsets.
Definition nds_buffer.hh:418
DLL_EXPORT void reset_channel_info(const channel &ChannelInfo, gps_second_type Second, gps_nanosecond_type NanoSecond)
Reset the channel type. Set the sample count to 0.
Definition nds_buffer.cc:64
DLL_EXPORT void resize(size_type N)
Resize the container to hold N elements.
Definition nds_buffer.hh:477
Represents a LIGO data channel.
Definition nds_channel.hh:34
DLL_EXPORT channel_type Type() const
Return the type of the channel.
Definition nds_channel.hh:313
DLL_EXPORT sample_rate_type SampleRate() const
Return the sample rate of the channel.
Definition nds_channel.hh:348
size_t size_type
Defines sizes when dealing with channels.
Definition nds_channel.hh:99
Definition nds_epoch.hh:17
buffer::gps_second_type gps_start
Definition nds_epoch.hh:20
buffer::gps_second_type gps_stop
Definition nds_epoch.hh:21
Definition nds_gap_handler.hh:17
Definition nds_gap_handler.hh:29
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
Definition nds_iterate_handlers.hh:562
buffer::size_type cur_segment_
Definition nds_iterate_handlers.hh:564
bool has_next() override
Definition nds_iterate_handlers.hh:684
buffer::gps_second_type gps_stop_
Definition nds_iterate_handlers.hh:567
buffers_type next_entry_
Definition nds_iterate_handlers.hh:570
~iterate_available_handler() override=default
void setup_next_step(NDS::detail::conn_p_type &parent)
Definition nds_iterate_handlers.hh:573
buffer::gps_second_type gps_start_
Definition nds_iterate_handlers.hh:566
void next(buffers_type &output) override
Definition nds_iterate_handlers.hh:713
channel::channel_names_type names_
Definition nds_iterate_handlers.hh:569
buffer::gps_second_type max_stride_
Definition nds_iterate_handlers.hh:568
buffer::gps_second_type cur_gps_
Definition nds_iterate_handlers.hh:565
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
detail::request_fragments_type fragment_list_
Definition nds_iterate_handlers.hh:563
Definition nds_iterate_handlers.hh:28
~iterate_fast_handler() override=default
buffer::gps_second_type gps_stop_
Definition nds_iterate_handlers.hh:32
buffer::gps_second_type cur_gps_
Definition nds_iterate_handlers.hh:30
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
bool online_
Definition nds_iterate_handlers.hh:34
void get_next_block(buffers_type &output)
Definition nds_iterate_handlers.hh:50
buffer::gps_second_type gps_start_
Definition nds_iterate_handlers.hh:31
bool has_next() override
Definition nds_iterate_handlers.hh:98
T safe_add(T val1, T val2)
Definition nds_iterate_handlers.hh:39
buffers_type next_entry_
Definition nds_iterate_handlers.hh:35
void next(buffers_type &output) override
Definition nds_iterate_handlers.hh:120
buffer::gps_second_type stride_
Definition nds_iterate_handlers.hh:33
Definition nds_iterate_handlers.hh:755
epoch prev_epoch_
Definition nds_iterate_handlers.hh:762
void advance()
Definition nds_iterate_handlers.hh:784
~iterate_full_handler() override=default
channel::channel_names_type names_
Definition nds_iterate_handlers.hh:760
buffer::gps_second_type cur_gps_
Definition nds_iterate_handlers.hh:759
buffer::gps_second_type gps_start_
Definition nds_iterate_handlers.hh:756
bool done() override
Definition nds_iterate_handlers.hh:789
bool has_next() override
Definition nds_iterate_handlers.hh:795
buffer::gps_second_type gps_stride_
Definition nds_iterate_handlers.hh:758
channels_type channels_
Definition nds_iterate_handlers.hh:761
void next(buffers_type &output) override
Definition nds_iterate_handlers.hh:809
buffer::gps_second_type gps_stop_
Definition nds_iterate_handlers.hh:757
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
Definition nds_iterate_handlers.hh:146
buffer::gps_second_type gps_stop_
Definition nds_iterate_handlers.hh:426
bool has_next() override
Definition nds_iterate_handlers.hh:466
~iterate_handler_with_simple_gaps() override=default
bool is_more_data_available_
Definition nds_iterate_handlers.hh:434
std::vector< NDS::channel >::const_iterator ch_vec_const_iter
Definition nds_iterate_handlers.hh:149
buffer::gps_second_type gps_start_
Definition nds_iterate_handlers.hh:425
void next(buffers_type &output) override
Definition nds_iterate_handlers.hh:472
buffer::gps_second_type stride_
Definition nds_iterate_handlers.hh:427
indexed_buffers pending_buffer_
Definition nds_iterate_handlers.hh:432
std::unique_ptr< detail::gap_handler > gap_handler_
Definition nds_iterate_handlers.hh:428
indexed_buffers current_buffer_
Definition nds_iterate_handlers.hh:431
buffer::gps_second_type cur_gps_
Definition nds_iterate_handlers.hh:424
std::vector< NDS::channel >::iterator ch_vec_iter
Definition nds_iterate_handlers.hh:147
std::vector< NDS::channel > channel_list_
Definition nds_iterate_handlers.hh:429
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
Definition nds_iterate_handler.hh:21
NDS::detail::conn_p_type * conn()
Definition nds_iterate_handler.hh:48
#define DAQD_NOT_FOUND
Definition daqc_response.h:62
std::vector< buffer > buffers_type
Definition nds_buffer.hh:356
std::vector< channel > channels_type
Definition nds_channel.hh:298
std::ostream & dout()
Definition debug_stream.cc:23
std::vector< request_fragment > request_fragments_type
Definition nds_request_fragment.hh:36
The NDS client namespace.
Definition debug_stream.cc:18
Definition nds_connection_ptype.hh:149
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
Definition nds_iterate_handlers.hh:160
indexed_buffers()
Definition nds_iterate_handlers.hh:169
buffer::gps_second_type stride_
Definition nds_iterate_handlers.hh:164
buffer::gps_second_type cur() const
Definition nds_iterate_handlers.hh:264
void advance(buffer::gps_second_type delta)
Definition nds_iterate_handlers.hh:304
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 apply_gap_handler(detail::gap_handler &handler, buffer::gps_second_type gps_stop)
Definition nds_iterate_handlers.hh:374
void apply_delayed_handlers()
Definition nds_iterate_handlers.hh:407
void reset(buffers_type &other)
Definition nds_iterate_handlers.hh:236
buffers_type & bufs()
Definition nds_iterate_handlers.hh:254
buffer::gps_second_type cur_
Definition nds_iterate_handlers.hh:163
buffer::gps_second_type start() const
Definition nds_iterate_handlers.hh:274
std::vector< std::unique_ptr< NDS::detail::delayed_gap_handler > > delay_
Definition nds_iterate_handlers.hh:167
bool valid() const
Definition nds_iterate_handlers.hh:216
buffer::gps_second_type append_data_from(indexed_buffers &other)
Definition nds_iterate_handlers.hh:322
buffers_type bufs_
Definition nds_iterate_handlers.hh:162
buffer::gps_second_type remaining() const
Definition nds_iterate_handlers.hh:290