7#include <sio/compression/zlib.h>
8#include <sio/definitions.h>
17 m_stream.open(filename, std::ios::binary);
18 if (!m_stream.is_open()) {
19 throw std::runtime_error(
"File " + filename +
" couldn't be opened");
24 readCollectionIDTable();
28 if (name != m_categoryName) {
33 sio::api::go_to_record(m_stream,
"event_record");
34 }
catch (sio::exception&) {
43 sio::buffer::container bufferBytes{m_tableBuffer.data(), m_tableBuffer.data() + m_tableBuffer.size()};
44 auto tableBuffer = sio::buffer(std::move(bufferBytes));
47 return std::make_unique<SIOFrameData>(std::move(dataBuffer), dataInfo._uncompressed_length, std::move(tableBuffer),
52 if (name != m_categoryName) {
58 m_eventNumber = entry;
60 const auto recordPos = m_tocRecord.
getPosition(
"event_record", entry);
64 m_stream.seekg(recordPos);
70 if (name !=
"events") {
76void SIOLegacyReader::readCollectionIDTable() {
81 sio::block_list blocks;
82 blocks.emplace_back(std::make_shared<SIOCollectionIDTableBlock>());
83 blocks.emplace_back(std::make_shared<SIOVersionBlock>());
84 sio::api::read_blocks(infoBuffer.span(), blocks);
86 m_fileVersion =
static_cast<SIOVersionBlock*
>(blocks[1].get())->version;
90 auto tmpUncBuffer = sio::buffer{sio::mbyte};
91 auto tmpRecInfo = sio::api::write_record(
"dummy", tmpUncBuffer, blocks, 0);
92 sio::zlib_compression compressor;
93 compressor.set_level(6);
94 sio::api::compress_record(tmpRecInfo, tmpUncBuffer, m_tableBuffer, compressor);
95 m_tableUncLength = tmpRecInfo._uncompressed_length;
98bool SIOLegacyReader::readFileTOCRecord() {
101 m_stream.seekg(-sio_helpers::SIOTocInfoSize, std::ios_base::end);
102 uint64_t firstWords{0};
103 m_stream.read(
reinterpret_cast<char*
>(&firstWords),
sizeof(firstWords));
105 const uint32_t marker = (firstWords >> 32) & 0xffffffff;
106 if (marker == sio_helpers::SIOTocMarker) {
107 const uint32_t position = firstWords & 0xffffffff;
108 m_stream.seekg(position);
112 sio::block_list blocks;
113 auto tocBlock = std::make_shared<SIOFileTOCRecordBlock>();
114 tocBlock->record = &m_tocRecord;
115 blocks.push_back(tocBlock);
117 sio::api::read_blocks(uncBuffer.span(), blocks);
129 return {m_categoryName};
static SIOBlockLibraryLoader & instance()
PositionType getPosition(const std::string &name, unsigned iEntry=0) const
size_t getNRecords(const std::string &name) const
std::unique_ptr< podio::SIOFrameData > readEntry(const std::string &, const unsigned entry)
unsigned getEntries(const std::string &name) const
Returns the number of.
std::unique_ptr< podio::SIOFrameData > readNextEntry(const std::string &)
void openFile(const std::string &filename)
std::vector< std::string_view > getAvailableCategories() const
Get the names of all the availalable Frame categories in the current file(s)
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.