BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnFileReaderRaw.cxx
Go to the documentation of this file.
1// headers from this target
2#include "BmnFileReaderRaw.h"
3
4// o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
5// ================== BmnFileReaderZstd public methods ==================
6// o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
7
8BmnFileReaderRaw::BmnFileReaderRaw(const std::string& fileName)
9 : BmnIFileReader(BmnFileType::Raw, fileName)
10 , fInputStream()
11 , fNextByteToRead(0ll)
12{}
13
15 : BmnIFileReader(BmnFileType::Raw, std::move(fileName))
16 , fInputStream()
17 , fNextByteToRead(0ll)
18{}
19
20BmnFileReaderRaw::BmnFileReaderRaw(const std::filesystem::path& filePath)
21 : BmnIFileReader(BmnFileType::Raw, filePath)
22 , fInputStream()
23 , fNextByteToRead(0ll)
24{}
25
26BmnFileReaderRaw::BmnFileReaderRaw(std::filesystem::path&& filePath)
27 : BmnIFileReader(BmnFileType::Raw, std::move(filePath))
28 , fInputStream()
29 , fNextByteToRead(0ll)
30{}
31
32// ========== BmnIFileReaderInterface ==========
33
35{
36 if (fInputStream.is_open()) {
37 LOG(error) << "Before opening a new stream with `BmnFileReaderRaw::Open`, close the old one!\n";
38 return;
39 }
40 if (!PerformStandardChecksBeforeOpening(processingFlags))
41 return;
42 fInputStream.open(fFilePath, std::ios::in | std::ios::binary);
43}
44
46{
47 fInputStream.close();
48 fNextByteToRead = 0ll;
49}
50
51int64_t BmnFileReaderRaw::Read(void* dataToFill, const int64_t sizeToFill)
52{
53 fInputStream.read((char*)dataToFill, sizeToFill);
54 int64_t noOfReadBytes = fInputStream.gcount();
55 fNextByteToRead += noOfReadBytes;
56 return noOfReadBytes;
57}
58
59int64_t BmnFileReaderRaw::Tell() const noexcept
60{
61 return fNextByteToRead;
62}
63
64void BmnFileReaderRaw::Seek(int64_t value)
65{
66 if (fInputStream.bad())
67 return;
68 fInputStream.seekg(value);
69 if (fInputStream.good())
70 fNextByteToRead = value;
71}
72
73bool BmnFileReaderRaw::IsGood() const noexcept
74{
75 return fInputStream.good();
76}
77
78bool BmnFileReaderRaw::IsEOF() const noexcept
79{
80 return fInputStream.eof();
81}
82
87
88bool BmnFileReaderRaw::IsOpen() const noexcept
89{
90 return fInputStream.is_open();
91}
virtual bool IsOpen() const noexcept override
std::ifstream fInputStream
virtual void ClearStateFlags() override
virtual void Close() noexcept override
BmnFileReaderRaw(const std::string &fileName="")
virtual int64_t Tell() const noexcept override
virtual void Seek(int64_t value) override
virtual bool IsEOF() const noexcept override
virtual void Open(const BmnBinaryFileProcessingOptions processingFlags=BmnBinaryFileProcessingOptions::ReadBinary) override
virtual bool IsGood() const noexcept override
virtual int64_t Read(void *dataToFill, const int64_t sizeToFill) override
BmnIFileReader(const BmnFileType fileType, const std::string &fileName="")
std::filesystem::path fFilePath
bool PerformStandardChecksBeforeOpening(const BmnBinaryFileProcessingOptions processingFlags)
BmnBinaryFileProcessingOptions
Definition json.hpp:4446