BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
BmnIFileReader.cxx
Go to the documentation of this file.
1// headers from this target
2#include "BmnIFileReader.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
5// ================== BmnIFileReader 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
7
8BmnIFileReader::BmnIFileReader(const BmnFileType fileType, const std::string& fileName)
9 : fFilePath(fileName)
11 , fFileType(fileType)
12{}
13
14BmnIFileReader::BmnIFileReader(const BmnFileType fileType, std::string&& fileName) noexcept
15 : fFilePath(std::move(fileName))
17 , fFileType(fileType)
18{}
19
20BmnIFileReader::BmnIFileReader(const BmnFileType fileType, const std::filesystem::path& filePath)
21 : fFilePath(filePath)
23 , fFileType(fileType)
24{}
25
26BmnIFileReader::BmnIFileReader(const BmnFileType fileType, std::filesystem::path&& filePath) noexcept
27 : fFilePath(std::move(filePath))
29 , fFileType(fileType)
30{}
31
32void BmnIFileReader::Open(const std::string& fileName, const BmnBinaryFileProcessingOptions processingFlags)
33{
34 if (fileName.empty())
35 LOG(warning) << "You passed an empty string into `BmnFileReaderZstd::Open`!\n";
36 else
37 fFilePath = fileName;
38 return Open(processingFlags);
39}
40
41void BmnIFileReader::Open(std::string&& fileName, const BmnBinaryFileProcessingOptions processingFlags)
42{
43 if (fileName.empty())
44 LOG(warning) << "You passed an empty string into `BmnFileReaderZstd::Open`!\n";
45 else
46 fFilePath = std::move(fileName);
47 return Open(processingFlags);
48}
49
50void BmnIFileReader::Open(const std::filesystem::path& filePath, const BmnBinaryFileProcessingOptions processingFlags)
51{
52 if (filePath.empty())
53 LOG(warning) << "You passed an empty path into `BmnFileReaderZstd::Open`!\n";
54 else
55 fFilePath = filePath;
56 return Open(processingFlags);
57}
58
59void BmnIFileReader::Open(std::filesystem::path&& filePath, const BmnBinaryFileProcessingOptions processingFlags)
60{
61 if (filePath.empty())
62 LOG(warning) << "You passed an empty path into `BmnFileReaderZstd::Open`!\n";
63 else
64 fFilePath = std::move(filePath);
65 return Open(processingFlags);
66}
67
68// 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
69// ================== BmnIFileReader protected method ==================
70// 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
71
73{
74 if (processingFlags != BmnBinaryFileProcessingOptions::None)
75 fProcessingFlags = processingFlags;
76 if (fFilePath.empty()) {
77 LOG(error) << "No filepath provided before calling `BmnFileReaderZstd::Open` command!\n";
78 return false;
79 }
80 try {
81 if (!std::filesystem::exists(fFilePath) || std::filesystem::is_directory(fFilePath)) {
82 LOG(error) << "You should provide an existing file! Provided path: " << fFilePath << '\n';
83 return false;
84 }
85 } catch (const std::bad_alloc& errorDescription) {
86 LOG(error) << "Filesystem failure! Reason: " << errorDescription.what() << '\n';
87 return false;
88 } catch (const std::filesystem::filesystem_error& errorDescription) {
89 LOG(error) << "Filesystem failure! Reason: " << errorDescription.what() << '\n';
90 return false;
91 }
93 LOG(error) << "`BmnFileReaderZstd` expects `BmnBinaryFileProcessingOptions::ReadBinary` flag!\n";
94 return false;
95 }
97 LOG(warning) << "You've set some `BmnBinaryFileProcessingOptions` flags for writing while opening a file for "
98 "reading - double-check your code!\n";
100 LOG(warning) << "You've set some `BmnBinaryFileProcessingOptions` flags for compressing intensity while "
101 "opening a file for decompressing - double-check your code!\n";
103 LOG(warning) << "You've set some `BmnBinaryFileProcessingOptions` flags for compressing memory while opening a "
104 "file for decompressing - double-check your code!\n";
105 Close();
106 return true;
107}
auto HasAnyFlags(const T lhv, const T rhv) -> std::enable_if_t< std::is_enum_v< T >, bool >
Definition BmnEnums.h:61
BmnIFileReader(const BmnFileType fileType, const std::string &fileName="")
virtual void Close() noexcept=0
std::filesystem::path fFilePath
bool PerformStandardChecksBeforeOpening(const BmnBinaryFileProcessingOptions processingFlags)
BmnBinaryFileProcessingOptions fProcessingFlags
virtual void Open(const BmnBinaryFileProcessingOptions processingFlags=BmnBinaryFileProcessingOptions::ReadBinary)=0
BmnFileType fFileType
constexpr BmnBinaryFileProcessingOptions cg_writeFileFlags
constexpr BmnBinaryFileProcessingOptions cg_compressionIntensityFlags
BmnBinaryFileProcessingOptions
constexpr BmnBinaryFileProcessingOptions cg_compressionMemoryFlags