PODIO v00-16-03
An Event-Data-Model Toolkit for High Energy Physics Experiments
Loading...
Searching...
No Matches
podio::SIOLegacyReader Class Reference

#include <SIOLegacyReader.h>

Public Member Functions

 SIOLegacyReader ()
 
 ~SIOLegacyReader ()=default
 
 SIOLegacyReader (const SIOLegacyReader &)=delete
 
SIOLegacyReaderoperator= (const SIOLegacyReader &)=delete
 
std::unique_ptr< podio::SIOFrameDatareadNextEntry (const std::string &)
 
std::unique_ptr< podio::SIOFrameDatareadEntry (const std::string &, const unsigned entry)
 
unsigned getEntries (const std::string &name) const
 Returns the number of.
 
void openFile (const std::string &filename)
 
podio::version::Version currentFileVersion () const
 Get the build version of podio that has been used to write the current file.
 
std::vector< std::string_view > getAvailableCategories () const
 Get the names of all the availalable Frame categories in the current file(s)
 

Detailed Description

A SIO reader for reading legacy podio .sio files that have been written using the legacy, non Frame based I/O model. This reader grants Frame based access to those files, by mimicking Frame I/O functionality and the interfaces of those readers.

NOTE: Since there was only one category ("events") for those legacy podio files this reader will really only work if you try to read that category, and will simply return no data if you try to read anything else.

Definition at line 28 of file SIOLegacyReader.h.

Constructor & Destructor Documentation

◆ SIOLegacyReader() [1/2]

podio::SIOLegacyReader::SIOLegacyReader ( )

Definition at line 12 of file SIOLegacyReader.cc.

12 {
13 auto& libLoader [[maybe_unused]] = SIOBlockLibraryLoader::instance();
14}
static SIOBlockLibraryLoader & instance()
Definition: SIOBlock.h:263

◆ ~SIOLegacyReader()

podio::SIOLegacyReader::~SIOLegacyReader ( )
default

◆ SIOLegacyReader() [2/2]

podio::SIOLegacyReader::SIOLegacyReader ( const SIOLegacyReader )
delete

Member Function Documentation

◆ currentFileVersion()

podio::version::Version podio::SIOLegacyReader::currentFileVersion ( ) const
inline

Get the build version of podio that has been used to write the current file.

Definition at line 62 of file SIOLegacyReader.h.

62 {
63 return m_fileVersion;
64 }

◆ getAvailableCategories()

std::vector< std::string_view > podio::SIOLegacyReader::getAvailableCategories ( ) const

Get the names of all the availalable Frame categories in the current file(s)

Definition at line 128 of file SIOLegacyReader.cc.

128 {
129 return {m_categoryName};
130}

◆ getEntries()

unsigned podio::SIOLegacyReader::getEntries ( const std::string &  name) const

Returns the number of.

Definition at line 69 of file SIOLegacyReader.cc.

69 {
70 if (name != "events") {
71 return 0;
72 }
73 return m_tocRecord.getNRecords("event_record");
74}
size_t getNRecords(const std::string &name) const
Definition: SIOBlock.cc:195

◆ openFile()

void podio::SIOLegacyReader::openFile ( const std::string &  filename)

Definition at line 16 of file SIOLegacyReader.cc.

16 {
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");
20 }
21
22 // NOTE: reading TOC record first because that jumps back to the start of the file!
23 readFileTOCRecord();
24 readCollectionIDTable();
25}

◆ operator=()

SIOLegacyReader & podio::SIOLegacyReader::operator= ( const SIOLegacyReader )
delete

◆ readEntry()

std::unique_ptr< podio::SIOFrameData > podio::SIOLegacyReader::readEntry ( const std::string &  name,
const unsigned  entry 
)

Read the specified data entry from which a Frame can be constructed In case the entry does not exist, this returns a nullptr.

NOTE: the category name has to be "events" in this case, as only that category is available for legacy files.

Definition at line 51 of file SIOLegacyReader.cc.

51 {
52 if (name != m_categoryName) {
53 return nullptr;
54 }
55
56 // Setting the event number to the desired one here and putting the stream to
57 // the right position is the necessary setup before simply handing off to readNextEntry
58 m_eventNumber = entry;
59 // NOTE: In legacy files the "events" are stored in "event_record" records
60 const auto recordPos = m_tocRecord.getPosition("event_record", entry);
61 if (recordPos == 0) {
62 return nullptr;
63 }
64 m_stream.seekg(recordPos);
65
66 return readNextEntry(name);
67}
PositionType getPosition(const std::string &name, unsigned iEntry=0) const
Definition: SIOBlock.cc:204
std::unique_ptr< podio::SIOFrameData > readNextEntry(const std::string &)

◆ readNextEntry()

std::unique_ptr< SIOFrameData > podio::SIOLegacyReader::readNextEntry ( const std::string &  name)

Read the next data entry from which a Frame can be constructed. In case there are no more entries left, this returns a nullptr.

NOTE: the category name has to be "events" in this case, as only that category is available for legacy files.

Definition at line 27 of file SIOLegacyReader.cc.

27 {
28 if (name != m_categoryName) {
29 return nullptr;
30 }
31 // skip possible intermediate records that are not event data
32 try {
33 sio::api::go_to_record(m_stream, "event_record");
34 } catch (sio::exception&) {
35 // If anything goes wrong, return a nullptr
36 return nullptr;
37 }
38
39 auto [dataBuffer, dataInfo] = sio_utils::readRecord(m_stream, false);
40 // Need to work around the fact that sio::buffers are not copyable by copying
41 // the underlying buffer (vector<byte>) and then using that to move construct
42 // a new buffer
43 sio::buffer::container bufferBytes{m_tableBuffer.data(), m_tableBuffer.data() + m_tableBuffer.size()};
44 auto tableBuffer = sio::buffer(std::move(bufferBytes));
45
46 m_eventNumber++;
47 return std::make_unique<SIOFrameData>(std::move(dataBuffer), dataInfo._uncompressed_length, std::move(tableBuffer),
48 m_tableUncLength);
49}
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.
Definition: sioUtils.h:18

Referenced by readEntry().


The documentation for this class was generated from the following files: