HOPS
HOPS class reference
MHO_SamplerLabeler.hh
Go to the documentation of this file.
1 #ifndef MHO_SamplerLabeler_HH__
2 #define MHO_SamplerLabeler_HH__
3 
4 #include <map>
5 #include <stack>
6 #include <string>
7 
8 #include "MHO_Message.hh"
9 #include "MHO_Tokenizer.hh"
10 
12 #include "MHO_TableContainer.hh"
13 #include "MHO_UnaryOperator.hh"
14 
15 namespace hops
16 {
17 
34 template< typename XArrayType > class MHO_SamplerLabeler: public MHO_UnaryOperator< XArrayType >
35 {
36  public:
38  {
39  fComma = ",";
40  fChannelLabelKey = "channel_label";
41  fRefSamplerIndexKey = "ref_sampler_index";
42  fRemSamplerIndexKey = "rem_sampler_index";
43  };
44 
45  virtual ~MHO_SamplerLabeler(){};
46 
52  void SetReferenceStationSamplerChannelSets(const std::vector< std::string >& channel_sets)
53  {
54  fRefSamplerChanSets = channel_sets;
55  }
56 
62  void SetRemoteStationSamplerChannelSets(const std::vector< std::string >& channel_sets)
63  {
64  fRemSamplerChanSets = channel_sets;
65  }
66 
67  protected:
76  virtual bool ExecuteInPlace(XArrayType* in) override
77  {
78  //map channel label (e.g. 'a', 'b', etc.) to sampler index for both reference and remote stations
79  ConstructChannelToSamplerIDMap(fRefSamplerChanSets, fRefChanToSamplerID);
80  ConstructChannelToSamplerIDMap(fRemSamplerChanSets, fRemChanToSamplerID);
81 
82  if(in != nullptr)
83  {
84  //need to retrieve the labels of each channel, then look up the
85  //sampler delay index using the map, and then insert that key:value pair
86  auto chan_axis_ptr = &(std::get< CHANNEL_AXIS >(*in));
87  std::size_t nchans = chan_axis_ptr->GetSize();
88 
89  for(std::size_t ch = 0; ch < nchans; ch++)
90  {
91  std::string chan_label = "";
92  chan_axis_ptr->RetrieveIndexLabelKeyValue(ch, fChannelLabelKey, chan_label);
93  //add sampler labels
94  if(fRefChanToSamplerID.find(chan_label) != fRefChanToSamplerID.end())
95  {
96  int ref_id = fRefChanToSamplerID[chan_label];
97  chan_axis_ptr->InsertIndexLabelKeyValue(ch, fRefSamplerIndexKey, ref_id);
98  }
99  if(fRemChanToSamplerID.find(chan_label) != fRemChanToSamplerID.end())
100  {
101  int rem_id = fRemChanToSamplerID[chan_label];
102  chan_axis_ptr->InsertIndexLabelKeyValue(ch, fRemSamplerIndexKey, rem_id);
103  }
104  }
105  return true;
106  }
107  return false;
108  }
109 
110  private:
111  //data maps channels to sampler
112  std::vector< std::string > fRefSamplerChanSets;
113  std::vector< std::string > fRemSamplerChanSets;
114  std::map< std::string, int > fRefChanToSamplerID;
115  std::map< std::string, int > fRemChanToSamplerID;
116 
117  std::string fComma;
118  std::string fChannelLabelKey;
119  std::string fRefSamplerIndexKey;
120  std::string fRemSamplerIndexKey;
121  MHO_Tokenizer fTokenizer;
122 
129  void ConstructChannelToSamplerIDMap(std::vector< std::string >& chan_set, std::map< std::string, int >& chan2id)
130  {
131  //figure out which sampler index each channel has been assigned to
132  for(std::size_t sampler_id = 0; sampler_id < chan_set.size(); sampler_id++)
133  {
134  std::string chans = chan_set[sampler_id];
135  std::vector< std::string > split_chans = SplitChannelLabels(chans);
136  for(auto it = split_chans.begin(); it != split_chans.end(); it++)
137  {
138  chan2id[*it] = (int)sampler_id;
139  }
140  }
141  }
142 
149  std::vector< std::string > SplitChannelLabels(std::string channels)
150  {
151  std::vector< std::string > split_chans;
152  //we have two possibilities, either channels are delimited by ',' or
153  //they are all single-char labels that are smashed together into a single string
154 
155  if((channels.find(',') != std::string::npos))
156  {
157  //found a comma, need to use the tokenizer
158  fTokenizer.SetDelimiter(fComma);
161  fTokenizer.SetIncludeEmptyTokensFalse();
162  fTokenizer.SetString(&channels);
163  fTokenizer.GetTokens(&split_chans);
164  }
165  else
166  {
167  //just split up the channels into individual characters
168  for(std::size_t i = 0; i < channels.size(); i++)
169  {
170  split_chans.push_back(std::string(1, channels[i]));
171  }
172  }
173  return split_chans;
174  }
175 };
176 
177 } // namespace hops
178 
179 #endif
Class MHO_SamplerLabeler.
Definition: MHO_SamplerLabeler.hh:35
virtual bool ExecuteInPlace(XArrayType *in) override
Function ExecuteInPlace - actual implementation, map channel label (e.g. 'a', 'b',...
Definition: MHO_SamplerLabeler.hh:76
void SetReferenceStationSamplerChannelSets(const std::vector< std::string > &channel_sets)
Setter for reference station sampler channel sets.
Definition: MHO_SamplerLabeler.hh:52
virtual ~MHO_SamplerLabeler()
Definition: MHO_SamplerLabeler.hh:45
MHO_SamplerLabeler()
Definition: MHO_SamplerLabeler.hh:37
void SetRemoteStationSamplerChannelSets(const std::vector< std::string > &channel_sets)
Setter for remote station sampler channel sets.
Definition: MHO_SamplerLabeler.hh:62
Class MHO_Tokenizer.
Definition: MHO_Tokenizer.hh:24
void SetUseMulticharacterDelimiterFalse()
Definition: MHO_Tokenizer.cc:40
void SetIncludeEmptyTokensFalse()
Definition: MHO_Tokenizer.cc:30
void SetString(const std::string *aString)
Definition: MHO_Tokenizer.cc:65
void GetTokens(std::vector< std::string > *tokens)
Definition: MHO_Tokenizer.cc:75
void SetRemoveLeadingTrailingWhitespaceTrue()
Setter for remove leading trailing whitespace true.
Definition: MHO_Tokenizer.cc:55
void SetDelimiter(const std::string &aDelim)
Definition: MHO_Tokenizer.cc:70
Class MHO_UnaryOperator.
Definition: MHO_UnaryOperator.hh:24
Definition: MHO_AdhocFlagging.hh:18