MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

bool MayaFlux::IO::RawTensorReader::open ( const std::string & filepath,
FileReadOptions options = FileReadOptions::ALL )
overridevirtual

Open a file for reading.

Parameters
filepathPath to the file.
optionsReading options (see FileReadOptions).
Returns
true if file was successfully opened.

Implements MayaFlux::IO::FileReader.

Definition at line 45 of file RawTensorReader.cpp.

46{
47 close();
48 if (m_layout.empty()) {
49 return fail("set_layout() must describe the tensors before open()");
50 }
51
52 m_path = resolve_path(filepath);
53 m_file.open(m_path, std::ios::binary);
54 if (!m_file) {
55 return fail("cannot open '" + m_path + "'");
56 }
57 m_file.seekg(0, std::ios::end);
58 const auto file_size = static_cast<uint64_t>(m_file.tellg());
59
60 uint64_t cursor = 0;
61 for (const auto& entry : m_layout) {
62 const uint64_t begin = entry.file_offset.value_or(cursor);
63 const auto range = entry.spec.byte_range();
64 if (!range || range->second > file_size || begin > file_size - range->second) {
65 close();
66 return fail("tensor '" + entry.spec.name + "' extends past the end of the file");
67 }
68 m_offsets.push_back(begin);
69 cursor = begin + range->second;
70 }
71
72 m_open = true;
73 m_last_error.clear();
74 return true;
75}
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
std::vector< RawTensorEntry > m_layout
std::vector< uint64_t > m_offsets
void close() override
Close the currently open file.
bool fail(std::string reason)
Record a failure reason and return false.
std::vector< double > range(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Value range (max - min) per window.
Definition Analysis.cpp:473

References close(), MayaFlux::IO::TensorReader::fail(), m_file, MayaFlux::IO::TensorReader::m_last_error, m_layout, m_offsets, m_open, MayaFlux::IO::TensorReader::m_path, and MayaFlux::IO::FileReader::resolve_path().

Here is the call graph for this function: