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

#include <SIOReader.h>

+ Inheritance diagram for podio::SIOReader:

Public Member Functions

 SIOReader ()
 
 ~SIOReader ()=default
 
 SIOReader (const SIOReader &)=delete
 
SIOReaderoperator= (const SIOReader &)=delete
 
void openFile (const std::string &filename) override
 
void closeFile () override
 
void readEvent () override
 Read all collections requested.
 
void goToEvent (unsigned iEvent) override
 
std::shared_ptr< CollectionIDTablegetCollectionIDTable () override
 Read CollectionIDTable from SIO file.
 
unsigned getEntries () const override
 get the number of events available from this reader
 
bool isValid () const override
 Check if file is valid.
 
podio::version::Version currentFileVersion () const override
 Get the podio version with which the current file has been written.
 
void endOfEvent () override
 Prepare the reader to read the next event.
 
- Public Member Functions inherited from podio::IReader
virtual ~IReader ()=default
 
virtual CollectionBasereadCollection (const std::string &name)=0
 
virtual std::shared_ptr< CollectionIDTablegetCollectionIDTable ()=0
 Get CollectionIDTable of read-in data.
 
virtual GenericParametersreadEventMetaData ()=0
 read event meta data from file
 
virtual std::map< int, GenericParameters > * readCollectionMetaData ()=0
 
virtual std::map< int, GenericParameters > * readRunMetaData ()=0
 
virtual unsigned getEntries () const =0
 get the number of events available from this reader
 
virtual void endOfEvent ()=0
 Prepare the reader to read the next event.
 
virtual bool isValid () const =0
 Check if reader is valid.
 
virtual void openFile (const std::string &filename)=0
 
virtual void closeFile ()=0
 
virtual void readEvent ()=0
 
virtual void goToEvent (unsigned iEvent)=0
 
virtual podio::version::Version currentFileVersion () const =0
 Get the podio version with which the current file has been written.
 

Detailed Description

This class has the function to read available data from disk and to prepare collections and buffers.

Definition at line 30 of file SIOReader.h.

Constructor & Destructor Documentation

◆ SIOReader() [1/2]

podio::SIOReader::SIOReader ( )

Definition at line 15 of file SIOReader.cc.

15 :
16 m_eventNumber(0),
17 m_eventMetaData(std::make_shared<SIOEventMetaDataBlock>()),
18 m_runMetaData(std::make_shared<SIONumberedMetaDataBlock>("RunMetaData")),
19 m_collectionMetaData(std::make_shared<SIONumberedMetaDataBlock>("CollectionMetaData")) {
20 auto& libLoader [[maybe_unused]] = SIOBlockLibraryLoader::instance();
21}
static SIOBlockLibraryLoader & instance()
Definition: SIOBlock.h:263

◆ ~SIOReader()

podio::SIOReader::~SIOReader ( )
default

◆ SIOReader() [2/2]

podio::SIOReader::SIOReader ( const SIOReader )
delete

Member Function Documentation

◆ closeFile()

void podio::SIOReader::closeFile ( )
overridevirtual

Implements podio::IReader.

Definition at line 74 of file SIOReader.cc.

74 {
75 m_stream.close();
76}

Referenced by main().

◆ currentFileVersion()

podio::version::Version podio::SIOReader::currentFileVersion ( ) const
inlineoverridevirtual

Get the podio version with which the current file has been written.

Implements podio::IReader.

Definition at line 61 of file SIOReader.h.

61 {
62 return m_fileVersion;
63 }

Referenced by main().

◆ endOfEvent()

void podio::SIOReader::endOfEvent ( )
overridevirtual

Prepare the reader to read the next event.

Implements podio::IReader.

Definition at line 107 of file SIOReader.cc.

107 {
108 ++m_eventNumber;
109 m_blocks.clear();
110 m_inputs.clear();
111}

Referenced by main().

◆ getCollectionIDTable()

std::shared_ptr< CollectionIDTable > podio::SIOReader::getCollectionIDTable ( )
inlineoverridevirtual

Read CollectionIDTable from SIO file.

Implements podio::IReader.

Definition at line 50 of file SIOReader.h.

50 {
51 return m_table;
52 }

◆ getEntries()

unsigned podio::SIOReader::getEntries ( ) const
inlineoverridevirtual

get the number of events available from this reader

Implements podio::IReader.

Definition at line 54 of file SIOReader.h.

54 {
55 return m_tocRecord.getNRecords("event_record");
56 }
size_t getNRecords(const std::string &name) const
Definition: SIOBlock.cc:195

Referenced by main().

◆ goToEvent()

void podio::SIOReader::goToEvent ( unsigned  iEvent)
overridevirtual

Implements podio::IReader.

Definition at line 113 of file SIOReader.cc.

113 {
114 // If we are already past the desired event number, rewind to the start first
115 if (eventNumber < (unsigned)m_eventNumber) {
116 m_stream.clear();
117 m_stream.seekg(0);
118 m_eventNumber = 0;
119 }
120
121 sio::api::go_to_record(m_stream, "event_record");
122 if ((eventNumber - m_eventNumber) > 0) {
123 sio::api::skip_n_records(m_stream, eventNumber - m_eventNumber);
124 }
125 m_eventNumber = eventNumber;
126
127 m_inputs.clear();
128 m_blocks.clear();
129}

◆ isValid()

bool podio::SIOReader::isValid ( ) const
overridevirtual

Check if file is valid.

Implements podio::IReader.

Definition at line 103 of file SIOReader.cc.

103 {
104 return m_stream.good();
105}

Referenced by openFile().

◆ openFile()

void podio::SIOReader::openFile ( const std::string &  filename)
overridevirtual

Implements podio::IReader.

Definition at line 62 of file SIOReader.cc.

62 {
63 m_stream.open(filename, std::ios::binary);
64 if (!this->isValid()) {
65 throw std::runtime_error("File " + filename + " couldn't be found");
66 }
67 readCollectionIDTable();
68
69 if (!readFileTOCRecord()) {
70 reconstructFileTOCRecord();
71 }
72}
bool isValid() const override
Check if file is valid.
Definition: SIOReader.cc:103

Referenced by main().

◆ operator=()

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

◆ readEvent()

void podio::SIOReader::readEvent ( )
overridevirtual

Read all collections requested.

Implements podio::IReader.

Definition at line 78 of file SIOReader.cc.

78 {
79 // recreate the blocks, since the contents are owned and managed by the
80 // EventStore
81 createBlocks();
82
83 // skip possible intermediate records that are not event data
84 sio::api::go_to_record(m_stream, "event_record");
85
86 sio::record_info rec_info;
87 sio::api::read_record_info(m_stream, rec_info, m_info_buffer);
88 sio::api::read_record_data(m_stream, rec_info, m_rec_buffer);
89
90 m_unc_buffer.resize(rec_info._uncompressed_length);
91 sio::zlib_compression compressor;
92 compressor.uncompress(m_rec_buffer.span(), m_unc_buffer);
93 sio::api::read_blocks(m_unc_buffer.span(), m_blocks);
94
95 for (size_t i = 1; i < m_blocks.size(); ++i) {
96 auto* blk = static_cast<podio::SIOBlock*>(m_blocks[i].get());
97 m_inputs.emplace_back(blk->getCollection(), m_table->names()[i - 1]);
98 }
99
100 m_lastEventRead = m_eventNumber;
101}
Base class for sio::block handlers used with PODIO.
Definition: SIOBlock.h:60

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