-
Notifications
You must be signed in to change notification settings - Fork 20
/
waveformprocessor.cpp
632 lines (428 loc) · 18.4 KB
/
waveformprocessor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
/***************************************************************************
* Copyright (C) gempa GmbH *
* All rights reserved. *
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
* *
* GNU Affero General Public License Usage *
* This file may be used under the terms of the GNU Affero *
* Public License version 3.0 as published by the Free Software Foundation *
* and appearing in the file LICENSE included in the packaging of this *
* file. Please review the following information to ensure the GNU Affero *
* Public License version 3.0 requirements will be met: *
* https://www.gnu.org/licenses/agpl-3.0.html. *
* *
* Other Usage *
* Alternatively, this file may be used in accordance with the terms and *
* conditions contained in a signed written agreement between you and *
* gempa GmbH. *
***************************************************************************/
#define SEISCOMP_COMPONENT WaveformProcessor
#include <seiscomp/processing/waveformprocessor.h>
#include <seiscomp/processing/waveformoperator.h>
#include <seiscomp/logging/log.h>
#include <functional>
namespace Seiscomp {
namespace Processing {
IMPLEMENT_SC_ABSTRACT_CLASS(WaveformProcessor, "WaveformProcessor");
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WaveformProcessor::StreamState::StreamState()
: lastSample(0), neededSamples(0), receivedSamples(0), initialized(false),
fsamp(0.0), filter(nullptr) {
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WaveformProcessor::StreamState::~StreamState() {
if ( filter != nullptr ) delete filter;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WaveformProcessor::WaveformProcessor(const Core::TimeSpan &initTime,
const Core::TimeSpan &gapThreshold)
: _enabled(true),
_initTime(initTime), _gapThreshold(gapThreshold), _usedComponent(Vertical) {
_gapTolerance = 0.;
_enableGapInterpolation = false;
_enableSaturationCheck = false;
_saturationThreshold = -1;
reset();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WaveformProcessor::~WaveformProcessor() {
close();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stream &WaveformProcessor::streamConfig(Component c) {
return _streamConfig[c];
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
const Stream &WaveformProcessor::streamConfig(Component c) const {
return _streamConfig[c];
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setFilter(Filter *filter) {
if ( _stream.filter ) delete _stream.filter;
_stream.filter = filter;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setOperator(WaveformOperator *op) {
if ( _operator ) _operator->setStoreFunc(WaveformOperator::StoreFunc());
_operator = op;
if ( _operator ) _operator->setStoreFunc(std::bind(&WaveformProcessor::store, this, std::placeholders::_1));
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setGapTolerance(const Core::TimeSpan &length) {
_gapTolerance = length;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
const Core::TimeSpan &WaveformProcessor::gapTolerance() const {
return _gapTolerance;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::reset() {
Filter *tmp = _stream.filter;
_stream = StreamState();
if ( _operator ) _operator->reset();
if ( tmp != nullptr ) {
_stream.filter = tmp->clone();
delete tmp;
}
_status = WaitingForData;
_statusValue = 0.;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setEnabled(bool e) {
if ( _enabled == e ) return;
_enabled = e;
_enabled?enabled():disabled();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setGapInterpolationEnabled(bool enable) {
_enableGapInterpolation = enable;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::isGapInterpolationEnabled() const {
return _enableGapInterpolation;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setSaturationCheckEnabled(bool enable) {
_enableSaturationCheck = enable;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setSaturationThreshold(double t) {
_saturationThreshold = t;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::isSaturationCheckEnabled() const {
return _enableSaturationCheck;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Core::TimeWindow WaveformProcessor::dataTimeWindow() const {
return _stream.dataTimeWindow;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
const Record *WaveformProcessor::lastRecord() const {
return _stream.lastRecord.get();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::initFilter(double fsamp) {
_stream.fsamp = fsamp;
_stream.neededSamples = static_cast<size_t>(_initTime * _stream.fsamp + 0.5);
if ( _stream.filter )
_stream.filter->setSamplingFrequency(fsamp);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
double WaveformProcessor::samplingFrequency() const {
return _stream.fsamp;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::feed(const Record *rec) {
if ( rec->sampleCount() == 0 ) return false;
if ( !_operator ) return store(rec);
Status stat = _operator->feed(rec);
if ( stat > Terminated ) {
setStatus(stat, -1);
return false;
}
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::store(const Record *record) {
if ( _status > InProgress ) return false;
if ( record->data() == nullptr ) return false;
DoubleArrayPtr arr = (DoubleArray*)record->data()->copy(Array::DOUBLE);
if ( _stream.lastRecord ) {
if ( record == _stream.lastRecord ) return false;
if ( record->samplingFrequency() != _stream.fsamp ) {
SEISCOMP_WARNING("%s: sampling rate changed, resetting stream: %f != %f",
record->streamID().c_str(),
record->samplingFrequency(), _stream.fsamp);
_stream.lastRecord = nullptr;
}
else {
Core::TimeSpan gap = record->startTime() - _stream.dataTimeWindow.endTime() - Core::TimeSpan(0,1);
double gapSecs = (double)gap;
if ( gap > _gapThreshold ) {
size_t gapsize = static_cast<size_t>(ceil(_stream.fsamp * gapSecs));
bool handled = handleGap(_stream.filter, gap, _stream.lastSample, (*arr)[0], gapsize);
if ( handled )
SEISCOMP_DEBUG("[%s] detected gap of %.6f secs or %lu samples (handled)",
record->streamID().c_str(), (double)gap, (unsigned long)gapsize);
else {
SEISCOMP_DEBUG("[%s] detected gap of %.6f secs or %lu samples (NOT handled): status = %s",
record->streamID().c_str(), (double)gap, (unsigned long)gapsize,
status().toString());
if ( _status > InProgress ) return false;
}
}
else if ( gapSecs < 0 ) {
size_t gapsize = static_cast<size_t>(ceil(-_stream.fsamp * gapSecs));
if ( gapsize > 1 ) return false;
}
// update the received data timewindow
_stream.dataTimeWindow.setEndTime(record->endTime());
}
}
// NOTE: Do not use else here, because lastRecord can be set nullptr
// when calling reset() in handleGap(...)
if ( !_stream.lastRecord ) {
try {
setupStream(record->samplingFrequency());
}
catch ( std::exception &e ) {
SEISCOMP_WARNING("%s: setup stream: %s", record->streamID().c_str(),
e.what());
return false;
}
// update the received data timewindow
_stream.dataTimeWindow = record->timeWindow();
/*
std::cerr << "Received first record for " << record->streamID() << ", "
<< className() << " [" << record->startTime().iso() << " - " << record->endTime().iso() << std::endl;
*/
if ( _stream.filter ) {
_stream.filter->setStartTime(record->startTime());
_stream.filter->setStreamID(record->networkCode(), record->stationCode(),
record->locationCode(), record->channelCode());
}
}
_stream.lastSample = (*arr)[arr->size()-1];
// Fill the values and do the actual filtering
fill(arr->size(), arr->typedData());
if ( _status > InProgress ) return false;
if ( !_stream.initialized ) {
if ( _stream.receivedSamples > _stream.neededSamples ) {
//_initialized = true;
process(record, *arr);
// NOTE: To allow derived classes to notice modification of the variable
// _initialized, it is necessary to set this after calling process.
_stream.initialized = true;
}
}
else
// Call process to cause a derived processor to work on the data.
process(record, *arr);
_stream.lastRecord = record;
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int WaveformProcessor::feedSequence(const RecordSequence *sequence) {
int count = 0;
if ( sequence == nullptr ) return count;
for ( RecordSequence::const_iterator it = sequence->begin();
it != sequence->end(); ++it )
if ( feed(it->get()) ) ++count;
return count;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setUserData(Core::BaseObject *obj) const {
_userData = obj;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Core::BaseObject *WaveformProcessor::userData() const {
return _userData.get();
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::fill(size_t n, double *samples) {
_stream.receivedSamples += n;
if ( _enableSaturationCheck ) {
for ( size_t i = 0; i < n; ++i ) {
if ( fabs(samples[i]) >= _saturationThreshold ) {
setStatus(DataClipped, samples[i]);
break;
}
}
}
if ( _stream.filter ) _stream.filter->apply(n, samples);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::handleGap(Filter *filter, const Core::TimeSpan& span,
double lastSample, double nextSample,
size_t missingSamples) {
if ( span <= _gapTolerance ) {
if ( _enableGapInterpolation ) {
double delta = nextSample - lastSample;
double step = 1./(double)(missingSamples+1);
double di = step;
for ( size_t i = 0; i < missingSamples; ++i, di += step ) {
double value = lastSample + di*delta;
fill(1, &value);
}
return true;
}
}
return false;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::isFinished() const {
return _status > InProgress;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setStatus(Status status, double value) {
_status = status;
_statusValue = value;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::terminate() {
setStatus(Terminated, _status);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
WaveformProcessor::Status WaveformProcessor::status() const {
return _status;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
double WaveformProcessor::statusValue() const {
return _statusValue;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::close() const {}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::parseSaturationThreshold(const Settings &settings,
const std::string &optionName) {
std::string saturationThreshold;
if ( settings.getValue(saturationThreshold, optionName) ) {
Core::trim(saturationThreshold);
if ( saturationThreshold == "false" ) {
setSaturationCheckEnabled(false);
return true;
}
// Parse it
size_t atPos = saturationThreshold.find('@');
double sat_thrs = -1;
if ( atPos == std::string::npos ) {
// This is an absolute value
if ( !Core::fromString(sat_thrs, saturationThreshold) ) {
SEISCOMP_ERROR("Invalid saturation threshold: %s", saturationThreshold.c_str());
return false;
}
}
else {
std::string strBits = saturationThreshold.substr(atPos+1);
std::string strValue;
int bits;
double value;
if ( strBits.empty() ) {
SEISCOMP_ERROR("No effective bits specified: %s",
saturationThreshold.c_str());
return false;
}
if ( !Core::fromString(bits, strBits) ) {
SEISCOMP_ERROR("Invalid saturation threshold bits: %s",
saturationThreshold.c_str());
return false;
}
if ( bits <= 0 || bits > 64 ) {
SEISCOMP_ERROR("Number of effective bits out of range: %d", bits);
return false;
}
strValue = saturationThreshold.substr(0, atPos);
Core::trim(strValue);
if ( strValue.empty() ) {
SEISCOMP_ERROR("Saturation threshold relative value is empty: %s",
saturationThreshold.c_str());
return false;
}
bool isPercent = false;
if ( *strValue.rbegin() == '%' ) {
isPercent = true;
strValue.resize(strValue.size()-1);
}
if ( strValue.empty() ) {
SEISCOMP_ERROR("Saturation threshold relative value is empty: %s",
saturationThreshold.c_str());
return false;
}
if ( !Core::fromString(value, strValue) ) {
SEISCOMP_ERROR("Invalid saturation threshold relative value: %s",
saturationThreshold.c_str());
return false;
}
if ( isPercent )
value *= 0.01;
if ( value < 0 || value > 1 ) {
SEISCOMP_ERROR("Number of relative value out of range [0,1]: %f", value);
return false;
}
sat_thrs = (1 << bits) * value;
}
setSaturationThreshold(sat_thrs);
setSaturationCheckEnabled(true);
}
return true;
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void WaveformProcessor::setupStream(double fsamp) {
const Core::TimeSpan minGapThres(2 * 1.0 / fsamp);
if ( minGapThres > _gapThreshold ) {
SEISCOMP_WARNING("Gap threshold smaller than twice the sampling interval: "
"%ld.%06lds < %ld.%06lds. Resetting gap threshold.",
_gapThreshold.seconds(), _gapThreshold.microseconds(),
minGapThres.seconds(), minGapThres.microseconds());
_gapThreshold = minGapThres;
}
initFilter(fsamp);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool WaveformProcessor::setup(const Settings &settings) {
if ( !parseSaturationThreshold(settings, "waveforms.saturationThreshold") )
return false;
return Processor::setup(settings);
}
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
}
}