DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment > Class Template Reference

#include <BufferedFileReader.hpp>

Public Member Functions

 BufferedFileReader (std::string filename, size_t buffer_size, std::string compression_algorithm="None")
 
 BufferedFileReader ()
 
 BufferedFileReader (const BufferedFileReader &)=delete
 BufferedFileReader is not copy-constructible.
 
BufferedFileReaderoperator= (const BufferedFileReader &)=delete
 BufferedFileReader is not copy-assginable.
 
 BufferedFileReader (BufferedFileReader &&)=delete
 BufferedFileReader is not move-constructible.
 
BufferedFileReaderoperator= (BufferedFileReader &&)=delete
 BufferedFileReader is not move-assignable.
 
void open (std::string filename, size_t buffer_size, std::string compression_algorithm="None")
 
bool is_open () const
 
bool read (ReadoutType &element)
 
void close ()
 

Private Types

using io_source_t = boost::iostreams::file_descriptor_source
 
using aligned_allocator_t = boost::alignment::aligned_allocator<io_source_t::char_type, Alignment>
 
using filtering_istream_t
 

Private Attributes

std::string m_filename
 
size_t m_buffer_size
 
std::string m_compression_algorithm
 
filtering_istream_t m_input_stream
 
bool m_is_open = false
 

Detailed Description

template<class ReadoutType, size_t Alignment = 4096>
class dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >

Class to read data of a specified type in a buffered manner.

Template Parameters
ReadoutTypeType of the data that is read from the file.
AlignmentThe alignment size of internal buffers.

Definition at line 43 of file BufferedFileReader.hpp.

Member Typedef Documentation

◆ aligned_allocator_t

template<class ReadoutType , size_t Alignment = 4096>
using dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::aligned_allocator_t = boost::alignment::aligned_allocator<io_source_t::char_type, Alignment>
private

Definition at line 46 of file BufferedFileReader.hpp.

◆ filtering_istream_t

template<class ReadoutType , size_t Alignment = 4096>
using dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::filtering_istream_t
private
Initial value:
boost::iostreams::filtering_stream<boost::iostreams::input, char, std::char_traits<char>, aligned_allocator_t>
boost::alignment::aligned_allocator< io_source_t::char_type, Alignment > aligned_allocator_t

Definition at line 47 of file BufferedFileReader.hpp.

◆ io_source_t

template<class ReadoutType , size_t Alignment = 4096>
using dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::io_source_t = boost::iostreams::file_descriptor_source
private

Definition at line 45 of file BufferedFileReader.hpp.

Constructor & Destructor Documentation

◆ BufferedFileReader() [1/4]

template<class ReadoutType , size_t Alignment = 4096>
dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::BufferedFileReader ( std::string filename,
size_t buffer_size,
std::string compression_algorithm = "None" )
inline

Constructor to construct and initalize an instance. The file will be open after initialization.

Parameters
filenameThe file to be used.
buffer_sizeThe size of the buffer to be used.
compression_algorithmThe compression algorithm to use. Can be one of: None, zstd, lzma or zlib
Exceptions
CannotOpenFileIf the file can not be opened.
ConfigurationErrorIf the compression algorithm parameter is not recognized.

Definition at line 59 of file BufferedFileReader.hpp.

60 {
61 open(filename, buffer_size, compression_algorithm);
62 }
void open(std::string filename, size_t buffer_size, std::string compression_algorithm="None")

◆ BufferedFileReader() [2/4]

template<class ReadoutType , size_t Alignment = 4096>
dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::BufferedFileReader ( )
inline

Constructor to construct and instance without opening a file.

Definition at line 67 of file BufferedFileReader.hpp.

67{}

◆ BufferedFileReader() [3/4]

template<class ReadoutType , size_t Alignment = 4096>
dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::BufferedFileReader ( const BufferedFileReader< ReadoutType, Alignment > & )
delete

BufferedFileReader is not copy-constructible.

◆ BufferedFileReader() [4/4]

template<class ReadoutType , size_t Alignment = 4096>
dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::BufferedFileReader ( BufferedFileReader< ReadoutType, Alignment > && )
delete

BufferedFileReader is not move-constructible.

Member Function Documentation

◆ close()

template<class ReadoutType , size_t Alignment = 4096>
void dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::close ( )
inline

Close the reader.

Definition at line 138 of file BufferedFileReader.hpp.

◆ is_open()

template<class ReadoutType , size_t Alignment = 4096>
bool dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::is_open ( ) const
inline

Check if the file is open.

Returns
true if the file is open, false otherwise.
Exceptions
CannotOpenFileIf the file can not be opened.
ConfigurationErrorIf the compression algorithm parameter is not recognized.

