11#ifndef DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_UTILS_BUFFEREDFILEWRITER_HPP_
12#define DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_UTILS_BUFFEREDFILEWRITER_HPP_
19#include <boost/align/aligned_allocator.hpp>
20#include <boost/iostreams/device/file_descriptor.hpp>
21#include <boost/iostreams/filter/lzma.hpp>
22#include <boost/iostreams/filter/zlib.hpp>
23#include <boost/iostreams/filter/zstd.hpp>
24#include <boost/iostreams/filtering_stream.hpp>
25#include <boost/iostreams/stream.hpp>
26#include <boost/iostreams/stream_buffer.hpp>
38namespace datahandlinglibs {
46template<
size_t Alignment = 4096>
49 using io_sink_t = boost::iostreams::file_descriptor_sink;
52 boost::iostreams::filtering_stream<boost::iostreams::output, char, std::char_traits<char>,
aligned_allocator_t>;
68 open(
filename, buffer_size, compression_algorithm, use_o_direct);
103 std::string compression_algorithm =
"None",
104 bool use_o_direct =
true)
114 auto oflag = O_CREAT | O_WRONLY;
116 oflag = oflag | O_DIRECT;
126 TLOG_DEBUG(TLVL_WORK_STEPS) <<
"Using zstd compression" << std::endl;
127 m_output_stream.push(boost::iostreams::zstd_compressor(boost::iostreams::zstd::best_speed));
129 TLOG_DEBUG(TLVL_WORK_STEPS) <<
"Using lzma compression" << std::endl;
130 m_output_stream.push(boost::iostreams::lzma_compressor(boost::iostreams::lzma::best_speed));
132 TLOG_DEBUG(TLVL_WORK_STEPS) <<
"Using zlib compression" << std::endl;
133 m_output_stream.push(boost::iostreams::zlib_compressor(boost::iostreams::zlib::best_speed));
135 TLOG_DEBUG(TLVL_WORK_STEPS) <<
"Running without compression" << std::endl;
171 fcntl(
m_fd, F_SETFL, O_CREAT | O_WRONLY);
184 fcntl(
m_fd, F_SETFL, O_CREAT | O_WRONLY);
188 auto oflag = O_CREAT | O_WRONLY;
190 oflag = oflag | O_DIRECT;
192 fcntl(
m_fd, F_SETFL, oflag);
BufferedFileWriter(const BufferedFileWriter &)=delete
BufferedFileWriter is not copy-constructible.
boost::iostreams::filtering_stream< boost::iostreams::output, char, std::char_traits< char >, aligned_allocator_t > filtering_ostream_t
boost::alignment::aligned_allocator< io_sink_t::char_type, Alignment > aligned_allocator_t
void open(std::string filename, size_t buffer_size, std::string compression_algorithm="None", bool use_o_direct=true)
BufferedFileWriter & operator=(BufferedFileWriter &&)=delete
BufferedFileWriter is not move-assignable.
std::string m_compression_algorithm
bool write(const char *memory, const size_t size)
boost::iostreams::file_descriptor_sink io_sink_t
BufferedFileWriter(std::string filename, size_t buffer_size, std::string compression_algorithm="None", bool use_o_direct=true)
BufferedFileWriter(BufferedFileWriter &&)=delete
BufferedFileWriter is not move-constructible.
BufferedFileWriter & operator=(const BufferedFileWriter &)=delete
BufferedFileWriter is not copy-assginable.
filtering_ostream_t m_output_stream
#define TLOG_DEBUG(lvl,...)
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size
SourceID[" << sourceid << "] Command daqdataformats::SourceID Readout Initialization std::string initerror BufferedReaderWriterConfigurationError