casacore
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 
9 template <typename data_t>
11  public:
12  typedef unsigned symbol_t;
13 
14  TimeBlockBuffer(size_t nPol, size_t nChannels)
15  : _nPol(nPol), _nChannels(nChannels) {}
16 
17  bool Empty() const { return _data.empty(); }
18 
19  void resize(size_t nRows) { _data.resize(nRows); }
20 
21  struct DataRow {
22  size_t antenna1, antenna2;
23  std::vector<data_t> visibilities;
24  };
25 
26  DataRow &operator[](size_t rowIndex) { return _data[rowIndex]; }
27 
28  void ResetData() { _data.clear(); }
29 
30  void SetData(size_t blockRow, size_t antenna1, size_t antenna2,
31  const data_t *data) {
32  if (_data.size() <= blockRow) _data.resize(blockRow + 1);
33  DataRow &newRow = _data[blockRow];
34  newRow.antenna1 = antenna1;
35  newRow.antenna2 = antenna2;
36  newRow.visibilities.resize(_nPol * _nChannels);
37  for (size_t i = 0; i != _nPol * _nChannels; ++i)
38  newRow.visibilities[i] = data[i];
39  }
40 
41  void GetData(size_t blockRow, data_t *destination) const {
42  const data_t *srcPtr = _data[blockRow].visibilities.data();
43  memcpy(destination, srcPtr,
44  sizeof(data_t) * _data[blockRow].visibilities.size());
45  }
46 
47  size_t NRows() const { return _data.size(); }
48 
49  size_t MaxAntennaIndex() const {
50  size_t maxAntennaIndex = 0;
51  for (const DataRow &row : _data) {
52  maxAntennaIndex =
53  std::max(maxAntennaIndex, std::max(row.antenna1, row.antenna2));
54  }
55  return maxAntennaIndex;
56  }
57 
58  const std::vector<DataRow> &GetVector() const { return _data; }
59  std::vector<DataRow> &GetVector() { return _data; }
60 
61  template <typename other_t>
63  std::vector<typename TimeBlockBuffer<other_t>::DataRow> &vector) const {
64  vector.resize(_data.size());
65  for (size_t i = 0; i != _data.size(); ++i) {
66  const DataRow &rowIn = _data[i];
67  typename TimeBlockBuffer<other_t>::DataRow &rowOut = vector[i];
68  rowOut.antenna1 = rowIn.antenna1;
69  rowOut.antenna2 = rowIn.antenna2;
70  rowOut.visibilities.assign(rowIn.visibilities.begin(),
71  rowIn.visibilities.end());
72  }
73  }
74 
75  private:
76  size_t _nPol, _nChannels;
77  std::vector<DataRow> _data;
78 };
79 
81 
82 #endif
std::vector< DataRow > _data
size_t NRows() const
bool Empty() const
const std::vector< DataRow > & GetVector() const
DataRow & operator[](size_t rowIndex)
void SetData(size_t blockRow, size_t antenna1, size_t antenna2, const data_t *data)
size_t MaxAntennaIndex() const
std::vector< DataRow > & GetVector()
TimeBlockBuffer(size_t nPol, size_t nChannels)
void ConvertVector(std::vector< typename TimeBlockBuffer< other_t >::DataRow > &vector) const
void GetData(size_t blockRow, data_t *destination) const
void resize(size_t nRows)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
std::vector< data_t > visibilities
Header file for uvector and its relational and swap functions.