nidas v1.2.3
SampleBuffer.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 ** 2009, 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_SAMPLEBUFFER_H
28#define NIDAS_CORE_SAMPLEBUFFER_H
29
30#include <iostream>
31#include <deque>
32
33#include "SampleThread.h"
34#include "SampleSourceSupport.h"
35
36namespace nidas { namespace core {
37
44{
45public:
46
50 SampleBuffer(const std::string& name,bool raw);
51
52 virtual ~SampleBuffer();
53
54 void setKeepStats(bool val)
55 {
57 }
58
59 bool getKeepStats() const
60 {
61 return _source.getKeepStats();
62 }
63
68
73
78 void addSampleTag(const SampleTag* tag) throw()
79 {
81 }
82
83 void removeSampleTag(const SampleTag* tag) throw()
84 {
86 }
87
91 std::list<const SampleTag*> getSampleTags() const
92 {
93 return _source.getSampleTags();
94 }
95
103
107 void addSampleClient(SampleClient* client) throw()
108 {
109 _source.addSampleClient(client);
110 }
111
112 void removeSampleClient(SampleClient* client) throw()
113 {
115 }
116
121 void addSampleClientForTag(SampleClient* client,const SampleTag* tag) throw()
122 {
123 _source.addSampleClientForTag(client,tag);
124 }
125
126 void removeSampleClientForTag(SampleClient* client,const SampleTag* tag) throw()
127 {
129 }
130
131 int getClientCount() const throw()
132 {
133 return _source.getClientCount();
134 }
135
137 {
138 return _source.getSampleStats();
139 }
140
144 void flush() throw();
145
146 void interrupt();
147
154 bool receive(const Sample *s) throw();
155
165 size_t size() const;
166
167 void setLengthSecs(float)
168 {
169 }
170
171 float getLengthSecs() const
172 {
173 return 0.0;
174 }
175
180 void setHeapMax(size_t val) { _heapMax = val; }
181
182 size_t getHeapMax() const { return _heapMax; }
183
187 size_t getHeapSize() const { return _heapSize; }
188
196 void setHeapBlock(bool val) { _heapBlock = val; }
197
198 bool getHeapBlock() const { return _heapBlock; }
199
200 // void setDebug(bool val) { debug = val; }
201
207 {
208 return _discardedSamples;
209 }
210
215 size_t getNumFutureSamples() const
216 {
218 }
219
225 void setRealTime(bool val)
226 {
227 _realTime = val;
228 }
229
230 bool getRealTime() const
231 {
232 return _realTime;
233 }
234
235 void setLateSampleCacheSize(unsigned int)
236 {
237 }
238
239 unsigned int getLateSampleCacheSize() const
240 {
241 return 0;
242 }
243
244private:
245
249 int run();
250
251 std::vector<const Sample*> _sampleBufs[2];
252
253 std::vector<const Sample*>* _inserterBuf;
254
255 std::vector<const Sample*>* _consumerBuf;
256
258
264 void heapDecrement(size_t bytes);
265
267
269
274 size_t _heapMax;
275
279 size_t _heapSize;
280
293
295
301
307
312
314
316
323
324 size_t sizeNoLock() const;
325
326 bool emptyNoLock() const;
327
328
333
338
339};
340
341}} // namespace nidas namespace core
342
343#endif
A SampleClient that buffers its received samples, using a pair of STL vectors, and then sends the buf...
Definition SampleBuffer.h:44
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition SampleBuffer.h:99
bool _doFlush
Definition SampleBuffer.h:313
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition SampleBuffer.h:107
bool _heapBlock
_heapBlock controls what happens when the number of bytes in _samples exceeds _heapMax.
Definition SampleBuffer.h:292
size_t getNumFutureSamples() const
Number of samples discarded because their timetags were in the future.
Definition SampleBuffer.h:215
unsigned int getLateSampleCacheSize() const
Definition SampleBuffer.h:239
SampleSourceSupport _source
Definition SampleBuffer.h:257
void interrupt()
Interrupt this thread.
Definition SampleBuffer.cc:294
std::vector< const Sample * > * _inserterBuf
Definition SampleBuffer.h:253
void addSampleTag(const SampleTag *tag)
How to tell this SampleBuffer what sample tags it will be sorting.
Definition SampleBuffer.h:78
nidas::util::Cond _sampleBufCond
Definition SampleBuffer.h:266
int getClientCount() const
How many SampleClients are currently in my list.
Definition SampleBuffer.h:131
SampleBuffer(const std::string &name, bool raw)
Constructor.
Definition SampleBuffer.cc:41
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleBuffer.h:69
size_t _heapMax
Limit on the maximum size of memory to use while buffering samples.
Definition SampleBuffer.h:274
bool getRealTime() const
Definition SampleBuffer.h:230
void addSampleClientForTag(SampleClient *client, const SampleTag *tag)
Add a Client for a given SampleTag.
Definition SampleBuffer.h:121
std::vector< const Sample * > * _consumerBuf
Definition SampleBuffer.h:255
size_t _heapSize
Current heap size, in bytes.
Definition SampleBuffer.h:279
size_t _realTimeFutureSamples
Number of samples discarded because getRealTime() is true and the samples have timetags later than th...
Definition SampleBuffer.h:306
void setKeepStats(bool val)
Definition SampleBuffer.h:54
virtual ~SampleBuffer()
Definition SampleBuffer.cc:55
bool emptyNoLock() const
Definition SampleBuffer.cc:82
void removeSampleClientForTag(SampleClient *client, const SampleTag *tag)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition SampleBuffer.h:126
size_t _discardedSamples
Number of samples discarded because of _heapSize > _heapMax and heapBlock == true.
Definition SampleBuffer.h:300
void heapDecrement(size_t bytes)
Utility function to decrement the heap size after writing one or more samples.
Definition SampleBuffer.cc:317
std::list< const SampleTag * > getSampleTags() const
Implementation of SampleSource::getSampleTags().
Definition SampleBuffer.h:91
int _discardWarningCount
How often to log warnings about discardedSamples.
Definition SampleBuffer.h:311
bool receive(const Sample *s)
Insert a sample in the buffer, where it is then passed on to SampleClients.
Definition SampleBuffer.cc:334
bool _realTime
Is this sorter running in real-time? If so then we can screen for bad time-tags by checking against t...
Definition SampleBuffer.h:322
nidas::util::Cond _flushCond
Definition SampleBuffer.h:268
size_t sizeNoLock() const
Definition SampleBuffer.cc:77
size_t getHeapSize() const
Get the current amount of heap being used for sorting.
Definition SampleBuffer.h:187
void setHeapBlock(bool val)
Definition SampleBuffer.h:196
void setHeapMax(size_t val)
Set the maximum amount of heap memory to use for sorting samples.
Definition SampleBuffer.h:180
void setLengthSecs(float)
Definition SampleBuffer.h:167
const SampleStats & getSampleStats() const
Definition SampleBuffer.h:136
size_t size() const
Current number of samples in the buffer.
Definition SampleBuffer.cc:71
size_t getNumDiscardedSamples() const
Number of samples discarded because of _heapSize > _heapMax and heapBlock == true.
Definition SampleBuffer.h:206
void setLateSampleCacheSize(unsigned int)
Definition SampleBuffer.h:235
SampleBuffer(const SampleBuffer &)
No copy.
SampleBuffer & operator=(const SampleBuffer &)
No assignment.
std::vector< const Sample * > _sampleBufs[2]
Definition SampleBuffer.h:251
void setRealTime(bool val)
Is this sorter running in real-time? If so then we can screen for bad time-tags by checking against t...
Definition SampleBuffer.h:225
nidas::util::Cond _heapCond
Definition SampleBuffer.h:294
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleBuffer.h:64
float getLengthSecs() const
Definition SampleBuffer.h:171
int run()
Thread run function.
Definition SampleBuffer.cc:90
bool getKeepStats() const
Definition SampleBuffer.h:59
bool _flushed
Definition SampleBuffer.h:315
void flush()
flush all samples from buffer, distributing them to SampleClients.
Definition SampleBuffer.cc:348
size_t getHeapMax() const
Definition SampleBuffer.h:182
bool getHeapBlock() const
Definition SampleBuffer.h:198
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition SampleBuffer.h:112
void removeSampleTag(const SampleTag *tag)
Definition SampleBuffer.h:83
Pure virtual interface of a client of Samples.
Definition SampleClient.h:38
A source of samples.
Definition SampleSourceSupport.h:47
bool getKeepStats() const
Definition SampleSourceSupport.h:159
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
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleSourceSupport.h:60
void removeSampleClientForTag(SampleClient *c, const SampleTag *)
Add a SampleClient to this SampleSource.
Definition SampleSourceSupport.cc:121
void addSampleClientForTag(SampleClient *c, const SampleTag *)
Add a SampleClient to this SampleSource.
Definition SampleSourceSupport.cc:101
void addSampleClient(SampleClient *c)
Add a SampleClient to this SampleSource.
Definition SampleSourceSupport.cc:80
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleSourceSupport.h:66
void setKeepStats(bool val)
Definition SampleSourceSupport.h:154
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
Interface for a Thread for buffering samples.
Definition SampleThread.h:54
Interface to a data sample.
Definition Sample.h:190
A wrapper class for a Posix condition variable.
Definition ThreadSupport.h:258
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
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31