1#ifndef CASACORE_BUFFERED_COLUMNAR_FILE_H_
2#define CASACORE_BUFFERED_COLUMNAR_FILE_H_
32template <u
int64_t BufferSize = 100 * 1024>
54 rhs.active_block_ = 0;
55 rhs.rows_per_block_ = 0;
62 const size_t n_rows_to_write =
109 uint64_t header_size,
121 size_t header_size) {
134 void Read(uint64_t row, uint64_t column_offset,
float* data, uint64_t n) {
141 void Read(uint64_t row, uint64_t column_offset,
double* data, uint64_t n) {
148 void Read(uint64_t row, uint64_t column_offset, int32_t* data, uint64_t n) {
155 void Read(uint64_t row, uint64_t column_offset, std::complex<float>* data,
164 void Read(uint64_t row, uint64_t column_offset,
bool* data, uint64_t n) {
165 const size_t byte_size = (n + 7) / 8;
166 assert(column_offset + byte_size <=
Stride());
168 if (row >=
NRows()) {
169 std::fill_n(data, n,
false);
180 void Write(uint64_t row, uint64_t column_offset,
const float* data,
188 void Write(uint64_t row, uint64_t column_offset,
const double* data,
196 void Write(uint64_t row, uint64_t column_offset,
const int32_t* data,
204 void Write(uint64_t row, uint64_t column_offset,
205 const std::complex<float>* data, uint64_t n) {
212 void Write(uint64_t row, uint64_t column_offset,
213 const std::complex<double>* data, uint64_t n) {
221 void Write(uint64_t row, uint64_t column_offset,
const bool* data,
223 const size_t byte_size = (n + 7) / 8;
224 assert(column_offset + byte_size <=
Stride());
241 new_stride == 0 ? 0 : std::max<size_t>(1, BufferSize / new_stride);
253 :
std::
max<size_t>(1, BufferSize / stride)),
275 const size_t n_rows_to_read =
289 template <
typename ValueType>
292 assert(column_offset + n *
sizeof(ValueType) <=
Stride());
293 if (row >=
NRows()) {
294 std::fill_n(data, n, ValueType());
298 const unsigned char* position =
300 std::copy_n(position, n *
sizeof(ValueType),
301 reinterpret_cast<unsigned char*
>(data));
305 template <
typename ValueType>
307 const ValueType* data, uint64_t n) {
308 assert(column_offset + n *
sizeof(ValueType) <=
Stride());
311 unsigned char* position =
313 std::copy_n(
reinterpret_cast<const unsigned char*
>(data),
314 n *
sizeof(ValueType), position);
321 const size_t n_rows_to_write =
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.
static VarBufferedColumnarFile CreateNew(const std::string &filename, uint64_t header_size, uint64_t stride)
Create a new file on disk.
static VarBufferedColumnarFile OpenExisting(const std::string &filename, size_t header_size)
Open an existing file from disk.
void Write(uint64_t row, uint64_t column_offset, const std::complex< double > *data, uint64_t n)
Write an array of complex doubles.
void Write(uint64_t row, uint64_t column_offset, const bool *data, uint64_t n)
Write an array of bools.
void ReadImplementation(uint64_t row, uint64_t column_offset, ValueType *data, uint64_t n)
void ActivateBlock(uint64_t row)
void Write(uint64_t row, uint64_t column_offset, const double *data, uint64_t n)
Write an array of doubles.
void Read(uint64_t row, uint64_t column_offset, int32_t *data, uint64_t n)
Read array of int32_t.
void Read(uint64_t row, uint64_t column_offset, std::complex< float > *data, uint64_t n)
Read array of complex floats.
void SetStride(uint64_t new_stride)
Set the number of bytes per row for this file.
VarBufferedColumnarFile() noexcept=default
VarBufferedColumnarFile(const std::string &filename, size_t header_size)
Open an existing columnar file.
void Read(uint64_t row, uint64_t column_offset, double *data, uint64_t n)
Read array of doubles.
void WriteImplementation(uint64_t row, uint64_t column_offset, const ValueType *data, uint64_t n)
VarBufferedColumnarFile(const std::string &filename, uint64_t header_size, uint64_t stride)
Create or overwrite a new columnar file on disk.
void Write(uint64_t row, uint64_t column_offset, const int32_t *data, uint64_t n)
Write an array of int32_t.
std::vector< unsigned char > block_buffer_
VarBufferedColumnarFile & operator=(VarBufferedColumnarFile &&rhs)
void Write(uint64_t row, uint64_t column_offset, const std::complex< float > *data, uint64_t n)
Write an array of complex floats.
void Read(uint64_t row, uint64_t column_offset, bool *data, uint64_t n)
Read an array of bools.
uint64_t NRows() const
Total number of rows stored in this file.
void Read(uint64_t row, uint64_t column_offset, float *data, uint64_t n)
Read one cell containing an array of floats.
void Write(uint64_t row, uint64_t column_offset, const float *data, uint64_t n)
Write one cell containing an array of floats.
~VarBufferedColumnarFile() noexcept
std::vector< unsigned char > packed_buffer_
This buffer is used temporarily for (un)packing booleans.
uint64_t Stride() const
Total number of bytes in one row.
void Close()
Close the file.
this file contains all the compiler specific defines
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
Define real & complex conjugation for non-complex types and put comparisons into std namespace.