nds2-client - ClientDeveloper  0.16.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
8 namespace NDS
9 {
10  namespace detail
11  {
12  class composer
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  {
50  NDS::channels_type chans;
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,
60  FIRST_CHANNEL );
61  } );
62  initialize_buffers( chans );
63  if ( !initialized )
64  {
65  throw connection::daq_error(
66  DAQD_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 );
110  DLL_EXPORT
111  void do_finish_gap_handling( );
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 > >
122  bool finished;
123 
125  };
126 
127  inline void
128  composer::fill_gap( buffer& cur_buffer,
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__
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
DLL_EXPORT void add_segment(const buffers_type &cur_bufs)
Definition: nds_composer.cc:42
request_fragment::working_buffers & buffers
Definition: nds_composer.hh:113
Definition: nds_connection_ptype.hh:113
std::vector< buffer * > working_buffers
Definition: nds_request_fragment.hh:17
std::ostream & dout()
Definition: debug_stream.cc:23
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
Definition: nds_composer.hh:12
DLL_EXPORT void do_finish_gap_handling()
Definition: nds_composer.cc:126
const gap_handler & _gap_handler
Definition: nds_composer.hh:116
std::vector< std::unique_ptr< delayed_gap_handler > > delayed_handlers
Definition: nds_composer.hh:119
#define DLL_EXPORT
Definition: channel.h:12
selection_method
Definition: nds_channel_selection.hh:35
composer & operator=(const composer &other)=delete
bool initialized
Definition: nds_composer.hh:121
void fill_gap(buffer &cur_buffer, buffer::size_type start_sample, buffer::size_type end_sample)
Definition: nds_composer.hh:128
void initialize_buffers(const T &ref_set)
Definition: nds_composer.hh:78
#define DAQD_ERROR
Definition: daqc_response.h:17
const NDS::detail::buffer_initializer initializer
Definition: nds_composer.hh:115
Definition: nds_gap_handler.hh:44
Definition: nds_gap_handler.hh:28
void finish(T &selector)
Definition: nds_composer.hh:41
std::vector< channel > channels_type
Definition: nds_channel.hh:298
DLL_EXPORT void reset_buffer(buffer *cur_buffer, const channel &channel_info) const
Definition: nds_connection_ptype.cc:204
bool empty_is_safe
Definition: nds_composer.hh:120
std::vector< buffer::size_type > cur_progress
Definition: nds_composer.hh:117
std::vector< buffer > buffers_type
Definition: nds_buffer.hh:356
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
static fixed_point_gap_handler zero_gap_handler
Definition: nds_composer.hh:124
const NDS::connection::channel_names_type _channel_names
Definition: nds_composer.hh:114