Loading...
Searching...
No Matches
StokesIStManColumn.h
Go to the documentation of this file.
#ifndef CASACORE_STOKES_I_ST_MAN_COLUMN_H_
#define CASACORE_STOKES_I_ST_MAN_COLUMN_H_
#include <casacore/tables/DataMan/StManColumn.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/Arrays/IPosition.h>
#include "BufferedColumnarFile.h"
#include <optional>
namespace casacore {
class StokesIStMan;
template <typename T>
void ExpandFromStokesI(T *data, size_t n) {
for (size_t i = 0; i != n; ++i) {
const size_t index = n - i - 1;
const T value = data[index];
data[index * 4] = value;
data[index * 4 + 1] = T();
data[index * 4 + 2] = T();
data[index * 4 + 3] = value;
}
}
template <>
void ExpandFromStokesI(bool *data, size_t n) {
for (size_t i = 0; i != n; ++i) {
const size_t index = n - i - 1;
const bool value = data[index];
data[index * 4] = value;
data[index * 4 + 1] = value;
data[index * 4 + 2] = value;
data[index * 4 + 3] = value;
}
}
template <typename T>
inline T *TransformToStokesI(const T *input, char *buffer, size_t n) {
for (size_t i = 0; i != n; ++i) {
// Placement new is used, because the lifetime of type T needs
// to be started.
new (&buffer[i * sizeof(T)]) T((input[i * 4] + input[i * 4 + 3]) * T(0.5));
if (input[i * 4 + 1] != T(0.0) || input[i * 4 + 2] != T(0.0))
throw std::runtime_error(
"Stokes-I stman cannot store data for which the 2nd and 3rd "
"correlation are non-zero");
// While we could also check whether pp == qq, this is a bit more
// complicated because of rounding inaccuracies. The above check should
// catch the most crucial misuse of the stman, so a pp == qq check is not
// performed.
}
return reinterpret_cast<T *>(buffer);
}
template <>
inline bool *TransformToStokesI(const bool *input, char *buffer, size_t n) {
for (size_t i = 0; i != n; ++i) {
const bool a = input[i * 4];
const bool b = input[i * 4 + 1];
const bool c = input[i * 4 + 2];
const bool d = input[i * 4 + 3];
if (a != b || a != c || a != d)
throw std::runtime_error(
"Stokes-I stman cannot store boolean data for which not all "
"correlations are equal");
new (&buffer[i]) bool(a);
}
return reinterpret_cast<bool *>(buffer);
}
class StokesIStManColumn final : public casacore::StManColumn {
public:
explicit StokesIStManColumn(StokesIStMan &parent, BufferedColumnarFile &file,
casacore::DataType dtype)
: casacore::StManColumn(dtype), parent_(parent), file_(file) {}
casacore::Bool isWritable() const final { return true; }
void setShapeColumn(const casacore::IPosition &shape) final {
if (shape.size() != 2) {
throw std::runtime_error("StokesIStMan is used for a column with " +
std::to_string(shape.size()) +
" dimensions, but it can only be used for "
"columns with exactly 2 dimensions");
}
shape_ = shape;
updateStride();
}
casacore::IPosition shape(casacore::uInt) final { return shape_; }
casacore::IPosition shape(casacore::rownr_t) final { return shape_; }
const casacore::IPosition &shape() const { return shape_; }
void getArrayComplexV(casacore::uInt rowNr,
casacore::Array<casacore::Complex> *dataPtr) final {
getArrayGeneric(rowNr, dataPtr);
}
void getArrayfloatV(casacore::uInt rowNr,
casacore::Array<float> *dataPtr) final {
getArrayGeneric(rowNr, dataPtr);
}
void getArrayBoolV(casacore::uInt rowNr,
casacore::Array<casacore::Bool> *dataPtr) final {
getArrayGeneric(rowNr, dataPtr);
}
void putArrayComplexV(
casacore::uInt rowNr,
const casacore::Array<casacore::Complex> *dataPtr) final {
putArrayGeneric(rowNr, dataPtr);
}
void putArrayDComplexV(
casacore::uInt rowNr,
const casacore::Array<casacore::DComplex> *dataPtr) final {
putArrayGeneric(rowNr, dataPtr);
}
void putArraydoubleV(casacore::uInt rowNr,
const casacore::Array<double> *dataPtr) final {
putArrayGeneric(rowNr, dataPtr);
}
void putArrayfloatV(casacore::uInt rowNr,
const casacore::Array<float> *dataPtr) final {
putArrayGeneric(rowNr, dataPtr);
}
void putArrayBoolV(casacore::uInt rowNr,
const casacore::Array<casacore::Bool> *dataPtr) final {
putArrayGeneric(rowNr, dataPtr);
}
void setOffset(uint64_t column_offset) { column_offset_ = column_offset; }
uint64_t getStoredSizeInBytes() const {
if (dtype() == casacore::TpBool) {
return (shape_[1] + 7) / 8;
} else {
const uint64_t type_size = SizeOfType(dtype());
return shape_[1] * type_size;
}
}
private:
StokesIStManColumn(const StokesIStManColumn &source) = delete;
void operator=(const StokesIStManColumn &source) = delete;
template <typename T>
void getArrayGeneric(casacore::uInt rowNr, casacore::Array<T> *dataPtr) {
bool ownership;
T *storage = dataPtr->getStorage(ownership);
const size_t n_values = shape_[1];
file_.Read(rowNr, column_offset_, storage, n_values);
ExpandFromStokesI(storage, n_values);
dataPtr->putStorage(storage, ownership);
}
template <typename T>
void putArrayGeneric(casacore::uInt rowNr,
const casacore::Array<T> *dataPtr) {
bool ownership;
const T *storage = dataPtr->getStorage(ownership);
const size_t n_values = shape_[1];
buffer_.resize(n_values * sizeof(T));
T *buffer = TransformToStokesI(storage, buffer_.data(), n_values);
file_.Write(rowNr, column_offset_, buffer, n_values);
dataPtr->freeStorage(storage, ownership);
}
void updateStride();
StokesIStMan &parent_;
BufferedColumnarFile &file_;
IPosition shape_;
uint64_t column_offset_;
std::vector<char> buffer_;
};
} // namespace casacore
#include "StokesIStMan.h"
namespace casacore {
inline void StokesIStManColumn::updateStride() {
parent_.CalculateAndUpdateStride();
}
} // namespace casacore
#endif
BufferedColumnarFile.h
StokesIStMan.h
casacore::Array
Definition Array.h:155
casacore::Array::freeStorage
void freeStorage(const T *&storage, bool deleteIt) const
If deleteIt is set, delete "storage".
casacore::Array::putStorage
void putStorage(T *&storage, bool deleteAndCopy)
putStorage() is normally called after a call to getStorage() (cf).
casacore::Array::getStorage
T * getStorage(bool &deleteIt)
Generally use of this should be shunned, except to use a FORTRAN routine or something similar.
casacore::IPosition
Definition IPosition.h:117
casacore::StManColumnBase::dtype
DataType dtype() const
Definition StManColumnBase.h:90
casacore::StManColumn
Definition StManColumn.h:74
casacore::StManColumn::StManColumn
StManColumn(int dataType)
Default constructor.
Definition StManColumn.h:78
casacore::StokesIStManColumn::putArrayfloatV
void putArrayfloatV(casacore::uInt rowNr, const casacore::Array< float > *dataPtr) final
Definition StokesIStManColumn.h:165
casacore::StokesIStManColumn::putArrayDComplexV
void putArrayDComplexV(casacore::uInt rowNr, const casacore::Array< casacore::DComplex > *dataPtr) final
Definition StokesIStManColumn.h:156
casacore::StokesIStManColumn::file_
BufferedColumnarFile & file_
Definition StokesIStManColumn.h:212
casacore::StokesIStManColumn::getArrayGeneric
void getArrayGeneric(casacore::uInt rowNr, casacore::Array< T > *dataPtr)
Definition StokesIStManColumn.h:189
casacore::StokesIStManColumn::getArrayfloatV
void getArrayfloatV(casacore::uInt rowNr, casacore::Array< float > *dataPtr) final
Definition StokesIStManColumn.h:136
casacore::StokesIStManColumn::getArrayComplexV
void getArrayComplexV(casacore::uInt rowNr, casacore::Array< casacore::Complex > *dataPtr) final
Read the values for a particular row.
Definition StokesIStManColumn.h:131
casacore::StokesIStManColumn::column_offset_
uint64_t column_offset_
Definition StokesIStManColumn.h:214
casacore::StokesIStManColumn::setOffset
void setOffset(uint64_t column_offset)
Definition StokesIStManColumn.h:174
casacore::StokesIStManColumn::getStoredSizeInBytes
uint64_t getStoredSizeInBytes() const
Definition StokesIStManColumn.h:175
casacore::StokesIStManColumn::shape
const casacore::IPosition & shape() const
Definition StokesIStManColumn.h:124
casacore::StokesIStManColumn::buffer_
std::vector< char > buffer_
Definition StokesIStManColumn.h:215
casacore::StokesIStManColumn::updateStride
void updateStride()
Definition StokesIStManColumn.h:223
casacore::StokesIStManColumn::putArrayGeneric
void putArrayGeneric(casacore::uInt rowNr, const casacore::Array< T > *dataPtr)
Definition StokesIStManColumn.h:199
casacore::StokesIStManColumn::shape_
IPosition shape_
Definition StokesIStManColumn.h:213
casacore::StokesIStManColumn::StokesIStManColumn
StokesIStManColumn(StokesIStMan &parent, BufferedColumnarFile &file, casacore::DataType dtype)
Constructor, to be overloaded by subclass.
Definition StokesIStManColumn.h:98
casacore::StokesIStManColumn::getArrayBoolV
void getArrayBoolV(casacore::uInt rowNr, casacore::Array< casacore::Bool > *dataPtr) final
Get the array value in the given row.
Definition StokesIStManColumn.h:141
casacore::StokesIStManColumn::shape
casacore::IPosition shape(casacore::rownr_t) final
Get the shape of the item in the given row.
Definition StokesIStManColumn.h:123
casacore::StokesIStManColumn::putArraydoubleV
void putArraydoubleV(casacore::uInt rowNr, const casacore::Array< double > *dataPtr) final
Definition StokesIStManColumn.h:161
casacore::StokesIStManColumn::parent_
StokesIStMan & parent_
Definition StokesIStManColumn.h:211
casacore::StokesIStManColumn::putArrayBoolV
void putArrayBoolV(casacore::uInt rowNr, const casacore::Array< casacore::Bool > *dataPtr) final
Put the array value into the given row.
Definition StokesIStManColumn.h:169
casacore::StokesIStManColumn::StokesIStManColumn
StokesIStManColumn(const StokesIStManColumn &source)=delete
casacore::StokesIStManColumn::isWritable
casacore::Bool isWritable() const final
Whether this column is writable.
Definition StokesIStManColumn.h:106
casacore::StokesIStManColumn::operator=
void operator=(const StokesIStManColumn &source)=delete
casacore::StokesIStManColumn::putArrayComplexV
void putArrayComplexV(casacore::uInt rowNr, const casacore::Array< casacore::Complex > *dataPtr) final
Write values into a particular row.
Definition StokesIStManColumn.h:151
casacore::StokesIStManColumn::setShapeColumn
void setShapeColumn(const casacore::IPosition &shape) final
Set the dimensions of values in this column.
Definition StokesIStManColumn.h:109
casacore::StokesIStManColumn::shape
casacore::IPosition shape(casacore::uInt) final
Get the dimensions of the values in a particular row.
Definition StokesIStManColumn.h:122
casacore::StokesIStMan
The Stokes I storage manager behaves like a full set of (4) polarizations but only stores the Stokes ...
Definition StokesIStMan.h:26
casacore::casacore::uInt
unsigned int uInt
Definition LatticeStatistics.h:50
casacore::casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition LatticeStatistics.h:41
casacore::casacore::rownr_t
uInt64 rownr_t
Define the type of a row number in a table.
Definition LatticeStatistics.h:45
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::TransformToStokesI
T * TransformToStokesI(const T *input, char *buffer, size_t n)
Calculates for every set of 4 input values the Stokes-I values by doing out = 0.5 * (in_pp + in_qq),...
Definition StokesIStManColumn.h:54
casacore::value
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:368
casacore::BufferedColumnarFile
VarBufferedColumnarFile< 100 *1024 > BufferedColumnarFile
Definition BufferedColumnarFile.h:340
casacore::ExpandFromStokesI
void ExpandFromStokesI(T *data, size_t n)
Expands n values from single Stokes I values to have 4 values, in place.
Definition StokesIStManColumn.h:23