nidas  v1.2-1520
NearestResamplerAtRate.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2006, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 
27 #ifndef NIDAS_CORE_NEARESTRESAMPLERATRATE_H
28 #define NIDAS_CORE_NEARESTRESAMPLERATRATE_H
29 
30 #include "Resampler.h"
31 #include "SampleTag.h"
32 
33 #include <vector>
34 
35 namespace nidas { namespace core {
36 
76 public:
77 
81  NearestResamplerAtRate(const std::vector<const Variable*>& vars,bool nansVariable=true);
82 
83  NearestResamplerAtRate(const std::vector<Variable*>& vars,bool nansVariable=true);
84 
86 
96  void setRate(double val);
97 
98  double getRate() const
99  {
100  return _rate;
101  }
102 
115  void setMiddleTimeTags(bool val)
116  {
117  _middleTimeTags = val;
118  }
119 
120  bool getMiddleTimeTags() const
121  {
122  return _middleTimeTags;
123  }
124 
128  void setFillGaps(bool val)
129  {
130  _fillGaps = val;
131  }
132 
133  bool getFillGaps() const
134  {
135  return _fillGaps;
136  }
137 
139 
141 
145  std::list<const SampleTag*> getSampleTags() const
146  {
147  return _source.getSampleTags();
148  }
149 
154  {
155  return _source.getSampleTagIterator();
156  }
157 
161  void addSampleClient(SampleClient* client) throw()
162  {
163  _source.addSampleClient(client);
164  }
165 
166  void removeSampleClient(SampleClient* client) throw()
167  {
168  _source.removeSampleClient(client);
169  }
170 
175  void addSampleClientForTag(SampleClient* client,const SampleTag*) throw()
176  {
177  // I only have one tag, so just call addSampleClient()
178  _source.addSampleClient(client);
179  }
180 
181  void removeSampleClientForTag(SampleClient* client,const SampleTag*) throw()
182  {
183  _source.removeSampleClient(client);
184  }
185 
186  int getClientCount() const throw()
187  {
188  return _source.getClientCount();
189  }
190 
194  void flush() throw();
195 
197  {
198  return _source.getSampleStats();
199  }
200 
205 
206  void disconnect(SampleSource* input) throw();
207 
208  bool receive(const Sample *s) throw();
209 
210 
211 private:
212 
216  void ctorCommon(const std::vector<const Variable*>& vars, bool nansVariable);
217 
221  void addSampleTag(const SampleTag* tag) throw()
222  {
223  _source.addSampleTag(tag);
224  }
225 
226  void removeSampleTag(const SampleTag* tag) throw ()
227  {
229  }
230 
231  void sendSample(dsm_time_t) throw();
232 
234 
236 
240  std::vector<Variable *> _reqVars;
241 
245  std::map<Variable*,unsigned int> _outVarIndices;
246 
251  std::map<dsm_sample_id_t,std::vector<unsigned int> > _inmap;
252 
256  std::map<dsm_sample_id_t,std::vector<unsigned int> > _lenmap;
257 
261  std::map<dsm_sample_id_t,std::vector<unsigned int> > _outmap;
262 
264 
265  int _outlen;
266 
267  double _rate;
268 
273 
278 
283 
291 
305 
307 
309 
311 
313 
314  float* _prevData;
315 
316  float* _nearData;
317 
319 
320  SampleT<float>* _osamp;
321 
322  bool _fillGaps;
323 
324  std::map<dsm_sample_id_t,unsigned int> _ttOutOfOrder;
325 
330 
334  NearestResamplerAtRate(const NearestResamplerAtRate& x);
335 };
336 
337 }} // namespace nidas namespace core
338 
339 #endif
A simple, nearest-point resampler, for generating merged samples from variables from one or more samp...
Definition: NearestResamplerAtRate.h:75
double _rate
Definition: NearestResamplerAtRate.h:267
dsm_time_t _outputTT
Definition: NearestResamplerAtRate.h:306
Interface for a resampler, simply a SampleClient and a SampleSource.
Definition: Resampler.h:39
std::list< const SampleTag * > getSampleTags() const
Get the SampleTag of my merged output sample.
Definition: NearestResamplerAtRate.h:145
bool getMiddleTimeTags() const
Definition: NearestResamplerAtRate.h:120
SampleSourceSupport _source
Definition: NearestResamplerAtRate.h:233
int _deltatUsecD10
DeltaT over 10.
Definition: NearestResamplerAtRate.h:277
unsigned int dsm_sample_id_t
Definition: Sample.h:63
int * _samplesSinceOutput
Definition: NearestResamplerAtRate.h:318
std::map< dsm_sample_id_t, std::vector< unsigned int > > _lenmap
For each input sample, length of variables to read.
Definition: NearestResamplerAtRate.h:256
void flush()
Implementation of Resampler::flush().
Definition: NearestResamplerAtRate.cc:471
void removeSampleTag(const SampleTag *tag)
Definition: SampleSourceSupport.cc:67
long long dsm_time_t
Posix time in microseconds, the number of non-leap microseconds since 1970 Jan 1 00:00 UTC...
Definition: Sample.h:61
dsm_time_t * _nearTT
Definition: NearestResamplerAtRate.h:312
Class describing a sampled variable.
Definition: Variable.h:46
Pure virtual interface for a source of Samples.
Definition: SampleSource.h:48
SampleTagIterator getSampleTagIterator() const
Definition: SampleSourceSupport.cc:75
void setMiddleTimeTags(bool val)
If true, generate output timetags that are the middle of the requested output periods.
Definition: NearestResamplerAtRate.h:115
float * _nearData
Definition: NearestResamplerAtRate.h:316
bool _exactDeltatUsec
True if simple integer math is used to increment output sample time tags.
Definition: NearestResamplerAtRate.h:290
std::map< dsm_sample_id_t, std::vector< unsigned int > > _outmap
For each input sample, index into output sample of each variable.
Definition: NearestResamplerAtRate.h:261
std::map< dsm_sample_id_t, std::vector< unsigned int > > _inmap
For each input sample, first index of variable data values to be read.
Definition: NearestResamplerAtRate.h:251
A source of samples.
Definition: SampleSourceSupport.h:47
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition: NearestResamplerAtRate.h:161
void removeSampleClient(SampleClient *c)
Remove a SampleClient from this SampleSource This will also remove a SampleClient if it has been adde...
Definition: SampleSourceSupport.cc:88
void addSampleClient(SampleClient *c)
Add a SampleClient to this SampleSource.
Definition: SampleSourceSupport.cc:80
std::vector< Variable * > _reqVars
Requested variables.
Definition: NearestResamplerAtRate.h:240
int _deltatUsecD2
DeltaT over 2.
Definition: NearestResamplerAtRate.h:282
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
int _outlen
Definition: NearestResamplerAtRate.h:265
const SampleStats & getSampleStats() const
Definition: SampleSourceSupport.h:149
void removeSampleClientForTag(SampleClient *client, const SampleTag *)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition: NearestResamplerAtRate.h:181
void setFillGaps(bool val)
Should output records of all missing data (nans), be generated, or just discarded.
Definition: NearestResamplerAtRate.h:128
dsm_time_t * _prevTT
Definition: NearestResamplerAtRate.h:310
bool receive(const Sample *s)
Method called to pass a sample to this client.
Definition: NearestResamplerAtRate.cc:261
const SampleStats & getSampleStats() const
Definition: NearestResamplerAtRate.h:196
SampleTag _outSample
Definition: NearestResamplerAtRate.h:235
void ctorCommon(const std::vector< const Variable * > &vars, bool nansVariable)
Common tasks of constructors.
Definition: NearestResamplerAtRate.cc:85
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: NearestResamplerAtRate.h:140
A typed Sample, with data of type DataT.
Definition: Sample.h:393
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition: NearestResamplerAtRate.h:153
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition: NearestResamplerAtRate.h:221
void removeSampleTag(const SampleTag *tag)
Definition: NearestResamplerAtRate.h:226
Interface to a data sample.
Definition: Sample.h:189
void disconnect(SampleSource *input)
Definition: NearestResamplerAtRate.cc:256
int getClientCount() const
How many SampleClients are currently in my list.
Definition: NearestResamplerAtRate.h:186
void connect(SampleSource *input)
Connect the resampler to a SampleSource.
Definition: NearestResamplerAtRate.cc:170
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
~NearestResamplerAtRate()
Definition: NearestResamplerAtRate.cc:72
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
bool _middleTimeTags
If true, generate output timetags that are the middle of the requested output periods.
Definition: NearestResamplerAtRate.h:304
int _deltatUsec
The output deltaT, 1/rate in microseconds.
Definition: NearestResamplerAtRate.h:272
bool _fillGaps
Definition: NearestResamplerAtRate.h:322
A source of samples.
Definition: SampleStats.h:41
void setRate(double val)
Set the requested output rate, in Hz.
Definition: NearestResamplerAtRate.cc:150
double getRate() const
Definition: NearestResamplerAtRate.h:98
SampleT< float > * _osamp
Definition: NearestResamplerAtRate.h:320
std::map< Variable *, unsigned int > _outVarIndices
Index of each requested output variable in the output sample.
Definition: NearestResamplerAtRate.h:245
bool getFillGaps() const
Definition: NearestResamplerAtRate.h:133
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition: NearestResamplerAtRate.h:166
int getClientCount() const
How many SampleClients are currently in my list.
Definition: SampleSourceSupport.cc:136
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: NearestResamplerAtRate.h:138
int _ndataValues
Definition: NearestResamplerAtRate.h:263
void addSampleClientForTag(SampleClient *client, const SampleTag *)
Add a Client for a given SampleTag.
Definition: NearestResamplerAtRate.h:175
std::list< const SampleTag * > getSampleTags() const
What SampleTags am I a SampleSource for?
Definition: SampleSourceSupport.cc:54
float * _prevData
Definition: NearestResamplerAtRate.h:314
std::map< dsm_sample_id_t, unsigned int > _ttOutOfOrder
Definition: NearestResamplerAtRate.h:324
void sendSample(dsm_time_t)
Definition: NearestResamplerAtRate.cc:367
dsm_time_t _nextOutputTT
Definition: NearestResamplerAtRate.h:308
Definition: InvalidParameterException.h:35
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition: SampleSourceSupport.cc:60
NearestResamplerAtRate(const std::vector< const Variable * > &vars, bool nansVariable=true)
Constructor.
Definition: NearestResamplerAtRate.cc:41