BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
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 */
16{
17 public:
18 /*
19 * A standard constructor that sets a path to the input raw binary file
20 * @note The constructor will not check whether the file actually exists
21 * @param fileName A path (most likely relative) to the input raw binary file
22 * @warning If using relative paths, be very careful about currently-working directory as it might
23 * be something unexpected based on the directory that initalized an application
24 */
25 explicit BmnFileReaderRaw(const std::string& fileName = "");
26
27 /*
28 * A standard constructor that sets a path to the input raw binary file
29 * @note The constructor will not check whether the file actually exists
30 * @param fileName A path (most likely relative) to the input raw binary file
31 * @warning If using relative paths, be very careful about currently-working directory as it might
32 * be something unexpected based on the directory that initalized an application
33 */
34 explicit BmnFileReaderRaw(std::string&& fileName);
35
36 /*
37 * A standard constructor that sets a path to the input raw binary file
38 * @note The constructor will not check whether the file actually exists
39 * @param filePath A path to the input raw binary file
40 * @warning If using relative paths, be very careful about currently-working directory as it might
41 * be something unexpected based on the directory that initalized an application
42 */
43 explicit BmnFileReaderRaw(const std::filesystem::path& filePath);
44
45 /*
46 * A standard constructor that sets a path to the input raw binary file
47 * @note The constructor will not check whether the file actually exists
48 * @param filePath A path to the input raw binary file
49 * @warning If using relative paths, be very careful about currently-working directory as it might
50 * be something unexpected based on the directory that initalized an application
51 */
52 explicit BmnFileReaderRaw(std::filesystem::path&& filePath);
53
54 virtual ~BmnFileReaderRaw() = default;
57 BmnFileReaderRaw(BmnFileReaderRaw&&) noexcept = delete;
58 BmnFileReaderRaw& operator=(BmnFileReaderRaw&&) noexcept = delete;
59
60 // ========== BmnIFileReaderInterface ==========
61
62 /*
63 * Opens a raw file for reading. The path of the file should be provided before calling this method
64 * @param processingFlags A flag that tells us how to open the file for reading. This class only supports
65 * `ReadBinary` flag
66 */
67 virtual void Open(
69
70 /*
71 * Closes the input stream. After calling `Close`, it's safe to reopen using the same instance of this class
72 */
73 virtual void Close() noexcept override;
74
75 /*
76 * Reads the binary-file data and writes them into the provided buffer.
77 * @param dataToFill A buffer that will be filled with uncompressed data
78 * @param sizeToFill A number of bytes that will be filled in `dataToFill`
79 * @return A number of bytes that were filled in `dataToFill`. This value should almost always be the same as
80 * `sizeToFill` except when the end of the stream is reached (only if the user asked for more data than
81 * possible)
82 */
83 virtual int64_t Read(void* dataToFill, const int64_t sizeToFill) override;
84
85 /*
86 * A method that tells us what's next to read
87 * @return A position of the next byte that should be read
88 */
89 [[nodiscard]] virtual int64_t Tell() const noexcept override;
90
91 /*
92 * A method that sets a position for a next-byte read
93 * @param value A position in the raw-data file to which one wants to move before the next read
94 */
95 virtual void Seek(int64_t value) override;
96
97 /*
98 * Checks whether the reading stream is good
99 * @return 'true' if the underlying stream is good, or 'false' otherwise
100 */
101 [[nodiscard]] virtual bool IsGood() const noexcept override;
102
103 /*
104 * Check if we have reached the file.
105 * @note This method will return 'true' ONLY IF one tries to a byte after the last one
106 * @return 'true' if eof flag of the internal stream is set, 'false' otherwise
107 */
108 [[nodiscard]] virtual bool IsEOF() const noexcept override;
109
110 /*
111 * A method that clears bad flags after an error has occurred. Just calling this error will most likely
112 * not solve the problem, and you will get an error again in the next read. That is, before calling `Read`,
113 * remove the previous error source
114 */
115 virtual void ClearStateFlags() override;
116
117 /*
118 * @return 'true' if the input stream is open, or 'false' if not
119 */
120 [[nodiscard]] virtual bool IsOpen() const noexcept override;
121
122 private:
123 std::ifstream fInputStream;
124 int64_t fNextByteToRead;
125};
126
127#endif // BmnFileReaderRaw_h
BmnFileReaderRaw(BmnFileReaderRaw &&) noexcept=delete
virtual bool IsOpen() const noexcept override
std::ifstream fInputStream
virtual void ClearStateFlags() override
BmnFileReaderRaw(std::string &&fileName)
virtual void Close() noexcept override
BmnFileReaderRaw(const std::string &fileName="")
virtual int64_t Tell() const noexcept override
virtual void Seek(int64_t value) override
BmnFileReaderRaw & operator=(const BmnFileReaderRaw &)=delete
BmnFileReaderRaw(std::filesystem::path &&filePath)
BmnFileReaderRaw(const BmnFileReaderRaw &)=delete
virtual bool IsEOF() const noexcept override
virtual void Open(const BmnBinaryFileProcessingOptions processingFlags=BmnBinaryFileProcessingOptions::ReadBinary) override
virtual bool IsGood() const noexcept override
BmnFileReaderRaw(const std::filesystem::path &filePath)
virtual ~BmnFileReaderRaw()=default
virtual int64_t Read(void *dataToFill, const int64_t sizeToFill) override
BmnBinaryFileProcessingOptions
Definition json.hpp:4446