nds2-client - ClientDeveloper  0.16.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nds_channel.hh
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /* set vi: ts=2:softtabstop=2,shiftwidth=2,expandtab */
3 
4 #ifndef SWIG__COMMON__NDS_CHANNEL_HH
5 #define SWIG__COMMON__NDS_CHANNEL_HH
6 
7 #include <ctime>
8 
9 #include <complex>
10 #include <memory>
11 #include <string>
12 #include <ostream>
13 #include <vector>
14 
15 #include "nds_export.hh"
16 
17 namespace NDS
18 {
19  namespace detail
20  {
21  struct conn_p_type;
22  }
23 
24  inline namespace abi_0
25  {
33  class channel
34  {
35  public:
39  typedef enum {
41  CHANNEL_TYPE_ONLINE = ( 1 << 0 ),
42  CHANNEL_TYPE_RAW = ( 1 << 1 ),
43  CHANNEL_TYPE_RDS = ( 1 << 2 ),
44  CHANNEL_TYPE_STREND = ( 1 << 3 ),
45  CHANNEL_TYPE_MTREND = ( 1 << 4 ),
46  CHANNEL_TYPE_TEST_POINT = ( 1 << 5 ),
47  CHANNEL_TYPE_STATIC = ( 1 << 6 )
48  } channel_type;
49 
53  typedef enum {
55  DATA_TYPE_INT16 = ( 1 << 0 ),
56  DATA_TYPE_INT32 = ( 1 << 1 ),
57  DATA_TYPE_INT64 = ( 1 << 2 ),
58  DATA_TYPE_FLOAT32 = ( 1 << 3 ),
59  DATA_TYPE_FLOAT64 = ( 1 << 4 ),
61  ( 1 << 5 ),
62  DATA_TYPE_UINT32 = ( 1 << 6 )
63  } data_type;
64 
71  class hash_type : private std::vector< unsigned char >
72  {
73  public:
74  typedef std::vector< unsigned char > element_type;
75 
76  using element_type::size;
77 
78  hash_type( );
79 
80  bool compare( const void* Buffer,
81  size_t Length = ( size_t )( -1 ) ) const;
82 
83  const void* ref( ) const;
84 
85  void reset( );
86 
87  private:
88  friend struct NDS::detail::conn_p_type;
89 
90  static const unsigned char zero_hash[ 1 ];
91  static const size_t MAX_SIZE;
92  };
93 
94  typedef double sample_rate_type;
95  typedef float signal_gain_type;
96  typedef float signal_slope_type;
97  typedef float signal_offset_type;
98  typedef size_t
100 
104  typedef std::vector< std::string > channel_names_type;
105 
110  ( channel_type )(
114 
122 
123  DLL_EXPORT static const sample_rate_type
125  DLL_EXPORT static const sample_rate_type
127 
135  DLL_EXPORT static channel_type convert_daq_chantype( int ChanType );
136 
144 
150  DLL_EXPORT static const std::string&
151  ToString( channel_type ChannelType );
152 
158  DLL_EXPORT static const std::string& ToString( data_type DataType );
159 
164  DLL_EXPORT
165  channel( );
166 
172  DLL_EXPORT
173  channel( const channel& Source );
174 
188  DLL_EXPORT
189  channel( const std::string& Name,
192  sample_rate_type SampleRate,
193  signal_gain_type Gain,
194  signal_slope_type Slope,
195  signal_offset_type Offset,
196  std::string Units );
197 
202  DLL_EXPORT const std::string& Name( ) const;
203 
211  DLL_EXPORT std::string NameLong( ) const;
212 
217  DLL_EXPORT channel_type Type( ) const;
218 
223  DLL_EXPORT data_type DataType( ) const;
224 
233 
238  DLL_EXPORT sample_rate_type SampleRate( ) const;
239 
244  DLL_EXPORT signal_gain_type Gain( ) const;
245 
250  DLL_EXPORT signal_slope_type Slope( ) const;
251 
256  DLL_EXPORT signal_offset_type Offset( ) const;
257 
262  DLL_EXPORT const std::string& Units( ) const;
263 
271  DLL_EXPORT void swap( channel& Source );
272 
278  DLL_EXPORT static bool IsSecondTrend( const std::string& Name );
279 
285  DLL_EXPORT static bool IsMinuteTrend( const std::string& Name );
286 
287  private:
288  std::string name;
291  sample_rate_type sample_rate;
292  signal_gain_type gain;
293  signal_slope_type slope;
294  signal_offset_type offset;
295  std::string units;
296  };
297 
298  typedef std::vector< channel > channels_type;
299 
300  inline const void*
302  {
303  return ( ( size( ) > 0 ) ? &( this->operator[]( 0 ) ) : zero_hash );
304  }
305 
306  inline const std::string&
307  channel::Name( ) const
308  {
309  return name;
310  }
311 
312  inline channel::channel_type
313  channel::Type( ) const
314  {
315  return type;
316  }
317 
318  inline channel::data_type
320  {
321  return data;
322  }
323 
324  inline channel::size_type
326  {
327  switch ( data )
328  {
329  case DATA_TYPE_INT16:
330  return ( 2 );
331  break;
332  case DATA_TYPE_INT32:
333  case DATA_TYPE_FLOAT32:
334  case DATA_TYPE_UINT32:
335  return ( 4 );
336  break;
337  case DATA_TYPE_INT64:
338  case DATA_TYPE_FLOAT64:
339  case DATA_TYPE_COMPLEX32:
340  return ( 8 );
341  break;
342  default:
343  return 0;
344  }
345  }
346 
349  {
350  return sample_rate;
351  }
352 
354  channel::Gain( ) const
355  {
356  return gain;
357  }
358 
360  channel::Slope( ) const
361  {
362  return slope;
363  }
364 
367  {
368  return offset;
369  }
370 
371  inline const std::string&
372  channel::Units( ) const
373  {
374  return units;
375  }
376 
377  inline bool
378  channel::IsSecondTrend( const std::string& Name )
379  {
380  static const std::string STREND_EXT( ",s-trend" );
381 
382  if ( Name.size( ) <= STREND_EXT.size( ) )
383  {
384  return false;
385  }
386  return ( STREND_EXT.compare( Name.substr(
387  Name.size( ) - STREND_EXT.size( ) ) ) == 0 );
388  }
389 
390  inline bool
391  channel::IsMinuteTrend( const std::string& Name )
392  {
393  static const std::string MTREND_EXT( ",m-trend" );
394 
395  if ( Name.size( ) <= MTREND_EXT.size( ) )
396  {
397  return false;
398  }
399  return ( MTREND_EXT.compare( Name.substr(
400  Name.size( ) - MTREND_EXT.size( ) ) ) == 0 );
401  }
402 
403  DLL_EXPORT extern std::ostream& operator<<( std::ostream& os,
404  const channel& ch );
405 
424  template < typename T >
426  {
427  static const NDS::channel::data_type value =
428  NDS::channel::DATA_TYPE_UNKNOWN;
429  };
430 
431  template <>
432  struct channel_data_type_conversion< std::int16_t >
433  {
434  static const NDS::channel::data_type value =
435  NDS::channel::DATA_TYPE_INT16;
436  };
437 
438  template <>
439  struct channel_data_type_conversion< std::int32_t >
440  {
441  static const NDS::channel::data_type value =
442  NDS::channel::DATA_TYPE_INT32;
443  };
444 
445  template <>
446  struct channel_data_type_conversion< std::int64_t >
447  {
448  static const NDS::channel::data_type value =
449  NDS::channel::DATA_TYPE_INT64;
450  };
451 
452  template <>
454  {
455  static const NDS::channel::data_type value =
456  ( NDS::channel::DATA_TYPE_FLOAT32 );
457  };
458 
459  template <>
461  {
462  static const NDS::channel::data_type value =
463  NDS::channel::DATA_TYPE_FLOAT64;
464  };
465 
466  template <>
467  struct channel_data_type_conversion< std::complex< float > >
468  {
469  static const NDS::channel::data_type value =
470  ( NDS::channel::DATA_TYPE_COMPLEX32 );
471  };
472 
473  template <>
474  struct channel_data_type_conversion< std::uint32_t >
475  {
476  static const NDS::channel::data_type value =
477  NDS::channel::DATA_TYPE_UINT32;
478  };
479 
480  DLL_EXPORT const std::string&
482 
483  DLL_EXPORT const std::string&
485  }
486 } // namespace - NDS
487 
488 #endif /* SWIG__COMMON__NDS_CHANNEL_HH */
std::vector< unsigned char > element_type
Definition: nds_channel.hh:74
DLL_EXPORT channel()
Default constructor.
Definition: nds_channel.cc:49
std::vector< std::string > channel_names_type
A vector of channel names.
Definition: nds_channel.hh:104
static DLL_EXPORT const std::string & ToString(channel_type ChannelType)
Return a string representatino of the given channel_type.
Definition: nds_channel.cc:82
Minute trend.
Definition: nds_channel.hh:45
const std::string & data_type_to_string(channel::data_type dtype)
Definition: nds_channel.cc:366
64 bit signed integer
Definition: nds_channel.hh:57
double sample_rate_type
Defines the sample rate type.
Definition: nds_channel.hh:94
float signal_offset_type
Defines the offset type.
Definition: nds_channel.hh:97
32 bit unsigned integer value
Definition: nds_channel.hh:62
Online channel.
Definition: nds_channel.hh:41
Test point data.
Definition: nds_channel.hh:46
DLL_EXPORT data_type DataType() const
Return the data type of the channel.
Definition: nds_channel.hh:319
DLL_EXPORT size_type DataTypeSize() const
Return the size in bytes of an individual sample from the channel.
Definition: nds_channel.hh:325
float signal_gain_type
Defines the gain type.
Definition: nds_channel.hh:95
DLL_EXPORT std::string NameLong() const
Return the name with additional information.
Definition: nds_channel.cc:70
static const unsigned char zero_hash[1]
Definition: nds_channel.hh:90
static DLL_EXPORT const sample_rate_type MAX_SAMPLE_RATE
Largest sample rate possible.
Definition: nds_channel.hh:126
hash_type()
Definition: nds_channel.cc:27
size_t size_type
Defines sizes when dealing with channels.
Definition: nds_channel.hh:99
Reduced data set.
Definition: nds_channel.hh:43
DLL_EXPORT const std::string & Name() const
Return the channel name.
Definition: nds_channel.hh:307
void reset()
Definition: nds_channel.cc:42
static DLL_EXPORT const channel_type DEFAULT_CHANNEL_MASK
The combination of all valid channel types.
Definition: nds_channel.hh:109
DLL_EXPORT void swap(channel &Source)
Swap this channel with another.
Definition: nds_channel.cc:272
32 bit float value
Definition: nds_channel.hh:58
#define DLL_EXPORT
Definition: channel.h:12
signal_slope_type slope
Definition: nds_channel.hh:293
Complex value, two 32 bit floats.
Definition: nds_channel.hh:60
static DLL_EXPORT const data_type DEFAULT_DATA_MASK
The combinatino of all valid data types.
Definition: nds_channel.hh:118
const std::string & channel_type_to_string(channel::channel_type ctype)
Definition: nds_channel.cc:310
bool compare(const void *Buffer, size_t Length=(size_t)(-1)) const
Definition: nds_channel.cc:33
Second trend.
Definition: nds_channel.hh:44
channel_type type
Definition: nds_channel.hh:289
DLL_EXPORT sample_rate_type SampleRate() const
Return the sample rate of the channel.
Definition: nds_channel.hh:348
DLL_EXPORT signal_gain_type Gain() const
Return the gain of the channel.
Definition: nds_channel.hh:354
static DLL_EXPORT data_type convert_daq_datatype(int DataType)
Convert from the legacy daqd data types to a data_type enum.
Definition: nds_channel.cc:227
const void * ref() const
Definition: nds_channel.hh:301
signal_gain_type gain
Definition: nds_channel.hh:292
The hash_type represents a channel hash. The channel hash is an hash of the NDS2 channel list...
Definition: nds_channel.hh:71
Raw channel.
Definition: nds_channel.hh:42
16 bit signed integer
Definition: nds_channel.hh:55
static const size_t MAX_SIZE
Definition: nds_channel.hh:91
32 bit signed integer
Definition: nds_channel.hh:56
DLL_EXPORT signal_slope_type Slope() const
Return the slope of the channel.
Definition: nds_channel.hh:360
std::string name
Definition: nds_channel.hh:288
static DLL_EXPORT const sample_rate_type MIN_SAMPLE_RATE
Smallest sample rate possible.
Definition: nds_channel.hh:124
channel_type
Definition: nds_channel.hh:39
data_type data
Definition: nds_channel.hh:290
std::string units
Definition: nds_channel.hh:295
64 bit float value
Definition: nds_channel.hh:59
Unkown.
Definition: nds_channel.hh:54
Static data.
Definition: nds_channel.hh:47
Unknown.
Definition: nds_channel.hh:40
std::vector< channel > channels_type
Definition: nds_channel.hh:298
DLL_EXPORT const std::string & Units() const
Return the units of this channel.
Definition: nds_channel.hh:372
signal_offset_type offset
Definition: nds_channel.hh:294
Represents a LIGO data channel.
Definition: nds_channel.hh:33
DLL_EXPORT signal_offset_type Offset() const
Return the offset of the channel.
Definition: nds_channel.hh:366
data_type
Defines the internal data representation.
Definition: nds_channel.hh:53
sample_rate_type sample_rate
Definition: nds_channel.hh:291
static DLL_EXPORT channel_type convert_daq_chantype(int ChanType)
Convert from the legacy daqd channel types to a channel_type enum.
Definition: nds_channel.cc:194
static DLL_EXPORT bool IsMinuteTrend(const std::string &Name)
Check the channel name to see if it is a minute trend.
Definition: nds_channel.hh:391
Definition: nds_connection_ptype.hh:148
static DLL_EXPORT bool IsSecondTrend(const std::string &Name)
Check the channel name to see if it is a second trend.
Definition: nds_channel.hh:378
DLL_EXPORT channel_type Type() const
Return the type of the channel.
Definition: nds_channel.hh:313
Given a C++ data type, determine which NDS channel data type applies to it.
Definition: nds_channel.hh:425
std::ostream & operator<<(std::ostream &os, const segment &obj)
Definition: nds_availability.cc:72
float signal_slope_type
Defines the slope type.
Definition: nds_channel.hh:96