-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmask_measurements_ringbuf.cpp
84 lines (72 loc) · 2.07 KB
/
mask_measurements_ringbuf.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
#include "rf_pipelines_internals.hpp"
#include "rf_pipelines_inventory.hpp"
using namespace std;
namespace rf_pipelines {
#if 0
}; // pacify emacs c-mode
#endif
typedef lock_guard<mutex> ulock;
mask_measurements::mask_measurements(ssize_t pos_, int nf_, int nt_)
{
this->pos = pos_;
this->nf = nf_;
this->nt = nt_;
this->nsamples = nf_ * nt_;
this->freqs_unmasked = make_sptr<int> (nf_);
}
mask_measurements_ringbuf::mask_measurements_ringbuf(int nhistory) :
next(0),
maxsize(nhistory)
{
if (nhistory <= 0)
throw runtime_error("rf_pipelines::mask_measurements_ringbuf constructor called with nhistory <= 0");
// Allocate ring buffer
ringbuf.resize(nhistory);
}
void mask_measurements_ringbuf::add(rf_pipelines::mask_measurements& meas) {
ulock l(mutex);
ringbuf[next % maxsize] = meas;
next++;
}
std::vector<rf_pipelines::mask_measurements>
mask_measurements_ringbuf::get_all_measurements() {
std::vector<rf_pipelines::mask_measurements> copy;
{
ulock l(mutex);
// The returned vector has the chunks listed in time order
int start;
int end;
if (next <= maxsize) {
start = 0;
end = next;
} else {
start = next;
end = next + maxsize;
}
for (int i=start; i<end; i++)
copy.push_back(ringbuf[i % maxsize]);
}
return copy;
}
std::unordered_map<std::string, float>
mask_measurements_ringbuf::get_stats(int nchunks) {
unordered_map<string, float> stats;
float totsamp = 0;
float totunmasked = 0;
if (nchunks > maxsize)
nchunks = maxsize;
{
ulock l(mutex);
int start = next - nchunks;
if (start < 0)
start = 0;
for (int i=start; i<next; i++) {
int reali = (i % maxsize);
totsamp += ringbuf[reali].nsamples;
totunmasked += ringbuf[reali].nsamples_unmasked;
}
}
stats["rfi_mask_pct_masked"] = 100. * (totsamp - totunmasked) / max(totsamp, 1.f);
return stats;
}
} // namespace rf_pipelines