casacore
Loading...
Searching...
No Matches
ShapesFileWriter.h
Go to the documentation of this file.
1#ifndef CASACORE_SHAPES_FILE_WRITER_H_
2#define CASACORE_SHAPES_FILE_WRITER_H_
3
4#include <fstream>
5
6#include <casacore/casa/Arrays/IPosition.h>
7
8#include "Deflate.h"
9
10namespace casacore {
11
13 public:
14 ShapesFileWriter(const std::string& filename) : compressor_(9), file_(filename) {}
15
17 if (!buffer_.empty()) Flush();
18 }
19
20 void Write(const IPosition& position) {
21 buffer_.emplace_back(position.size());
22 if (buffer_.size() == kMaxBufferSize) Flush();
23 for (ssize_t value : position) {
24 buffer_.emplace_back(value);
25 if (buffer_.size() == kMaxBufferSize) Flush();
26 }
27 }
28
29 private:
30 void Flush() {
31 const uint32_t uncompressed_size = buffer_.size() * sizeof(uint64_t);
32 compressed_buffer_.resize(compressor_.CompressBound(uncompressed_size));
33 std::span input(reinterpret_cast<const std::byte*>(buffer_.data()), uncompressed_size);
34 const uint32_t compressed_size = compressor_.Compress(input, compressed_buffer_);
35 file_.write(reinterpret_cast<const char*>(&uncompressed_size), sizeof(uint32_t));
36 file_.write(reinterpret_cast<const char*>(&compressed_size), sizeof(uint32_t));
37 file_.write(reinterpret_cast<const char*>(compressed_buffer_.data()), compressed_size);
38 buffer_.clear();
39 }
40
41 static constexpr size_t kMaxBufferSize = 1024 * 10 * 128;
42 std::vector<uint64_t> buffer_;
43 std::vector<std::byte> compressed_buffer_;
45 std::ofstream file_;
46};
47
48} // namespace casacore
49
50#endif
size_t size() const
Definition IPosition.h:552
static constexpr size_t kMaxBufferSize
deflate::Compressor compressor_
std::vector< uint64_t > buffer_
void Write(const IPosition &position)
ShapesFileWriter(const std::string &filename)
std::vector< std::byte > compressed_buffer_
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:360