nidas  v1.2-1520
NearestResampler.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_NEARESTRESAMPLER_H
28 #define NIDAS_CORE_NEARESTRESAMPLER_H
29 
30 #include "Resampler.h"
31 #include "SampleTag.h"
32 
33 #include <vector>
34 
35 namespace nidas { namespace core {
36 
54 class NearestResampler : public Resampler {
55 public:
56 
60  NearestResampler(const std::vector<const Variable*>& vars,bool nansVariable=true);
61 
62  NearestResampler(const std::vector<Variable*>& vars,bool nansVariable=true);
63 
65 
67 
69 
73  std::list<const SampleTag*> getSampleTags() const
74  {
75  return _source.getSampleTags();
76  }
77 
82  {
84  }
85 
89  void addSampleClient(SampleClient* client) throw()
90  {
91  _source.addSampleClient(client);
92  }
93 
94  void removeSampleClient(SampleClient* client) throw()
95  {
97  }
98 
103  void addSampleClientForTag(SampleClient* client,const SampleTag*) throw()
104  {
105  // I only have one tag, so just call addSampleClient()
106  _source.addSampleClient(client);
107  }
108 
109  void removeSampleClientForTag(SampleClient* client,const SampleTag*) throw()
110  {
111  _source.removeSampleClient(client);
112  }
113 
114  int getClientCount() const throw()
115  {
116  return _source.getClientCount();
117  }
118 
120  {
121  return _source.getSampleStats();
122  }
123 
128 
129  void disconnect(SampleSource* src) throw();
130 
134  bool receive(const Sample *s) throw();
135 
140  void flush() throw();
141 
142 private:
143 
147  void ctorCommon(const std::vector<const Variable*>& vars,bool nansVariable);
148 
152  void addSampleTag(const SampleTag* tag) throw ()
153  {
154  _source.addSampleTag(tag);
155  }
156 
157  void removeSampleTag(const SampleTag* tag) throw ()
158  {
160  }
161 
163 
165 
169  std::vector<Variable *> _reqVars;
170 
174  std::map<Variable*,unsigned int> _outVarIndices;
175 
180  std::map<dsm_sample_id_t,std::vector<unsigned int> > _inmap;
181 
185  std::map<dsm_sample_id_t,std::vector<unsigned int> > _lenmap;
186 
190  std::map<dsm_sample_id_t,std::vector<unsigned int> > _outmap;
191 
192  unsigned int _ndataValues;
193 
194  unsigned int _outlen;
195 
196  unsigned int _master;
197 
198  int _nmaster;
199 
201 
203 
204  float* _prevData;
205 
206  float* _nearData;
207 
209 
210  std::map<dsm_sample_id_t,unsigned int> _ttOutOfOrder;
211 
212  bool _debug;
213 
218 
223 };
224 
225 }} // namespace nidas namespace core
226 
227 #endif
void connect(SampleSource *src)
Connect the resampler to a SampleSource.
Definition: NearestResampler.cc:156
bool _debug
Definition: NearestResampler.h:212
unsigned int _master
Definition: NearestResampler.h:196
Interface for a resampler, simply a SampleClient and a SampleSource.
Definition: Resampler.h:39
void flush()
Implementation of Resampler::flush().
Definition: NearestResampler.cc:462
std::map< Variable *, unsigned int > _outVarIndices
Index of each requested output variable in the output sample.
Definition: NearestResampler.h:174
float * _prevData
Definition: NearestResampler.h:204
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition: NearestResampler.h:81
int _nmaster
Definition: NearestResampler.h:198
bool receive(const Sample *s)
Implementation of SampleClient::receive().
Definition: NearestResampler.cc:254
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
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 removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition: NearestResampler.h:94
NearestResampler & operator=(const NearestResampler &)
No assignment.
unsigned int _outlen
Definition: NearestResampler.h:194
A source of samples.
Definition: SampleSourceSupport.h:47
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
Pure virtual interface of a client of Samples.
Definition: SampleClient.h:38
std::map< dsm_sample_id_t, unsigned int > _ttOutOfOrder
Definition: NearestResampler.h:210
std::list< const SampleTag * > getSampleTags() const
Get the SampleTag of my merged output sample.
Definition: NearestResampler.h:73
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition: NearestResampler.h:152
const SampleStats & getSampleStats() const
Definition: SampleSourceSupport.h:149
dsm_time_t * _prevTT
Definition: NearestResampler.h:200
int getClientCount() const
How many SampleClients are currently in my list.
Definition: NearestResampler.h:114
void removeSampleClientForTag(SampleClient *client, const SampleTag *)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition: NearestResampler.h:109
SampleSourceSupport _source
Definition: NearestResampler.h:162
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: NearestResampler.h:180
void disconnect(SampleSource *src)
Definition: NearestResampler.cc:249
const SampleStats & getSampleStats() const
Definition: NearestResampler.h:119
int * _samplesSinceMaster
Definition: NearestResampler.h:208
Interface to a data sample.
Definition: Sample.h:189
float * _nearData
Definition: NearestResampler.h:206
std::vector< Variable * > _reqVars
Requested variables.
Definition: NearestResampler.h:169
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: NearestResampler.h:66
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
SampleTag _outSample
Definition: NearestResampler.h:164
A source of samples.
Definition: SampleStats.h:41
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: NearestResampler.h:68
unsigned int _ndataValues
Definition: NearestResampler.h:192
~NearestResampler()
Definition: NearestResampler.cc:68
std::map< dsm_sample_id_t, std::vector< unsigned int > > _lenmap
For each input sample, length of variables to read.
Definition: NearestResampler.h:185
std::map< dsm_sample_id_t, std::vector< unsigned int > > _outmap
For each input sample, index into output sample of each variable.
Definition: NearestResampler.h:190
int getClientCount() const
How many SampleClients are currently in my list.
Definition: SampleSourceSupport.cc:136
std::list< const SampleTag * > getSampleTags() const
What SampleTags am I a SampleSource for?
Definition: SampleSourceSupport.cc:54
void removeSampleTag(const SampleTag *tag)
Definition: NearestResampler.h:157
void addSampleClientForTag(SampleClient *client, const SampleTag *)
Add a Client for a given SampleTag.
Definition: NearestResampler.h:103
dsm_time_t * _nearTT
Definition: NearestResampler.h:202
A simple, nearest-point resampler, for generating merged samples from variables from one or more samp...
Definition: NearestResampler.h:54
NearestResampler(const std::vector< const Variable * > &vars, bool nansVariable=true)
Constructor.
Definition: NearestResampler.cc:39
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition: NearestResampler.h:89
void ctorCommon(const std::vector< const Variable * > &vars, bool nansVariable)
Common tasks of constructors.
Definition: NearestResampler.cc:80
Definition: InvalidParameterException.h:35
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition: SampleSourceSupport.cc:60