1#ifndef CASACORE_COLUMNAR_FILE_H_
2#define CASACORE_COLUMNAR_FILE_H_
51 uint64_t header_size, uint64_t stride) {
60 void Read(uint64_t row, uint64_t column_offset, std::complex<float>* data,
64 void Read(uint64_t row, uint64_t column_offset,
float* data, uint64_t n) {
67 void Read(uint64_t row, uint64_t column_offset,
double* data, uint64_t n) {
70 void Read(uint64_t row, uint64_t column_offset, int32_t* data, uint64_t n) {
73 void Read(uint64_t row, uint64_t column_offset,
bool* data, uint64_t n) {
74 const size_t byte_size = (n + 7) / 8;
75 assert(column_offset + byte_size <=
Stride());
77 std::fill_n(data, n,
false);
84 void Write(uint64_t row, uint64_t column_offset,
85 const std::complex<float>* data, uint64_t n) {
88 void Write(uint64_t row, uint64_t column_offset,
89 const std::complex<double>* data, uint64_t n) {
92 void Write(uint64_t row, uint64_t column_offset,
const float* data,
96 void Write(uint64_t row, uint64_t column_offset,
const double* data,
100 void Write(uint64_t row, uint64_t column_offset,
const int32_t* data,
104 void Write(uint64_t row, uint64_t column_offset,
const bool* data,
106 const size_t byte_size = (n + 7) / 8;
107 assert(column_offset + byte_size <=
Stride());
136 template <
typename ValueType>
139 assert(column_offset + n *
sizeof(ValueType) <=
Stride());
140 if (row >=
NRows()) {
141 std::fill_n(data, n, ValueType());
144 ReadData(
reinterpret_cast<unsigned char*
>(data), n *
sizeof(ValueType));
148 template <
typename ValueType>
150 const ValueType* data, uint64_t n) {
151 assert(column_offset + n *
sizeof(ValueType) <=
Stride());
153 WriteData(
reinterpret_cast<const unsigned char*
>(data),
154 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.
Class that provides binary table I/O.
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.
this file contains all the compiler specific defines
Define real & complex conjugation for non-complex types and put comparisons into std namespace.