DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
tpglibs::testapp::BinarySignalReader< T > Class Template Reference

Simple binary file reader for integer types. More...

#include <BinarySignalReader.hpp>

Public Member Functions

 BinarySignalReader (const std::string &filepath)
 Constructor - opens the file for reading.
 ~BinarySignalReader ()=default
 Destructor - closes the file.
std::vector< T > next (size_t n)
 Read next chunk of data.
bool eof ()
 Check if we've reached end of file.
std::streampos tellg ()
 Get current file position.
void seekg (std::streampos pos)
 Seek to specific position.

Private Attributes

std::ifstream m_file
bool m_eof_reached

Detailed Description

template<typename T>
class tpglibs::testapp::BinarySignalReader< T >

Simple binary file reader for integer types.

Reads binary data from a file and returns it as the requested integer type. Used for reading int16_t test data.

Definition at line 27 of file BinarySignalReader.hpp.

Constructor & Destructor Documentation

◆ BinarySignalReader()

template<typename T>
tpglibs::testapp::BinarySignalReader< T >::BinarySignalReader ( const std::string & filepath)
explicit

Constructor - opens the file for reading.

Parameters
filepathPath to the binary file
Exceptions
std::runtime_errorif file cannot be opened

Definition at line 19 of file BinarySignalReader.hxx.

21 , m_eof_reached(false)
22{
23 if (!m_file.is_open()) {
24 throw std::runtime_error("Failed to open file: " + filepath);
25 }
26}
Simple binary file reader for integer types.

◆ ~BinarySignalReader()

template<typename T>
tpglibs::testapp::BinarySignalReader< T >::~BinarySignalReader ( )
default

Destructor - closes the file.

Member Function Documentation

◆ eof()

template<typename T>
bool tpglibs::testapp::BinarySignalReader< T >::eof ( )

Check if we've reached end of file.

Returns
true if EOF reached

Definition at line 56 of file BinarySignalReader.hxx.

57{
58 // Check if we're at the end of the file by comparing position with file size
60 m_file.seekg(0, std::ios::end);
62 m_file.seekg(current_pos);
63
64 if (current_pos >= end_pos) {
65 m_eof_reached = true;
66 return true;
67 }
68
69 m_eof_reached = false;
70 return false;
71}
std::streampos tellg()
Get current file position.

◆ next()

template<typename T>
std::vector< T > tpglibs::testapp::BinarySignalReader< T >::next ( size_t n)

Read next chunk of data.

Parameters
nNumber of elements to read (actual bytes = n * sizeof(T))
Returns
Vector containing the read data
Exceptions
std::runtime_errorif read fails

Definition at line 30 of file BinarySignalReader.hxx.

31{
32 if (m_eof_reached || n == 0) {
33 return std::vector<T>();
34 }
35
37 result.reserve(n);
38
39 for (size_t i = 0; i < n; ++i) {
40 T value;
41 m_file.read(reinterpret_cast<char*>(&value), sizeof(T));
42
43 if (m_file.gcount() != sizeof(T)) {
44 m_eof_reached = true;
45 break;
46 }
47
48 result.push_back(value);
49 }
50
51 return result;
52}

◆ seekg()

template<typename T>
void tpglibs::testapp::BinarySignalReader< T >::seekg ( std::streampos pos)

Seek to specific position.

Parameters
posPosition to seek to

Definition at line 82 of file BinarySignalReader.hxx.

83{
84 m_file.seekg(pos);
85 eof(); // Update m_eof_reached based on actual position
86}
bool eof()
Check if we've reached end of file.

◆ tellg()

template<typename T>
std::streampos tpglibs::testapp::BinarySignalReader< T >::tellg ( )

Get current file position.

Returns
Current position in file

Definition at line 75 of file BinarySignalReader.hxx.

76{
77 return m_file.tellg();
78}

Member Data Documentation

◆ m_eof_reached

template<typename T>
bool tpglibs::testapp::BinarySignalReader< T >::m_eof_reached
private

Definition at line 70 of file BinarySignalReader.hpp.

◆ m_file

template<typename T>
std::ifstream tpglibs::testapp::BinarySignalReader< T >::m_file
private

Definition at line 69 of file BinarySignalReader.hpp.


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