1#ifndef CASACORE_COLUMNAR_FILE_H_
2#define CASACORE_COLUMNAR_FILE_H_
59 void Read(uint64_t row, uint64_t column_offset, std::complex<float>* data, uint64_t n) {
62 void Read(uint64_t row, uint64_t column_offset,
float* data, uint64_t n) {
65 void Read(uint64_t row, uint64_t column_offset,
double* data, uint64_t n) {
68 void Read(uint64_t row, uint64_t column_offset, int32_t* data, uint64_t n) {
71 void Read(uint64_t row, uint64_t column_offset,
bool* data, uint64_t n) {
72 const size_t byte_size = (n + 7) / 8;
73 assert(column_offset + byte_size <=
Stride());
75 std::fill_n(data, n,
false);
82 void Write(uint64_t row, uint64_t column_offset,
const std::complex<float>* data, uint64_t n) {
85 void Write(uint64_t row, uint64_t column_offset,
const std::complex<double>* data, uint64_t n) {
88 void Write(uint64_t row, uint64_t column_offset,
const float* data, uint64_t n) {
91 void Write(uint64_t row, uint64_t column_offset,
const double* data, uint64_t n) {
94 void Write(uint64_t row, uint64_t column_offset,
const int32_t* data, uint64_t n) {
97 void Write(uint64_t row, uint64_t column_offset,
const bool* data, uint64_t n) {
98 const size_t byte_size = (n + 7) / 8;
99 assert(column_offset + byte_size <=
Stride());
126 template <
typename ValueType>
128 assert(column_offset + n *
sizeof(ValueType) <=
Stride());
129 if (row >=
NRows()) {
130 std::fill_n(data, n, ValueType());
133 ReadData(
reinterpret_cast<unsigned char*
>(data), n *
sizeof(ValueType));
137 template <
typename ValueType>
140 assert(column_offset + n *
sizeof(ValueType) <=
Stride());
142 WriteData(
reinterpret_cast<const unsigned char*
>(data), n *
sizeof(ValueType));
void UnpackBoolArray(bool *output, const unsigned char *packed_input, size_t n)
void PackBoolArray(unsigned char *packed_buffer, const bool *input, size_t n)
void WriteData(const unsigned char *data, uint64_t size)
void Seek(off_t pos, int seek_direction)
uint64_t DataLocation() const
Offset of the first row in the file.
void SetStride(uint64_t new_stride)
Set the number of bytes per row for this file.
void ReadHeader(unsigned char *data)
Read an optional extra header to the file.
const std::string & Filename() const
RowBasedFile & operator=(RowBasedFile &&rhs)
void WriteHeader(const unsigned char *data)
Write an optional extra header to the file.
void AddRows(uint64_t n_rows)
Adds a given number of rows to the back of the file.
uint64_t NRows() const
Total number of rows stored in this file.
void ReadData(unsigned char *data, uint64_t size)
void DeleteRow()
Deletes the last row.
uint64_t Stride() const
Total number of bytes in one row.
void SetNRows(uint64_t new_n_rows)
void Close()
Close the file.
void Write(uint64_t row, uint64_t column_offset, const bool *data, uint64_t n)
void ReadImplementation(uint64_t row, uint64_t column_offset, ValueType *data, uint64_t n)
void Read(uint64_t row, uint64_t column_offset, std::complex< float > *data, uint64_t n)
void Read(uint64_t row, uint64_t column_offset, bool *data, uint64_t n)
void Read(uint64_t row, uint64_t column_offset, int32_t *data, uint64_t n)
static SimpleColumnarFile OpenExisting(const std::string &filename, size_t header_size)
void Read(uint64_t row, uint64_t column_offset, double *data, uint64_t n)
void WriteImplementation(uint64_t row, uint64_t column_offset, const ValueType *data, uint64_t n)
SimpleColumnarFile(const std::string &filename, size_t header_size)
Open an existing columnar file.
void Write(uint64_t row, uint64_t column_offset, const std::complex< float > *data, uint64_t n)
std::vector< unsigned char > packed_buffer_
This buffer is used temporarily for (un)packing booleans.
void Write(uint64_t row, uint64_t column_offset, const std::complex< double > *data, uint64_t n)
void Write(uint64_t row, uint64_t column_offset, const float *data, uint64_t n)
SimpleColumnarFile() noexcept=default
void Read(uint64_t row, uint64_t column_offset, float *data, uint64_t n)
static SimpleColumnarFile CreateNew(const std::string &filename, uint64_t header_size, uint64_t stride)
uint64_t NRows() const
Total number of rows stored in this file.
void SetStride(uint64_t new_stride)
Set the number of bytes per row for this file.
void Write(uint64_t row, uint64_t column_offset, const int32_t *data, uint64_t n)
void Write(uint64_t row, uint64_t column_offset, const double *data, uint64_t n)
SimpleColumnarFile(const std::string &filename, uint64_t header_size, uint64_t stride)
Create or overwrite a new columnar file on disk.
~SimpleColumnarFile() noexcept=default
uint64_t Stride() const
Total number of bytes in one row.
For temporary backward namespace compatibility, use casa as alias for casacore.
void move(TYPE *target, int npixels) const
Define real & complex conjugation for non-complex types and put comparisons into std namespace.