casacore
Loading...
Searching...
No Matches
timeblockbuffer.h
Go to the documentation of this file.
1#ifndef DYSCO_TIME_BLOCK_BUFFER_H
2#define DYSCO_TIME_BLOCK_BUFFER_H
3
4#include "uvector.h"
5
6#include <complex>
7#include <vector>
8
9template <typename data_t>
11 public:
12 typedef unsigned symbol_t;
13
14 TimeBlockBuffer(size_t nPol, size_t nChannels) : _nPol(nPol), _nChannels(nChannels) {}
15
16 bool Empty() const { return _data.empty(); }
17
18 void resize(size_t nRows) { _data.resize(nRows); }
19
20 struct DataRow {
22 std::vector<data_t> visibilities;
23 };
24
25 DataRow &operator[](size_t rowIndex) { return _data[rowIndex]; }
26
27 void ResetData() { _data.clear(); }
28
29 void SetData(size_t blockRow, size_t antenna1, size_t antenna2, const data_t *data) {
30 if (_data.size() <= blockRow) _data.resize(blockRow + 1);
31 DataRow &newRow = _data[blockRow];
32 newRow.antenna1 = antenna1;
33 newRow.antenna2 = antenna2;
34 newRow.visibilities.resize(_nPol * _nChannels);
35 for (size_t i = 0; i != _nPol * _nChannels; ++i) newRow.visibilities[i] = data[i];
36 }
37
38 void GetData(size_t blockRow, data_t *destination) const {
39 const data_t *srcPtr = _data[blockRow].visibilities.data();
40 memcpy(destination, srcPtr, sizeof(data_t) * _data[blockRow].visibilities.size());
41 }
42
43 size_t NRows() const { return _data.size(); }
44
45 size_t MaxAntennaIndex() const {
46 size_t maxAntennaIndex = 0;
47 for (const DataRow &row : _data) {
48 maxAntennaIndex = std::max(maxAntennaIndex, std::max(row.antenna1, row.antenna2));
49 }
50 return maxAntennaIndex;
51 }
52
53 const std::vector<DataRow> &GetVector() const { return _data; }
54 std::vector<DataRow> &GetVector() { return _data; }
55
56 template <typename other_t>
57 void ConvertVector(std::vector<typename TimeBlockBuffer<other_t>::DataRow> &vector) const {
58 vector.resize(_data.size());
59 for (size_t i = 0; i != _data.size(); ++i) {
60 const DataRow &rowIn = _data[i];
61 typename TimeBlockBuffer<other_t>::DataRow &rowOut = vector[i];
62 rowOut.antenna1 = rowIn.antenna1;
63 rowOut.antenna2 = rowIn.antenna2;
64 rowOut.visibilities.assign(rowIn.visibilities.begin(), rowIn.visibilities.end());
65 }
66 }
67
68 private:
70 std::vector<DataRow> _data;
71};
72
74
75#endif
const std::vector< DataRow > & GetVector() const
std::vector< DataRow > _data
size_t NRows() const
bool Empty() const
unsigned symbol_t
std::vector< DataRow > & GetVector()
DataRow & operator[](size_t rowIndex)
void SetData(size_t blockRow, size_t antenna1, size_t antenna2, const data_t *data)
size_t MaxAntennaIndex() const
TimeBlockBuffer(size_t nPol, size_t nChannels)
void ConvertVector(std::vector< typename TimeBlockBuffer< other_t >::DataRow > &vector) const
size_t _nChannels
void GetData(size_t blockRow, data_t *destination) const
void resize(size_t nRows)
std::vector< data_t > visibilities
Header file for UVector and its relational and swap functions.