nidas v1.2.3
SampleSorter.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_SAMPLESORTER_H
28#define NIDAS_CORE_SAMPLESORTER_H
29
30#include "SampleThread.h"
31#include "SampleSourceSupport.h"
32#include "SortedSampleSet.h"
33
34namespace nidas { namespace core {
35
52{
53public:
54
62 SampleSorter(const std::string& name,bool raw);
63
64 virtual ~SampleSorter();
65
66 void setKeepStats(bool val)
67 {
69 }
70
71 bool getKeepStats() const
72 {
73 return _source.getKeepStats();
74 }
75
80
85
90 void addSampleTag(const SampleTag* tag) throw()
91 {
93 }
94
95 void removeSampleTag(const SampleTag* tag) throw()
96 {
98 }
99
103 std::list<const SampleTag*> getSampleTags() const
104 {
105 return _source.getSampleTags();
106 }
107
115
119 void addSampleClient(SampleClient* client) throw()
120 {
121 _source.addSampleClient(client);
122 }
123
124 void removeSampleClient(SampleClient* client) throw()
125 {
127 }
128
133 void addSampleClientForTag(SampleClient* client,const SampleTag* tag) throw()
134 {
135 _source.addSampleClientForTag(client,tag);
136 }
137
138 void removeSampleClientForTag(SampleClient* client,const SampleTag* tag) throw()
139 {
141 }
142
143 int getClientCount() const throw()
144 {
145 return _source.getClientCount();
146 }
147
149 {
150 return _source.getSampleStats();
151 }
152
158 void flush() throw();
159
163 void interrupt();
164
168 bool receive(const Sample *s) throw();
169
177 size_t size() const { return _samples.size(); }
178
179 void setLengthSecs(float val)
180 {
181 _sorterLengthUsec = (unsigned int)((double)val * USECS_PER_SEC);
182 }
183
184 float getLengthSecs() const
185 {
186 return (double)_sorterLengthUsec / USECS_PER_SEC;
187 }
188
193 void setHeapMax(size_t val) { _heapMax = val; }
194
195 size_t getHeapMax() const { return _heapMax; }
196
200 size_t getHeapSize() const { return _heapSize; }
201
209 void setHeapBlock(bool val) { _heapBlock = val; }
210
211 bool getHeapBlock() const { return _heapBlock; }
212
218 {
219 return _discardedSamples;
220 }
221
226 size_t getNumFutureSamples() const
227 {
229 }
230
234 size_t getNumEarlySamples() const
235 {
236 return _earlySamples;
237 }
243 void setRealTime(bool val)
244 {
245 _realTime = val;
246 }
247
248 bool getRealTime() const
249 {
250 return _realTime;
251 }
252
263 void setLateSampleCacheSize(unsigned int val)
264 {
266 }
267
268 unsigned int getLateSampleCacheSize() const
269 {
271 }
272
273private:
274
276
282 int run();
283
287 unsigned int _sorterLengthUsec;
288
290
296 void heapDecrement(size_t bytes);
297
299
301
306 size_t _heapMax;
307
311 size_t _heapSize;
312
325
327
329
334 unsigned int _discardedSamples;
335
341
349 unsigned int _earlySamples;
350
355
360
362
364
365 SampleT<char> _dummy;
366
373
375
377
382
387
388};
389
390}} // namespace nidas namespace core
391
392#endif
Pure virtual interface of a client of Samples.
Definition SampleClient.h:38
A SampleClient that sorts its received samples, using an STL multiset, and then sends the sorted samp...
Definition SampleSorter.h:52
bool getKeepStats() const
Definition SampleSorter.h:71
long long _maxSorterLengthUsec
Definition SampleSorter.h:374
SampleT< char > _dummy
Definition SampleSorter.h:365
void flush()
Implementation of SampleSource::flush().
Definition SampleSorter.cc:431
unsigned int _lateSampleCacheSize
Definition SampleSorter.h:376
size_t _heapSize
Current heap size, in bytes.
Definition SampleSorter.h:311
void interrupt()
Interrupt sorting thread.
Definition SampleSorter.cc:364
size_t getHeapMax() const
Definition SampleSorter.h:195
void setHeapMax(size_t val)
Set the maximum amount of heap memory to use for sorting samples.
Definition SampleSorter.h:193
int getClientCount() const
How many SampleClients are currently in my list.
Definition SampleSorter.h:143
size_t size() const
Current number of samples in the sorter.
Definition SampleSorter.h:177
bool _flushed
Definition SampleSorter.h:363
SortedSampleSet _samples
Definition SampleSorter.h:289
nidas::util::Cond _sampleSetCond
Definition SampleSorter.h:298
int run()
Thread run function.
Definition SampleSorter.cc:141
void addSampleClientForTag(SampleClient *client, const SampleTag *tag)
Add a Client for a given SampleTag.
Definition SampleSorter.h:133
bool _realTime
Is this sorter running in real-time? If so then we can screen for bad time-tags by checking against t...
Definition SampleSorter.h:372
size_t _heapMax
Limit on the maximum size of memory to use while buffering samples.
Definition SampleSorter.h:306
size_t getHeapSize() const
Get the current amount of heap being used for sorting.
Definition SampleSorter.h:200
nidas::util::Cond _heapCond
Definition SampleSorter.h:326
unsigned int _discardedSamples
Number of samples discarded because of _heapSize > _heapMax and heapBlock == true.
Definition SampleSorter.h:334
void removeSampleClientForTag(SampleClient *client, const SampleTag *tag)
Remove a SampleClient for a given SampleTag from this SampleSource.
Definition SampleSorter.h:138
float getLengthSecs() const
Definition SampleSorter.h:184
SampleTagIterator getSampleTagIterator() const
Implementation of SampleSource::getSampleTagIterator().
Definition SampleSorter.h:111
std::list< const SampleTag * > getSampleTags() const
Implementation of SampleSource::getSampleTags().
Definition SampleSorter.h:103
int _discardWarningCount
How often to log warnings about discardedSamples.
Definition SampleSorter.h:354
bool receive(const Sample *s)
Implementation of SampleClient::receive().
Definition SampleSorter.cc:504
size_t getNumFutureSamples() const
Number of samples discarded because their timetags were in the future.
Definition SampleSorter.h:226
int _earlyWarningCount
How often to log warnings about early samples.
Definition SampleSorter.h:359
SampleSorter & operator=(const SampleSorter &)
No assignment.
SampleSource * getRawSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleSorter.h:76
nidas::util::Cond _flushCond
Definition SampleSorter.h:300
unsigned int _earlySamples
Samples which are earlier than the current latest sample in the sorter minus the sorter length.
Definition SampleSorter.h:349
bool _heapBlock
_heapBlock controls what happens when the number of bytes in _samples exceeds _heapMax.
Definition SampleSorter.h:324
void setHeapBlock(bool val)
Definition SampleSorter.h:209
void setLateSampleCacheSize(unsigned int val)
When aging-off samples, cache this number of samples with the latest time tags.
Definition SampleSorter.h:263
void setLengthSecs(float val)
Definition SampleSorter.h:179
void heapDecrement(size_t bytes)
Utility function to decrement the heap size after writing one or more samples.
Definition SampleSorter.cc:403
bool getRealTime() const
Definition SampleSorter.h:248
void addSampleTag(const SampleTag *tag)
How to tell this SampleSorter what sample tags it will be sorting.
Definition SampleSorter.h:90
SampleSorter(const std::string &name, bool raw)
Constructor.
Definition SampleSorter.cc:83
unsigned int _realTimeFutureSamples
Number of samples discarded because getRealTime() is true and the samples have timetags later than th...
Definition SampleSorter.h:340
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 SampleSorter.h:243
void removeSampleTag(const SampleTag *tag)
Definition SampleSorter.h:95
void addSampleClient(SampleClient *client)
Implementation of SampleSource::addSampleClient().
Definition SampleSorter.h:119
void removeSampleClient(SampleClient *client)
Remove a SampleClient from this SampleSource.
Definition SampleSorter.h:124
const SampleStats & getSampleStats() const
Definition SampleSorter.h:148
size_t getNumDiscardedSamples() const
Number of samples discarded because of _heapSize > _heapMax and heapBlock == true.
Definition SampleSorter.h:217
bool _heapExceeded
Definition SampleSorter.h:328
SampleSource * getProcessedSampleSource()
Several objects in NIDAS can be both a SampleSource of raw Samples and processed Samples.
Definition SampleSorter.h:81
SampleSorter(const SampleSorter &)
No copy.
bool getHeapBlock() const
Definition SampleSorter.h:211
void setKeepStats(bool val)
Definition SampleSorter.h:66
unsigned int _sorterLengthUsec
Length of SampleSorter, in micro-seconds.
Definition SampleSorter.h:287
size_t getNumEarlySamples() const
Number of early samples, which may not be sorted.
Definition SampleSorter.h:234
SampleSourceSupport _source
Definition SampleSorter.h:275
bool _doFlush
Definition SampleSorter.h:361
virtual ~SampleSorter()
Definition SampleSorter.cc:103
unsigned int getLateSampleCacheSize() const
Definition SampleSorter.h:268
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
std::multiset< const Sample *, SampleTimetagComparator > SortedSampleSet
A multiset for storing samples sorted by timetag.
Definition SortedSampleSet.h:107
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
#define USECS_PER_SEC
Definition ublox.cc:59