BmnRoot
26.10.0-233-gb9bbe585
Software framework of the BM@N experiment
Toggle main menu visibility
Loading...
Searching...
No Matches
BmnFileReaderRaw.h
Go to the documentation of this file.
1
#pragma once
2
#ifndef BmnFileReaderRaw_h
3
#define BmnFileReaderRaw_h
4
5
// headers from this target
6
#include "
BmnIFileReader.h
"
7
// std:: headers
8
#include <fstream>
9
10
/*
11
* A class that allows one to read raw binary files. This class is very similar to `std::ifstream`
12
* and only implements its methods. Still, APi of `BmnIFileReader` is used so one can use this class
13
* along with other children classes based on needs
14
*/
15
class
BmnFileReaderRaw
:
public
BmnIFileReader
16
{
17
public
:
18
/*
19
* A standard constructor that sets a path to the input raw binary file
20
* @param aFilePath A path to the input raw binary file. If provided, the file will be opened in the constructor
21
* @warning If using relative paths, be very careful about currently-working directory as it might
22
* be something unexpected based on the directory that initialized an application
23
*/
24
explicit
BmnFileReaderRaw
(
const
std::filesystem::path& aFilePath);
25
26
virtual
~BmnFileReaderRaw
() =
default
;
27
BmnFileReaderRaw
(
const
BmnFileReaderRaw
&) =
delete
;
28
BmnFileReaderRaw
&
operator=
(
const
BmnFileReaderRaw
&) =
delete
;
29
BmnFileReaderRaw
(
BmnFileReaderRaw
&&) noexcept = delete;
30
BmnFileReaderRaw
& operator=(
BmnFileReaderRaw
&&) noexcept = delete;
31
32
// ========== BmnIFileReaderInterface ==========
33
34
/*
35
* A method that opens a raw-binary file for reading
36
* @param aFilePath A path to the file that should be opened
37
* @warning Be very carful with "the currently-working directory" as it may not be the same as the executable path!
38
*/
39
virtual
void
Open
(const std::filesystem::path& aFilePath) override;
40
41
/*
42
* Closes the input stream. After calling `Close`, it's safe to reopen using the same instance of this class
43
*/
44
virtual
void
Close
() noexcept override;
45
46
/*
47
* Reads the binary-file data and writes them into the provided buffer.
48
* @param dataToFill A buffer that will be filled with uncompressed data
49
* @param sizeToFill A number of bytes that will be filled in `dataToFill`
50
* @return A number of bytes that were filled in `dataToFill`. This value should almost always be the same as
51
* `sizeToFill` except when the end of the stream is reached (only if the user asked for more data than
52
* possible)
53
*/
54
virtual int64_t
Read
(
void
* dataToFill, const int64_t sizeToFill) override;
55
56
/*
57
* A method that tells us what's next to read
58
* @return A position of the next byte that should be read
59
*/
60
[[nodiscard]] virtual int64_t
Tell
() const noexcept override;
61
62
/*
63
* A method that sets a position for a next-byte read
64
* @param value A position in the raw-data file to which one wants to move before the next read
65
*/
66
virtual
void
Seek
(int64_t value) override;
67
68
/*
69
* Checks whether the reading stream is good
70
* @return 'true' if the underlying stream is good, or 'false' otherwise
71
*/
72
[[nodiscard]] virtual
bool
IsGood
() const noexcept override;
73
74
/*
75
* Check if we have reached the file.
76
* @note This method will return 'true' ONLY IF one tries to a byte after the last one
77
* @return 'true' if eof flag of the internal stream is set, 'false' otherwise
78
*/
79
[[nodiscard]] virtual
bool
IsEOF
() const noexcept override;
80
81
/*
82
* A method that clears bad flags after an error has occurred. Just calling this error will most likely
83
* not solve the problem, and you will get an error again in the next read. That is, before calling `Read`,
84
* remove the previous error source
85
*/
86
virtual
void
ClearStateFlags
() override;
87
88
/*
89
* @return 'true' if the input stream is open, or 'false' if not
90
*/
91
[[nodiscard]] virtual
bool
IsOpen
() const noexcept override;
92
93
/*
94
* @return BmnFileType::Raw
95
*/
96
[[nodiscard]] virtual
BmnFileType
GetFileType
() const noexcept override;
97
98
private:
99
std::ifstream
fInputStream
;
100
int64_t
fNextByteToRead
;
101
};
102
103
#endif
// BmnFileReaderRaw_h
BmnFileType
BmnFileType
Definition
BmnFileProcessingFlags.h:16
BmnIFileReader.h
BmnFileReaderRaw::BmnFileReaderRaw
BmnFileReaderRaw(BmnFileReaderRaw &&) noexcept=delete
BmnFileReaderRaw::IsOpen
virtual bool IsOpen() const noexcept override
Definition
BmnFileReaderRaw.cxx:74
BmnFileReaderRaw::GetFileType
virtual BmnFileType GetFileType() const noexcept override
Definition
BmnFileReaderRaw.cxx:79
BmnFileReaderRaw::fInputStream
std::ifstream fInputStream
Definition
BmnFileReaderRaw.h:99
BmnFileReaderRaw::ClearStateFlags
virtual void ClearStateFlags() override
Definition
BmnFileReaderRaw.cxx:69
BmnFileReaderRaw::Close
virtual void Close() noexcept override
Definition
BmnFileReaderRaw.cxx:31
BmnFileReaderRaw::fNextByteToRead
int64_t fNextByteToRead
Definition
BmnFileReaderRaw.h:100
BmnFileReaderRaw::Tell
virtual int64_t Tell() const noexcept override
Definition
BmnFileReaderRaw.cxx:45
BmnFileReaderRaw::Open
virtual void Open(const std::filesystem::path &aFilePath) override
Definition
BmnFileReaderRaw.cxx:20
BmnFileReaderRaw::Seek
virtual void Seek(int64_t value) override
Definition
BmnFileReaderRaw.cxx:50
BmnFileReaderRaw::operator=
BmnFileReaderRaw & operator=(const BmnFileReaderRaw &)=delete
BmnFileReaderRaw::BmnFileReaderRaw
BmnFileReaderRaw(const std::filesystem::path &aFilePath)
Definition
BmnFileReaderRaw.cxx:8
BmnFileReaderRaw::BmnFileReaderRaw
BmnFileReaderRaw(const BmnFileReaderRaw &)=delete
BmnFileReaderRaw::IsEOF
virtual bool IsEOF() const noexcept override
Definition
BmnFileReaderRaw.cxx:64
BmnFileReaderRaw::IsGood
virtual bool IsGood() const noexcept override
Definition
BmnFileReaderRaw.cxx:59
BmnFileReaderRaw::~BmnFileReaderRaw
virtual ~BmnFileReaderRaw()=default
BmnFileReaderRaw::Read
virtual int64_t Read(void *dataToFill, const int64_t sizeToFill) override
Definition
BmnFileReaderRaw.cxx:37
BmnIFileReader::BmnIFileReader
BmnIFileReader()=default
compression
include
BmnFileReaderRaw.h
Generated on
for BmnRoot by
1.17.0