Loading...
Searching...
No Matches
timeblockbuffer.h
Go to the documentation of this file.
#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
TimeBlockBuffer
Definition timeblockbuffer.h:10
TimeBlockBuffer::GetVector
const std::vector< DataRow > & GetVector() const
Definition timeblockbuffer.h:58
symbol_t::_data
std::vector< DataRow > _data
Definition timeblockbuffer.h:77
TimeBlockBuffer::NRows
size_t NRows() const
Definition timeblockbuffer.h:47
TimeBlockBuffer::Empty
bool Empty() const
Definition timeblockbuffer.h:17
TimeBlockBuffer::ResetData
void ResetData()
Definition timeblockbuffer.h:28
symbol_t::symbol_t
unsigned symbol_t
Definition timeblockbuffer.h:12
TimeBlockBuffer::GetVector
std::vector< DataRow > & GetVector()
Definition timeblockbuffer.h:59
TimeBlockBuffer::operator[]
DataRow & operator[](size_t rowIndex)
Definition timeblockbuffer.h:26
TimeBlockBuffer::SetData
void SetData(size_t blockRow, size_t antenna1, size_t antenna2, const data_t *data)
Definition timeblockbuffer.h:30
TimeBlockBuffer::MaxAntennaIndex
size_t MaxAntennaIndex() const
Definition timeblockbuffer.h:49
symbol_t::_nPol
size_t _nPol
Definition timeblockbuffer.h:76
TimeBlockBuffer::TimeBlockBuffer
TimeBlockBuffer(size_t nPol, size_t nChannels)
Definition timeblockbuffer.h:14
TimeBlockBuffer::ConvertVector
void ConvertVector(std::vector< typename TimeBlockBuffer< other_t >::DataRow > &vector) const
Definition timeblockbuffer.h:62
symbol_t::_nChannels
size_t _nChannels
Definition timeblockbuffer.h:76
TimeBlockBuffer::GetData
void GetData(size_t blockRow, data_t *destination) const
Definition timeblockbuffer.h:41
TimeBlockBuffer::resize
void resize(size_t nRows)
Definition timeblockbuffer.h:19
TimeBlockBuffer::DataRow
Definition timeblockbuffer.h:21
TimeBlockBuffer::DataRow::antenna2
size_t antenna2
Definition timeblockbuffer.h:22
TimeBlockBuffer::DataRow::antenna1
size_t antenna1
Definition timeblockbuffer.h:22
TimeBlockBuffer::DataRow::visibilities
std::vector< data_t > visibilities
Definition timeblockbuffer.h:23
uvector.h
Header file for uvector and its relational and swap functions.