Definition at line 120 of file BufferedFileReader.hpp.

120{ return m_is_open; }

◆ open()

template<class ReadoutType , size_t Alignment = 4096>
void dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::open ( std::string filename,
size_t buffer_size,
std::string compression_algorithm = "None" )
inline

Open a file.

Parameters
filenameThe file to be used.
buffer_sizeThe size of the buffer to be used.
compression_algorithmThe compression algorithm to use. Can be one of: None, zstd, lzma or zlib
Exceptions
CannotOpenFileIf the file can not be opened.
ConfigurationErrorIf the compression algorithm parameter is not recognized.

Definition at line 82 of file BufferedFileReader.hpp.

83 {
85 m_buffer_size = buffer_size;
86 m_compression_algorithm = compression_algorithm;
87
88 int fd = ::open(m_filename.c_str(), O_RDONLY);
89 if (fd == -1) {
90 throw BufferedReaderWriterCannotOpenFile(ERS_HERE, m_filename);
91 }
92
93 io_source_t io_source(fd, boost::iostreams::file_descriptor_flags::close_handle);
94 if (m_compression_algorithm == "zstd") {
95 TLOG_DEBUG(TLVL_WORK_STEPS) << "Using zstd compression" << std::endl;
96 m_input_stream.push(boost::iostreams::zstd_decompressor());
97 } else if (m_compression_algorithm == "lzma") {
98 TLOG_DEBUG(TLVL_WORK_STEPS) << "Using lzma compression" << std::endl;
99 m_input_stream.push(boost::iostreams::lzma_decompressor());
100 } else if (m_compression_algorithm == "zlib") {
101 TLOG_DEBUG(TLVL_WORK_STEPS) << "Using zlib compression" << std::endl;
102 m_input_stream.push(boost::iostreams::zlib_decompressor());
103 } else if (m_compression_algorithm == "None") {
104 TLOG_DEBUG(TLVL_WORK_STEPS) << "Running without compression" << std::endl;
105 } else {
107 "Non-recognized compression algorithm: " + m_compression_algorithm);
108 }
109
110 m_input_stream.push(io_source, m_buffer_size);
111 m_is_open = true;
112 }
#define ERS_HERE
boost::iostreams::file_descriptor_source io_source_t
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
SourceID[" << sourceid << "] Command daqdataformats::SourceID Readout Initialization std::string initerror BufferedReaderWriterConfigurationError

◆ operator=() [1/2]

template<class ReadoutType , size_t Alignment = 4096>
BufferedFileReader & dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::operator= ( BufferedFileReader< ReadoutType, Alignment > && )
delete

BufferedFileReader is not move-assignable.

◆ operator=() [2/2]

template<class ReadoutType , size_t Alignment = 4096>
BufferedFileReader & dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::operator= ( const BufferedFileReader< ReadoutType, Alignment > & )
delete

BufferedFileReader is not copy-assginable.

◆ read()

template<class ReadoutType , size_t Alignment = 4096>
bool dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::read ( ReadoutType & element)
inline

Read one element from the file.

Parameters
elementReference to the element that will contain the value that was read.
Returns
true if the read was successful, false if the reader is not open or the read was not successful.

Definition at line 127 of file BufferedFileReader.hpp.

128 {
129 if (!m_is_open)
130 return false;
131 m_input_stream.read(reinterpret_cast<char*>(&element), sizeof(element)); // NOLINT
132 return (m_input_stream.gcount() == sizeof(element));
133 }

Member Data Documentation

◆ m_buffer_size

template<class ReadoutType , size_t Alignment = 4096>
size_t dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::m_buffer_size
private

Definition at line 147 of file BufferedFileReader.hpp.

◆ m_compression_algorithm

template<class ReadoutType , size_t Alignment = 4096>
std::string dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::m_compression_algorithm
private

Definition at line 148 of file BufferedFileReader.hpp.

◆ m_filename

template<class ReadoutType , size_t Alignment = 4096>
std::string dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::m_filename
private

Definition at line 146 of file BufferedFileReader.hpp.

◆ m_input_stream

template<class ReadoutType , size_t Alignment = 4096>
filtering_istream_t dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::m_input_stream
private

Definition at line 151 of file BufferedFileReader.hpp.

◆ m_is_open

template<class ReadoutType , size_t Alignment = 4096>
bool dunedaq::datahandlinglibs::BufferedFileReader< ReadoutType, Alignment >::m_is_open = false
private

Definition at line 152 of file BufferedFileReader.hpp.


The documentation for this class was generated from the following file: