nidas v1.2.3
SampleAverager.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 ** 2005, 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_SAMPLEAVERAGER_H
28#define NIDAS_CORE_SAMPLEAVERAGER_H
29
30#include "Resampler.h"
31#include "SampleTag.h"
32
33namespace nidas { namespace core {
34
35class Variable;
36
37class SampleAverager : public Resampler {
38public:
39
41
42 SampleAverager(const std::vector<const Variable*>& vars);
43
44 SampleAverager(const std::vector<Variable*>& vars);
45
46 virtual ~SampleAverager();
47
52 void setAveragePeriodSecs(float val) {
53 _averagePeriodUsecs = (int)rint((double)val * USECS_PER_SEC);
55 }
56
61 float getAveragePeriodSecs() const { return (double)_averagePeriodUsecs / USECS_PER_SEC; }
62
63 void addVariable(const Variable *var);
64
65 void addVariables(const std::vector<const Variable*>&);
66
68
70
74 std::list<const SampleTag*> getSampleTags() const
75 {
76 return _source.getSampleTags();
77 }
78
86
90 void addSampleClient(SampleClient* client) throw()
91 {
93 }
94
95 void removeSampleClient(SampleClient* client) throw()
96 {
98 }
99
104 void addSampleClientForTag(SampleClient* client,const SampleTag*) throw()
105 {
106 // I only have one tag, so just call addSampleClient()
107 _source.addSampleClient(client);
108 }
109
111 {
113 }
114
115 int getClientCount() const throw()
116 {
117 return _source.getClientCount();
118 }
119
123 void flush() throw();
124
126 {
127 return _source.getSampleStats();
128 }
129
135 void connect(SampleSource* source);
136
137 void disconnect(SampleSource* source) throw();
138
139 bool receive(const Sample *s) throw();
140
141protected:
142
143 void init() throw();
144
145private:
146
150 void addSampleTag(const SampleTag* tag) throw ()
151 {
153 }
154
155 void removeSampleTag(const SampleTag* tag) throw ()
156 {
158 }
159
161
163
168
173
177 std::map<Variable*,unsigned int> _outVarIndices;
178
179 std::map<dsm_sample_id_t,std::vector<unsigned int> > _inmap;
180
181 std::map<dsm_sample_id_t,std::vector<unsigned int> > _lenmap;
182
183 std::map<dsm_sample_id_t,std::vector<unsigned int> > _outmap;
184
185 unsigned int _ndataValues;
186
187 double *_sums;
188
189 int *_cnts;
190
195
200
201};
202
203}} // namespace nidas namespace core
204
205#endif
206
Interface for a resampler, simply a SampleClient and a SampleSource.
Definition Resampler.h:39
Definition SampleAverager.h:37
void removeSampleTag(const SampleTag *tag)
Definition SampleAverager.h:155
unsigned int _ndataValues
Definition SampleAverager.h:185
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleAverager.h:67
void connect(SampleSource *source)
Connect the resampler to a SampleSource.
Definition SampleAverager.cc:97
dsm_time_t _endTime
end time of current statistics window.
Definition SampleAverager.h:172
double * _sums
Definition SampleAverager.h:187
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition SampleAverager.h:150
SampleSourceSupport _source
Definition SampleAverager.h:160
int * _cnts
Definition SampleAverager.h:189
void removeSampleClientForTag(SampleClient *client, const SampleTag *)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition SampleAverager.h:110
SampleAverager & operator=(const SampleAverager &)
No assignment.
virtual ~SampleAverager()
Definition SampleAverager.cc:74
bool receive(const Sample *s)
Method called to pass a sample to this client.
Definition SampleAverager.cc:247
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition SampleAverager.h:82
std::map< Variable *, unsigned int > _outVarIndices
Index of each requested output variable in the output sample.
Definition SampleAverager.h:177
const SampleStats & getSampleStats() const
Definition SampleAverager.h:125
void addVariables(const std::vector< const Variable * > &)
Definition SampleAverager.cc:80
void addVariable(const Variable *var)
Definition SampleAverager.cc:89
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition SampleAverager.h:90
SampleTag _outSample
Definition SampleAverager.h:162
SampleAverager(const SampleAverager &)
No copy.
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition SampleAverager.h:95
void flush()
Implementation of Resampler::flush().
Definition SampleAverager.cc:221
void init()
Definition SampleAverager.cc:209
void disconnect(SampleSource *source)
Definition SampleAverager.cc:204
void addSampleClientForTag(SampleClient *client, const SampleTag *)
Add a Client for a given SampleTag.
Definition SampleAverager.h:104
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleAverager.h:69
SampleAverager()
Definition SampleAverager.cc:41
std::map< dsm_sample_id_t, std::vector< unsigned int > > _lenmap
Definition SampleAverager.h:181
std::map< dsm_sample_id_t, std::vector< unsigned int > > _inmap
Definition SampleAverager.h:179
int getClientCount() const
How many SampleClients are currently in my list.
Definition SampleAverager.h:115
void setAveragePeriodSecs(float val)
Set average period.
Definition SampleAverager.h:52
int _averagePeriodUsecs
Length of average, in microseconds.
Definition SampleAverager.h:167
float getAveragePeriodSecs() const
Get average period.
Definition SampleAverager.h:61
std::list< const SampleTag * > getSampleTags() const
Get the output SampleTags.
Definition SampleAverager.h:74
std::map< dsm_sample_id_t, std::vector< unsigned int > > _outmap
Definition SampleAverager.h:183
Pure virtual interface of a client of Samples.
Definition SampleClient.h:38
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
SampleTagIterator getSampleTagIterator() const
Definition SampleSourceSupport.cc:75
int getClientCount() const
How many SampleClients are currently in my list.
Definition SampleSourceSupport.cc:136
void removeSampleTag(const SampleTag *tag)
Definition SampleSourceSupport.cc:67
const SampleStats & getSampleStats() const
Definition SampleSourceSupport.h:149
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition SampleSourceSupport.cc:60
std::list< const SampleTag * > getSampleTags() const
What SampleTags am I a SampleSource for?
Definition SampleSourceSupport.cc:54
Pure virtual interface for a source of Samples.
Definition SampleSource.h:48
A source of samples.
Definition SampleStats.h:41
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition NidsIterators.h:218
Class describing a group of variables that are sampled and handled together.
Definition SampleTag.h:88
virtual void setRate(double val)
Set sampling rate in samples/sec.
Definition SampleTag.h:202
Interface to a data sample.
Definition Sample.h:190
Class describing a sampled variable.
Definition Variable.h:47
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
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:62
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31
#define USECS_PER_SEC
Definition ublox.cc:59