-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimeblockbuffer.h
82 lines (64 loc) · 2.29 KB
/
timeblockbuffer.h
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
#ifndef DYSCO_TIME_BLOCK_BUFFER_H
#define DYSCO_TIME_BLOCK_BUFFER_H
#include "uvector.h"
#include <complex>
#include <vector>
template <typename data_t>
class TimeBlockBuffer {
public:
typedef unsigned symbol_t;
TimeBlockBuffer(size_t nPol, size_t nChannels)
: _nPol(nPol), _nChannels(nChannels) {}
bool Empty() const { return _data.empty(); }
void resize(size_t nRows) { _data.resize(nRows); }
struct DataRow {
size_t antenna1, antenna2;
std::vector<data_t> visibilities;
};
DataRow &operator[](size_t rowIndex) { return _data[rowIndex]; }
void ResetData() { _data.clear(); }
void SetData(size_t blockRow, size_t antenna1, size_t antenna2,
const data_t *data) {
if (_data.size() <= blockRow) _data.resize(blockRow + 1);
DataRow &newRow = _data[blockRow];
newRow.antenna1 = antenna1;
newRow.antenna2 = antenna2;
newRow.visibilities.resize(_nPol * _nChannels);
for (size_t i = 0; i != _nPol * _nChannels; ++i)
newRow.visibilities[i] = data[i];
}
void GetData(size_t blockRow, data_t *destination) const {
const data_t *srcPtr = _data[blockRow].visibilities.data();
memcpy(destination, srcPtr,
sizeof(data_t) * _data[blockRow].visibilities.size());
}
size_t NRows() const { return _data.size(); }
size_t MaxAntennaIndex() const {
size_t maxAntennaIndex = 0;
for (const DataRow &row : _data) {
maxAntennaIndex =
std::max(maxAntennaIndex, std::max(row.antenna1, row.antenna2));
}
return maxAntennaIndex;
}
const std::vector<DataRow> &GetVector() const { return _data; }
std::vector<DataRow> &GetVector() { return _data; }
template <typename other_t>
void ConvertVector(
std::vector<typename TimeBlockBuffer<other_t>::DataRow> &vector) const {
vector.resize(_data.size());
for (size_t i = 0; i != _data.size(); ++i) {
const DataRow &rowIn = _data[i];
typename TimeBlockBuffer<other_t>::DataRow &rowOut = vector[i];
rowOut.antenna1 = rowIn.antenna1;
rowOut.antenna2 = rowIn.antenna2;
rowOut.visibilities.assign(rowIn.visibilities.begin(),
rowIn.visibilities.end());
}
}
private:
size_t _nPol, _nChannels;
std::vector<DataRow> _data;
};
template class TimeBlockBuffer<std::complex<float>>;
#endif