nds2-client - ClientUser  0.16.8
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
nds_channel_selection.hh
1 //
2 // Created by jonathan.hanks on 9/6/18.
3 //
4 #ifndef NDS2_CLIENT_NDS_CHANNEL_SELECTION_HH
5 #define NDS2_CLIENT_NDS_CHANNEL_SELECTION_HH
6 
7 #include <memory>
8 
9 #include "nds_channel.hh"
10 #include "nds_connection_ptype.hh"
11 
12 namespace NDS
13 {
14  namespace detail
15  {
16  // Given a channel name return the channel name with any [ms]-trend
17  // component stripped out
18  DLL_EXPORT
19  std::string filter_trend_from_string( const std::string& input );
20 
21  // Given a channel return the channel with the name stripped of
22  // [ms]-trend.
23  //
24  // On NDS1 it can be necessary to strip the 's-trend', 'm-trend'
25  // text from a channel name to make the names match between
26  // channel listing and fetch/iterate
27  DLL_EXPORT
28  channel strip_trend_from_name( const channel& chan );
29 
30  // Given a channel name, try to determine which NDS::channel
31  // it corresponds to.
32  class channel_selector
33  {
34  public:
35  enum class selection_method
36  {
37  UNIQUE_CHANNEL,
38  FIRST_CHANNEL,
40  UNIQUE_THEN_FIRST
42  };
44 
45  // Initialize the channel_selector with a connection object
46  DLL_EXPORT
47  explicit channel_selector( std::shared_ptr< conn_p_type > conn )
48  : conn_( std::move( conn ) )
49  {
50  }
51  DLL_EXPORT
52  channel_selector( const channel_selector& other ) = default;
53  DLL_EXPORT
54  channel_selector( channel_selector&& other ) = default;
55 
56  channel_selector&
57  operator=( const channel_selector& other ) = default;
58  channel_selector& operator=( channel_selector&& other ) = default;
59 
60  // Given a channel name return a channel object that it maps to, or
61  // raise a daq_error
62  // if no good match could be found.
63  // Do not use for online channels
64  DLL_EXPORT
65  channel operator( )(
66  const std::string& name,
67  selection_method policy = selection_method::UNIQUE_CHANNEL );
68 
69  private:
70  // \brief Given a list of channels return a vector of pointers
71  // into the input list that are filtered to be compatible with
72  // the given channel_type_mask. Then sort the list.
73  // \note You must ensure that the input is around as long as the
74  // output array is needed, as non-owning pointers are returned
75  std::vector< const NDS::channel* > filter_and_sort_channel_list(
76  NDS::channels_type& input,
77  NDS::channel::channel_type channel_type_mask );
78 
79  // \brief Given a list of possible channels, downselect to one
80  // @param input List of channels
81  // @param name The channel name
82  // @param policy Is any match good, or does it need to be unambigous
83  // @notes may throw if the policy can not be satisfied
84  channel downselect( NDS::channels_type& input,
85  const std::string& name,
86  NDS::channel::channel_type channel_type_mask,
87  selection_method policy );
88 
89  std::shared_ptr< conn_p_type > conn_;
90  };
91  }
92 }
93 
94 #endif // NDS2_CLIENT_NDS_CHANNEL_SELECTION_HH