HepMC3 event record library
|
GenEvent I/O parsing and serialization for protobuf-based binary files.
If HepMC was compiled with path to protobuf available, this class can be used for protobuf file I/O in the same manner as with HepMC::ReaderAscii class.
Definition at line 40 of file Readerprotobuf.h.
#include <Readerprotobuf.h>
Public Member Functions | |
Readerprotobuf (const std::string &filename) | |
filename constructor | |
Readerprotobuf (std::istream &stream) | |
istream constructor | |
Readerprotobuf (std::shared_ptr< std::istream > stream) | |
istream constructor | |
bool | skip (const int n) override |
skips the next n events | |
bool | read_event (GenEvent &evt) override |
Read event from file. | |
void | close () override |
Close file stream. | |
bool | failed () override |
Get stream error state. | |
virtual std::shared_ptr< GenRunInfo > | run_info () const |
Get the global GenRunInfo object. | |
virtual void | set_options (const std::map< std::string, std::string > &options) |
Set options. | |
virtual std::map< std::string, std::string > | get_options () const |
Get options. | |
virtual void | set_run_info (std::shared_ptr< GenRunInfo > run) |
Set the global GenRunInfo object. | |
Protected Attributes | |
std::map< std::string, std::string > | m_options |
Options. | |
Private Member Functions | |
bool | read_digest () |
Read the next protobuf message digest. | |
bool | read_GenRunInfo () |
Parse the next protobuf message as a GenRunInfo message. | |
bool | read_GenEvent (bool skip, GenEvent &evt) |
Parse the next protobuf message as a GenEvent message. | |
bool | read_Header () |
Parse the next protobuf message as a Header message. | |
bool | read_file_start () |
Parse the front matter of the protobuf message stream before the events. | |
Private Attributes | |
std::shared_ptr< std::istream > | m_shared_stream |
Passed in shared_ptr to an input stream. | |
std::istream * | m_in_stream = nullptr |
The stream object that is read from. | |
std::unique_ptr< google::protobuf::io::FileInputStream > | m_inf_zcstream |
File input. | |
std::unique_ptr< google::protobuf::io::IstreamInputStream > | m_in_zcistream |
Stream input. | |
google::protobuf::io::ZeroCopyInputStream * | m_in_zcstream = nullptr |
Zero copy input stream. | |
HepMC3_pb::MessageDigest | m_md_pb |
Message digest. | |
HepMC3_pb::Header | m_hdr_pb |
Header. | |
HepMC3_pb::GenRunInfoData | m_gri_pb |
GenRunInfo data. | |
HepMC3_pb::GenEventData | m_evt_pb |
GenEventInfo data. | |
std::shared_ptr< GenRunInfo > | m_run_info |
The global GenRunInfo object. | |
Readerprotobuf | ( | const std::string & | filename | ) |
filename constructor
Attempts to open the passed filename and read protobuf HepMC3 events from it
Definition at line 37 of file Readerprotobuf.cc.
References HEPMC3_ERROR_LEVEL, m_in_zcstream, m_inf_zcstream, read_file_start(), and Readerprotobuf().
Readerprotobuf | ( | std::istream & | stream | ) |
istream constructor
Attempts to read a binary HepMC3 protobuf event stream from the passed istream object
Definition at line 62 of file Readerprotobuf.cc.
References m_in_stream, m_in_zcistream, m_in_zcstream, and read_file_start().
Readerprotobuf | ( | std::shared_ptr< std::istream > | stream | ) |
istream constructor
Attempts to read a binary HepMC3 protobuf event stream from the passed istream object
Definition at line 76 of file Readerprotobuf.cc.
References m_shared_stream, and Readerprotobuf().
|
overridevirtual |
Close file stream.
Implements Reader.
Definition at line 214 of file Readerprotobuf.cc.
References m_in_stream, m_in_zcistream, and m_inf_zcstream.
|
overridevirtual |
Get stream error state.
Implements Reader.
Definition at line 224 of file Readerprotobuf.cc.
References m_in_stream, and m_inf_zcstream.
|
inlinevirtualinherited |
Get options.
Reimplemented in ReaderPlugin.
Definition at line 53 of file Reader.h.
References m_options.
|
private |
Read the next protobuf message digest.
Determines the type and byte length of the next payload
Definition at line 110 of file Readerprotobuf.cc.
References close(), failed(), m_in_zcstream, m_md_pb, and HepMC3::MDBytesLength.
|
overridevirtual |
Read event from file.
[out] | evt | Contains parsed event |
Implements Reader.
Definition at line 203 of file Readerprotobuf.cc.
References read_GenEvent(), Reader::run_info(), and GenEvent::set_run_info().
|
private |
Parse the front matter of the protobuf message stream before the events.
Definition at line 81 of file Readerprotobuf.cc.
References HEPMC3_ERROR_LEVEL, m_in_zcstream, m_md_pb, HepMC3::ProtobufMagicHeader, HepMC3::ProtobufMagicHeaderBytes, read_GenRunInfo(), and read_Header().
|
private |
Parse the next protobuf message as a GenEvent message.
[in] | skip | Whether to bother actually parsing this message to a GenEvent |
[out] | evt | output GenEvent |
Definition at line 173 of file Readerprotobuf.cc.
References close(), m_evt_pb, m_in_zcstream, m_md_pb, GenEvent::read_data(), and read_digest().
|
private |
Parse the next protobuf message as a GenRunInfo message.
Definition at line 151 of file Readerprotobuf.cc.
References close(), m_gri_pb, m_in_zcstream, m_md_pb, read_digest(), Reader::run_info(), and Reader::set_run_info().
|
private |
Parse the next protobuf message as a Header message.
Definition at line 131 of file Readerprotobuf.cc.
References close(), m_hdr_pb, m_in_zcstream, m_md_pb, and read_digest().
|
inlinevirtualinherited |
Get the global GenRunInfo object.
Reimplemented in ReaderGZ< T >, and ReaderPlugin.
Definition at line 44 of file Reader.h.
References m_run_info.
|
inlinevirtualinherited |
Set options.
Reimplemented in ReaderPlugin.
Definition at line 51 of file Reader.h.
References m_options.
|
inlinevirtualinherited |
Set the global GenRunInfo object.
Reimplemented in ReaderGZ< T >, and ReaderPlugin.
Definition at line 56 of file Reader.h.
References m_run_info.
|
overridevirtual |
skips the next n events
[in] | n | the number of events to skip |
Reimplemented from Reader.
Definition at line 193 of file Readerprotobuf.cc.
References failed(), and read_GenEvent().
|
private |
GenEventInfo data.
Definition at line 147 of file Readerprotobuf.h.
|
private |
GenRunInfo data.
Definition at line 146 of file Readerprotobuf.h.
|
private |
Header.
Definition at line 145 of file Readerprotobuf.h.
|
private |
The stream object that is read from.
If constructed with either stream constructor this lets us check we can use this to check stream status
Definition at line 138 of file Readerprotobuf.h.
|
private |
Stream input.
Definition at line 141 of file Readerprotobuf.h.
|
private |
Zero copy input stream.
Definition at line 142 of file Readerprotobuf.h.
|
private |
File input.
Definition at line 140 of file Readerprotobuf.h.
|
private |
Message digest.
Definition at line 144 of file Readerprotobuf.h.
|
protectedinherited |
|
privateinherited |
The global GenRunInfo object.
|
private |
Passed in shared_ptr to an input stream.
This is non-null and shared by this class if constructed with the stream constructor
Definition at line 132 of file Readerprotobuf.h.