nds2-client - Developer 0.16.7
Loading...
Searching...
No Matches
nds_composer.hh
Go to the documentation of this file.
1#ifndef __NDS_COMPOSER_HH__
2#define __NDS_COMPOSER_HH__
3
4#include <memory>
5#include "nds_export.hh"
7
8namespace NDS
9{
10 namespace detail
11 {
13 {
14
15 public:
16 composer( ) = delete;
17 composer( const composer& other ) = delete;
18 composer( composer&& other ) = delete;
19 composer& operator=( const composer& other ) = delete;
20 composer& operator=( composer other ) = delete;
21
24 const NDS::connection::channel_names_type& channel_names,
27 bool buffers_have_been_initialized );
28
29 DLL_EXPORT void add_segment( const buffers_type& cur_bufs );
30
31 /*
32 * \brief Apply all the gaps and finish processing the buffers
33 * \param selector A selection object with the interface of
34 * NDS::detail::channel_selector
35 * this is used to help with initialization when no data is found
36 *
37 * \notes this is implemented as a template to make testing easier.
38 */
39 template < typename T >
40 void
41 finish( T& selector )
42 {
43 if ( finished )
44 {
45 return;
46 }
47 finished = true;
48 if ( !initialized && !empty_is_safe )
49 {
51 chans.reserve( buffers.size( ) );
52 std::transform(
53 _channel_names.begin( ),
54 _channel_names.end( ),
55 std::back_inserter( chans ),
56 [&selector]( const std::string& name ) -> NDS::channel {
57 return selector(
58 name,
59 channel_selector::selection_method::
60 FIRST_CHANNEL );
61 } );
62 initialize_buffers( chans );
63 if ( !initialized )
64 {
65 throw connection::daq_error(
67 "Internal client error, unable to "
68 "determine the channel meta data for a "
69 "buffer" );
70 }
71 }
73 }
74
75 private:
76 template < typename T >
77 void
78 initialize_buffers( const T& ref_set )
79 {
80 if ( initialized )
81 {
82 return;
83 }
84 if ( ref_set.size( ) != buffers.size( ) )
85 {
86 return;
87 }
88 int j = 0;
89 for ( typename T::const_iterator cur_buf = ref_set.begin( );
90 cur_buf != ref_set.end( );
91 ++cur_buf, ++j )
92 {
93 initializer.reset_buffer( buffers[ j ], *cur_buf );
95 << "Initializing buffer for " << buffers[ j ]->Name( )
96 << " with " << buffers[ j ]->Samples( ) << " entries"
97 << std::endl;
98 }
99 initialized = true;
100 }
101
102 void fill_gap( buffer& cur_buffer,
103 buffer::size_type start_sample,
104 buffer::size_type end_sample );
105
106 void bounds_check( const buffer& cur_buffer,
107 buffer::size_type cur_fill,
108 buffer::size_type offset_start,
109 buffer::size_type offset_end );
112
114 const NDS::connection::channel_names_type _channel_names;
117 std::vector< buffer::size_type > cur_progress;
118 std::vector< std::unique_ptr< delayed_gap_handler > >
123
125 };
126
127 inline void
129 buffer::size_type start_sample,
130 buffer::size_type end_sample )
131 {
132 static const std::string tname( ".n,s-trend" );
133 static const std::string cmp( ".n," );
134
135 // .n trends are always filled with 0s. This is a flag that the
136 // data
137 // was gap filled
138 // look for .n,s-trend or .n,m-trend, can probably optimize this to
139 // look
140 // for the '.n,'
141 const std::string& name = cur_buffer.Name( );
142 if ( name.size( ) > tname.size( ) &&
143 name.compare(
144 name.size( ) - tname.size( ), cmp.size( ), cmp ) == 0 )
145 {
147 cur_buffer, start_sample, end_sample );
148 }
149 else
150 {
151 std::unique_ptr< delayed_gap_handler > tmp(
153 cur_buffer, start_sample, end_sample ) );
154 if ( tmp )
155 {
156 delayed_handlers.push_back( std::move( tmp ) );
157 }
158 }
159 }
160 }
161
162} // namespace NDS
163
164#endif // __NDS_COMPOSER_H__
#define DLL_EXPORT
Definition channel.h:12
A buffer holds the data contents of a channel.
Definition nds_buffer.hh:28
Represents a LIGO data channel.
Definition nds_channel.hh:34
DLL_EXPORT const std::string & Name() const
Return the channel name.
Definition nds_channel.hh:307
size_t size_type
Defines sizes when dealing with channels.
Definition nds_channel.hh:99
Definition nds_connection_ptype.hh:114
DLL_EXPORT void reset_buffer(buffer *cur_buffer, const channel &channel_info) const
Definition nds_connection_ptype.cc:204
Definition nds_composer.hh:13
const NDS::connection::channel_names_type _channel_names
Definition nds_composer.hh:114
composer(composer &&other)=delete
std::vector< std::unique_ptr< delayed_gap_handler > > delayed_handlers
Definition nds_composer.hh:119
DLL_EXPORT void add_segment(const buffers_type &cur_bufs)
Definition nds_composer.cc:42
const gap_handler & _gap_handler
Definition nds_composer.hh:116
std::vector< buffer::size_type > cur_progress
Definition nds_composer.hh:117
void finish(T &selector)
Definition nds_composer.hh:41
const NDS::detail::buffer_initializer initializer
Definition nds_composer.hh:115
void fill_gap(buffer &cur_buffer, buffer::size_type start_sample, buffer::size_type end_sample)
Definition nds_composer.hh:128
composer(const composer &other)=delete
composer & operator=(const composer &other)=delete
DLL_EXPORT void do_finish_gap_handling()
Definition nds_composer.cc:126
request_fragment::working_buffers & buffers
Definition nds_composer.hh:113
bool initialized
Definition nds_composer.hh:121
composer & operator=(composer other)=delete
static fixed_point_gap_handler zero_gap_handler
Definition nds_composer.hh:124
bool finished
Definition nds_composer.hh:122
void bounds_check(const buffer &cur_buffer, buffer::size_type cur_fill, buffer::size_type offset_start, buffer::size_type offset_end)
Definition nds_composer.cc:167
void initialize_buffers(const T &ref_set)
Definition nds_composer.hh:78
bool empty_is_safe
Definition nds_composer.hh:120
Definition nds_gap_handler.hh:45
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 override
Definition nds_gap_handler.cc:163
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
#define DAQD_ERROR
Definition daqc_response.h:17
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
The NDS client namespace.
Definition debug_stream.cc:18
std::vector< buffer * > working_buffers
Definition nds_request_fragment.hh:17