DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
tpglibs
include
tpglibs
testapp
reader
BinarySignalReader.hxx
Go to the documentation of this file.
1
8
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)
21
,
m_eof_reached
(false)
22
{
23
if
(!
m_file
.is_open()) {
24
throw std::runtime_error(
"Failed to open file: "
+ filepath);
25
}
26
}
27
28
template
<
typename
T>
29
std::vector<T>
30
BinarySignalReader<T>::next
(
size_t
n)
31
{
32
if
(
m_eof_reached
|| n == 0) {
33
return
std::vector<T>();
34
}
35
36
std::vector<T> result;
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
}
53
54
template
<
typename
T>
55
bool
56
BinarySignalReader<T>::eof
()
57
{
58
// Check if we're at the end of the file by comparing position with file size
59
std::streampos current_pos =
m_file
.tellg();
60
m_file
.seekg(0, std::ios::end);
61
std::streampos end_pos =
m_file
.tellg();
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
}
72
73
template
<
typename
T>
74
std::streampos
75
BinarySignalReader<T>::tellg
()
76
{
77
return
m_file
.tellg();
78
}
79
80
template
<
typename
T>
81
void
82
BinarySignalReader<T>::seekg
(std::streampos pos)
83
{
84
m_file
.seekg(pos);
85
eof
();
// Update m_eof_reached based on actual position
86
}
87
88
}
// namespace testapp
89
}
// namespace tpglibs
90
91
#endif
// TPGLIBS_TESTAPP_BINARYSIGNALREADER_HXX_
BinarySignalReader.hpp
tpglibs::testapp::BinarySignalReader::tellg
std::streampos tellg()
Get current file position.
Definition
BinarySignalReader.hxx:75
tpglibs::testapp::BinarySignalReader::next
std::vector< T > next(size_t n)
Read next chunk of data.
Definition
BinarySignalReader.hxx:30
tpglibs::testapp::BinarySignalReader::m_eof_reached
bool m_eof_reached
Definition
BinarySignalReader.hpp:70
tpglibs::testapp::BinarySignalReader::m_file
std::ifstream m_file
Definition
BinarySignalReader.hpp:69
tpglibs::testapp::BinarySignalReader::seekg
void seekg(std::streampos pos)
Seek to specific position.
Definition
BinarySignalReader.hxx:82
tpglibs::testapp::BinarySignalReader::eof
bool eof()
Check if we've reached end of file.
Definition
BinarySignalReader.hxx:56
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::testapp
Definition
BinarySignalReader.hpp:18
tpglibs
Definition
AbstractFactory.hpp:20
Generated on
for DUNE-DAQ by
1.18.0