nidas  v1.2-1520
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 
33 namespace nidas { namespace core {
34 
35 class Variable;
36 
37 class SampleAverager : public Resampler {
38 public:
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);
54  _outSample.setRate(val);
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 
83  {
85  }
86 
90  void addSampleClient(SampleClient* client) throw()
91  {
92  _source.addSampleClient(client);
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 
110  void removeSampleClientForTag(SampleClient* client,const SampleTag*) throw()
111  {
112  _source.removeSampleClient(client);
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 
134 
135  void disconnect(SampleSource* source) throw();
136 
137  bool receive(const Sample *s) throw();
138 
139 protected:
140 
141  void init() throw();
142 
143 private:
144 
148  void addSampleTag(const SampleTag* tag) throw ()
149  {
150  _source.addSampleTag(tag);
151  }
152 
153  void removeSampleTag(const SampleTag* tag) throw ()
154  {
156  }
157 
159 
161 
166 
171 
175  std::map<Variable*,unsigned int> _outVarIndices;
176 
177  std::map<dsm_sample_id_t,std::vector<unsigned int> > _inmap;
178 
179  std::map<dsm_sample_id_t,std::vector<unsigned int> > _lenmap;
180 
181  std::map<dsm_sample_id_t,std::vector<unsigned int> > _outmap;
182 
183  unsigned int _ndataValues;
184 
185  double *_sums;
186 
187  int *_cnts;
188 
193 
198 
199 };
200 
201 }} // namespace nidas namespace core
202 
203 #endif
204 
void setAveragePeriodSecs(float val)
Set average period.
Definition: SampleAverager.h:52
void removeSampleClientForTag(SampleClient *client, const SampleTag *)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition: SampleAverager.h:110
std::map< Variable *, unsigned int > _outVarIndices
Index of each requested output variable in the output sample.
Definition: SampleAverager.h:175
Interface for a resampler, simply a SampleClient and a SampleSource.
Definition: Resampler.h:39
virtual ~SampleAverager()
Definition: SampleAverager.cc:74
int * _cnts
Definition: SampleAverager.h:187
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition: SampleAverager.h:90
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
const SampleStats & getSampleStats() const
Definition: SampleAverager.h:125
Pure virtual interface for a source of Samples.
Definition: SampleSource.h:48
SampleTagIterator getSampleTagIterator() const
Definition: SampleSourceSupport.cc:75
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: SampleAverager.h:67
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition: SampleAverager.h:148
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
Definition: SampleAverager.h:37
void connect(SampleSource *source)
Connect the resampler to a SampleSource.
Definition: SampleAverager.cc:97
const SampleStats & getSampleStats() const
Definition: SampleSourceSupport.h:149
void init()
Definition: SampleAverager.cc:210
SampleAverager()
Definition: SampleAverager.cc:41
double * _sums
Definition: SampleAverager.h:185
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition: SampleAverager.h:69
virtual void setRate(double val)
Set sampling rate in samples/sec.
Definition: SampleTag.h:200
void disconnect(SampleSource *source)
Definition: SampleAverager.cc:205
std::list< const SampleTag * > getSampleTags() const
Get the output SampleTags.
Definition: SampleAverager.h:74
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition: SampleAverager.h:95
unsigned int _ndataValues
Definition: SampleAverager.h:183
std::map< dsm_sample_id_t, std::vector< unsigned int > > _lenmap
Definition: SampleAverager.h:179
std::map< dsm_sample_id_t, std::vector< unsigned int > > _inmap
Definition: SampleAverager.h:177
Interface to a data sample.
Definition: Sample.h:189
Class for iterating over the SampleTags of a Project, Site, DSMConfig, or a SampleSource.
Definition: NidsIterators.h:217
float getAveragePeriodSecs() const
Get average period.
Definition: SampleAverager.h:61
SampleAverager & operator=(const SampleAverager &)
No assignment.
Class describing a group of variables that are sampled and handled together.
Definition: SampleTag.h:87
SampleSourceSupport _source
Definition: SampleAverager.h:158
int _averagePeriodUsecs
Length of average, in microseconds.
Definition: SampleAverager.h:165
A source of samples.
Definition: SampleStats.h:41
#define USECS_PER_SEC
Definition: ublox.cc:59
void addSampleClientForTag(SampleClient *client, const SampleTag *)
Add a Client for a given SampleTag.
Definition: SampleAverager.h:104
void removeSampleTag(const SampleTag *tag)
Definition: SampleAverager.h:153
dsm_time_t _endTime
end time of current statistics window.
Definition: SampleAverager.h:170
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition: SampleAverager.h:82
void addVariables(const std::vector< const Variable * > &)
Definition: SampleAverager.cc:80
int getClientCount() const
How many SampleClients are currently in my list.
Definition: SampleSourceSupport.cc:136
void flush()
Implementation of Resampler::flush().
Definition: SampleAverager.cc:222
std::list< const SampleTag * > getSampleTags() const
What SampleTags am I a SampleSource for?
Definition: SampleSourceSupport.cc:54
SampleTag _outSample
Definition: SampleAverager.h:160
int getClientCount() const
How many SampleClients are currently in my list.
Definition: SampleAverager.h:115
bool receive(const Sample *s)
Method called to pass a sample to this client.
Definition: SampleAverager.cc:248
Definition: InvalidParameterException.h:35
void addSampleTag(const SampleTag *tag)
Add a SampleTag to this SampleSource.
Definition: SampleSourceSupport.cc:60
void addVariable(const Variable *var)
Definition: SampleAverager.cc:89
std::map< dsm_sample_id_t, std::vector< unsigned int > > _outmap
Definition: SampleAverager.h:181