7#include <sio/definitions.h>
19 m_stream.open(filename, std::ios::binary);
20 if (!m_stream.is_open()) {
21 throw std::runtime_error(
"File " + filename +
" couldn't be opened");
36 const auto recordPos = m_tocRecord.
getPosition(name, m_nameCtr[name]);
40 m_stream.seekg(recordPos);
47 return std::make_unique<SIOFrameData>(std::move(dataBuffer), dataInfo._uncompressed_length, std::move(tableBuffer),
48 tableInfo._uncompressed_length);
54 m_nameCtr[name] = entry;
62 recordNames.erase(std::remove_if(recordNames.begin(), recordNames.end(),
63 [](
const auto& elem) { return elem == sio_helpers::SIOEDMDefinitionName; }),
72bool SIOFrameReader::readFileTOCRecord() {
75 m_stream.seekg(-sio_helpers::SIOTocInfoSize, std::ios_base::end);
76 uint64_t firstWords{0};
77 m_stream.read(
reinterpret_cast<char*
>(&firstWords),
sizeof(firstWords));
79 const uint32_t marker = (firstWords >> 32) & 0xffffffff;
80 if (marker == sio_helpers::SIOTocMarker) {
81 const uint32_t position = firstWords & 0xffffffff;
82 m_stream.seekg(position);
86 sio::block_list blocks;
87 auto tocBlock = std::make_shared<SIOFileTOCRecordBlock>();
88 tocBlock->record = &m_tocRecord;
89 blocks.push_back(tocBlock);
91 sio::api::read_blocks(uncBuffer.span(), blocks);
102void SIOFrameReader::readPodioHeader() {
105 sio::block_list blocks;
106 blocks.emplace_back(std::make_shared<SIOVersionBlock>());
107 sio::api::read_blocks(buffer.span(), blocks);
109 m_fileVersion =
static_cast<SIOVersionBlock*
>(blocks[0].get())->version;
112void SIOFrameReader::readEDMDefinitions() {
113 const auto recordPos = m_tocRecord.
getPosition(sio_helpers::SIOEDMDefinitionName);
114 if (recordPos == 0) {
118 m_stream.seekg(recordPos);
122 sio::block_list blocks;
124 sio::api::read_blocks(buffer.span(), blocks);
126 auto datamodelDefs =
static_cast<SIOMapBlock<std::string, std::string>*
>(blocks[0].get());
127 m_datamodelHolder = DatamodelDefinitionHolder(std::move(datamodelDefs->mapData));
static SIOBlockLibraryLoader & instance()
PositionType getPosition(const std::string &name, unsigned iEntry=0) const
size_t getNRecords(const std::string &name) const
std::vector< std::string_view > getRecordNames() const
unsigned getEntries(const std::string &name) const
Returns number of entries for the given name.
std::vector< std::string_view > getAvailableCategories() const
Get the names of all the availalable Frame categories in the current file(s)
void openFile(const std::string &filename)
std::unique_ptr< podio::SIOFrameData > readEntry(const std::string &name, const unsigned entry)
std::unique_ptr< podio::SIOFrameData > readNextEntry(const std::string &name)
std::pair< sio::buffer, sio::record_info > readRecord(sio::ifstream &stream, bool decompress=true, std::size_t initBufferSize=sio::mbyte)
Read the record into a buffer and potentially uncompress it.