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

#include <SIOFrameReader.h>

Public Member Functions

 SIOFrameReader ()
 
 ~SIOFrameReader ()=default
 
 SIOFrameReader (const SIOFrameReader &)=delete
 
SIOFrameReaderoperator= (const SIOFrameReader &)=delete
 
std::unique_ptr< podio::SIOFrameDatareadNextEntry (const std::string &name)
 
std::unique_ptr< podio::SIOFrameDatareadEntry (const std::string &name, const unsigned entry)
 
unsigned getEntries (const std::string &name) const
 Returns number of entries for the given name.
 
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)
 
const std::string_view getDatamodelDefinition (const std::string &name) const
 Get the datamodel definition for the given name.
 
std::vector< std::string > getAvailableDatamodels () const
 Get all names of the datamodels that ara available from this reader.
 

Detailed Description

Definition at line 20 of file SIOFrameReader.h.

Constructor & Destructor Documentation

◆ SIOFrameReader() [1/2]

podio::SIOFrameReader::SIOFrameReader ( )

Definition at line 14 of file SIOFrameReader.cc.

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

◆ ~SIOFrameReader()

podio::SIOFrameReader::~SIOFrameReader ( )
default

◆ SIOFrameReader() [2/2]

podio::SIOFrameReader::SIOFrameReader ( const SIOFrameReader )
delete

Member Function Documentation

◆ currentFileVersion()

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

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

Definition at line 50 of file SIOFrameReader.h.

50 {
51 return m_fileVersion;
52 }

◆ getAvailableCategories()

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

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

Definition at line 58 of file SIOFrameReader.cc.

58 {
59 // Filter the availalbe records from the TOC to remove records that are
60 // stored, but use reserved record names for podio meta data
61 auto recordNames = m_tocRecord.getRecordNames();
62 recordNames.erase(std::remove_if(recordNames.begin(), recordNames.end(),
63 [](const auto& elem) { return elem == sio_helpers::SIOEDMDefinitionName; }),
64 recordNames.end());
65 return recordNames;
66}
std::vector< std::string_view > getRecordNames() const
Definition: SIOBlock.cc:216

◆ getAvailableDatamodels()

std::vector< std::string > podio::SIOFrameReader::getAvailableDatamodels ( ) const
inline

Get all names of the datamodels that ara available from this reader.

Definition at line 63 of file SIOFrameReader.h.

63 {
64 return m_datamodelHolder.getAvailableDatamodels();
65 }
std::vector< std::string > getAvailableDatamodels() const

◆ getDatamodelDefinition()

const std::string_view podio::SIOFrameReader::getDatamodelDefinition ( const std::string &  name) const
inline

Get the datamodel definition for the given name.

Definition at line 58 of file SIOFrameReader.h.

58 {
59 return m_datamodelHolder.getDatamodelDefinition(name);
60 }
const std::string_view getDatamodelDefinition(const std::string &name) const

◆ getEntries()

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

Returns number of entries for the given name.

Definition at line 68 of file SIOFrameReader.cc.

68 {
69 return m_tocRecord.getNRecords(name);
70}
size_t getNRecords(const std::string &name) const
Definition: SIOBlock.cc:195

◆ openFile()

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

Definition at line 18 of file SIOFrameReader.cc.

18 {
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");
22 }
23
24 // NOTE: reading TOC record first because that jumps back to the start of the file!
25 readFileTOCRecord();
26 readPodioHeader();
27 readEDMDefinitions(); // Potentially could do this lazily
28}

◆ operator=()

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

◆ readEntry()

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

Read the specified data entry from which a Frame can be constructed for the given name. In case the entry does not exist for this name or in case there is no data for this name, this returns a nullptr.

Definition at line 51 of file SIOFrameReader.cc.

51 {
52 // NOTE: Will create or overwrite the entry counter
53 // All checks are done in the following function
54 m_nameCtr[name] = entry;
55 return readNextEntry(name);
56}
std::unique_ptr< podio::SIOFrameData > readNextEntry(const std::string &name)

◆ readNextEntry()

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

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

Definition at line 30 of file SIOFrameReader.cc.

30 {
31 // Skip to where the next record of this name starts in the file, based on
32 // how many times we have already read this name
33 //
34 // NOTE: exploiting the fact that the operator[] of a map will create a
35 // default initialized entry for us if not present yet
36 const auto recordPos = m_tocRecord.getPosition(name, m_nameCtr[name]);
37 if (recordPos == 0) {
38 return nullptr;
39 }
40 m_stream.seekg(recordPos);
41
42 auto [tableBuffer, tableInfo] = sio_utils::readRecord(m_stream, false);
43 auto [dataBuffer, dataInfo] = sio_utils::readRecord(m_stream, false);
44
45 m_nameCtr[name]++;
46
47 return std::make_unique<SIOFrameData>(std::move(dataBuffer), dataInfo._uncompressed_length, std::move(tableBuffer),
48 tableInfo._uncompressed_length);
49}
PositionType getPosition(const std::string &name, unsigned iEntry=0) const
Definition: SIOBlock.cc:204
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: