DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq
sourcecode
tpglibs
include
tpglibs
testapp
reader
BinarySignalReader.hxx
Go to the documentation of this file.
1
9
#ifndef TPGLIBS_TESTAPP_BINARYSIGNALREADER_HXX_
10
#define TPGLIBS_TESTAPP_BINARYSIGNALREADER_HXX_
11
12
#include "
BinarySignalReader.hpp
"
13
#include <iostream>
14
15
namespace
tpglibs
{
16
namespace
testapp {
17
18
template
<
typename
T>
19
BinarySignalReader<T>::BinarySignalReader
(
const
std::string& filepath)
20
: m_file(filepath,
std
::ios::binary), m_eof_reached(false) {
21
if
(!
m_file
.is_open()) {
22
throw std::runtime_error(
"Failed to open file: "
+ filepath);
23
}
24
}
25
26
template
<
typename
T>
27
std::vector<T>
BinarySignalReader<T>::next
(
size_t
n) {
28
if
(m_eof_reached || n == 0) {
29
return
std::vector<T>();
30
}
31
32
std::vector<T> result;
33
result.reserve(n);
34
35
for
(
size_t
i = 0; i < n; ++i) {
36
T value;
37
m_file.read(
reinterpret_cast<
char
*
>
(&value),
sizeof
(T));
38
39
if
(m_file.gcount() !=
sizeof
(T)) {
40
m_eof_reached =
true
;
41
break
;
42
}
43
44
result.push_back(value);
45
}
46
47
return
result;
48
}
49
50
template
<
typename
T>
51
bool
BinarySignalReader<T>::eof
() {
52
// Check if we're at the end of the file by comparing position with file size
53
std::streampos current_pos = m_file.tellg();
54
m_file.seekg(0, std::ios::end);
55
std::streampos end_pos = m_file.tellg();
56
m_file.seekg(current_pos);
57
58
if
(current_pos >= end_pos) {
59
m_eof_reached =
true
;
60
return
true
;
61
}
62
63
m_eof_reached =
false
;
64
return
false
;
65
}
66
67
template
<
typename
T>
68
std::streampos
BinarySignalReader<T>::tellg
() {
69
return
m_file.tellg();
70
}
71
72
template
<
typename
T>
73
void
BinarySignalReader<T>::seekg
(std::streampos pos) {
74
m_file.seekg(pos);
75
eof();
// Update m_eof_reached based on actual position
76
}
77
78
}
// namespace testapp
79
}
// namespace tpglibs
80
81
#endif
// TPGLIBS_TESTAPP_BINARYSIGNALREADER_HXX_
BinarySignalReader.hpp
tpglibs::testapp::BinarySignalReader::tellg
std::streampos tellg()
Get current file position.
Definition
BinarySignalReader.hxx:68
tpglibs::testapp::BinarySignalReader::next
std::vector< T > next(size_t n)
Read next chunk of data.
Definition
BinarySignalReader.hxx:27
tpglibs::testapp::BinarySignalReader::m_file
std::ifstream m_file
Definition
BinarySignalReader.hpp:68
tpglibs::testapp::BinarySignalReader::seekg
void seekg(std::streampos pos)
Seek to specific position.
Definition
BinarySignalReader.hxx:73
tpglibs::testapp::BinarySignalReader::eof
bool eof()
Check if we've reached end of file.
Definition
BinarySignalReader.hxx:51
tpglibs::testapp::BinarySignalReader::BinarySignalReader
BinarySignalReader(const std::string &filepath)
Constructor - opens the file for reading.
Definition
BinarySignalReader.hxx:19
std
Definition
SchemaUtils.hpp:118
tpglibs
Definition
AbstractFactory.hpp:20
Generated on Thu Dec 25 2025 for DUNE-DAQ by
1.12.0