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 37 of file Readerprotobuf.h.
#include <Readerprotobuf.h>
Data Structures | |
class | FileHeader |
A copy of the information contained in the protobuf file header. More... | |
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 the) override |
skips the next N events | |
bool | read_event (GenEvent &evt) override |
Read event from file. | |
void | close () override |
Close file stream. | |
FileHeader const & | file_header () |
Get the header information read from the protobuf file. | |
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 | buffer_message () |
Read the next protobuf message into the message buffer. | |
bool | read_GenRunInfo () |
Parse the next protobuf message as a GenRunInfo message. | |
bool | read_GenEvent (bool skip=false) |
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 | |
size_t | m_bytes_read = 0 |
The total number of event bytes read, including message frames. | |
std::unique_ptr< std::ifstream > | m_in_file |
The file stream of the file being read. | |
std::istream * | m_in_stream = nullptr |
The stream object that is read from. | |
std::string | m_msg_buffer |
The buffer used to hold the current message binary (header/genruninfo/genevent/footer) | |
std::string | m_md_buffer |
The buffer used to hold the current message digest binary (message frame) | |
int | m_msg_type |
The type of current message. | |
HepMC3::GenEventData | m_evdata |
The event data parsed from the message. | |
FileHeader | m_file_header |
A copy of the library version info stored in the proto file header. | |
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 34 of file Readerprotobuf.cc.
References HEPMC3_ERROR, and HepMC3::MDBytesLength.
Readerprotobuf | ( | std::istream & | stream | ) |
istream constructor
Attempts to read a binary HepMC3 protobuf event stream from the passed istream object
Definition at line 52 of file Readerprotobuf.cc.
References HEPMC3_ERROR, Readerprotobuf::m_in_stream, Readerprotobuf::m_md_buffer, HepMC3::MDBytesLength, and Readerprotobuf::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 67 of file Readerprotobuf.cc.
|
private |
Read the next protobuf message into the message buffer.
Fills m_msg_buffer with the next message and sets m_msg_type to signify the message type. Returns true if there is a message in the buffer ready to parse.
Definition at line 102 of file Readerprotobuf.cc.
References Readerprotobuf::close(), Readerprotobuf::failed(), Readerprotobuf::m_bytes_read, Readerprotobuf::m_in_stream, Readerprotobuf::m_md_buffer, Readerprotobuf::m_msg_buffer, Readerprotobuf::m_msg_type, and HepMC3::MDBytesLength.
|
overridevirtual |
Close file stream.
Implements Reader.
Definition at line 396 of file Readerprotobuf.cc.
References Readerprotobuf::m_in_file, Readerprotobuf::m_in_stream, and Readerprotobuf::m_msg_buffer.
|
overridevirtual |
Get stream error state.
Implements Reader.
Definition at line 405 of file Readerprotobuf.cc.
References Readerprotobuf::m_in_file, and Readerprotobuf::m_in_stream.
|
inline |
Get the header information read from the protobuf file.
Definition at line 101 of file Readerprotobuf.h.
References Readerprotobuf::m_file_header.
|
inlinevirtualinherited |
Get options
Reimplemented in ReaderPlugin.
Definition at line 53 of file Reader.h.
References Reader::m_options.
|
overridevirtual |
Read event from file.
[out] | evt | Contains parsed event |
Implements Reader.
Definition at line 384 of file Readerprotobuf.cc.
References Readerprotobuf::m_evdata, GenEvent::read_data(), Readerprotobuf::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 70 of file Readerprotobuf.cc.
References HEPMC3_ERROR, Readerprotobuf::m_in_stream, Readerprotobuf::m_msg_type, HepMC3::ProtobufMagicHeader, HepMC3::ProtobufMagicHeaderBytes, Readerprotobuf::read_GenRunInfo(), and Readerprotobuf::read_Header().
|
private |
Parse the next protobuf message as a GenEvent message.
[in] | skip | Whether to bother actually parsing this message to a GenEvent |
Definition at line 234 of file Readerprotobuf.cc.
References GenEventData::attribute_id, GenEventData::attribute_name, GenEventData::attribute_string, Readerprotobuf::buffer_message(), Readerprotobuf::close(), GenEventData::event_number, GenEventData::event_pos, HEPMC3_ERROR, GenParticleData::is_mass_set, GenEventData::length_unit, GenEventData::links1, GenEventData::links2, Readerprotobuf::m_evdata, Readerprotobuf::m_msg_buffer, Readerprotobuf::m_msg_type, FourVector::m_v1, GenParticleData::mass, GenParticleData::momentum, GenEventData::momentum_unit, GenEventData::particles, GenParticleData::pid, GenVertexData::position, Readerprotobuf::skip(), GenParticleData::status, GenVertexData::status, GenEventData::vertices, and GenEventData::weights.
|
private |
Parse the next protobuf message as a GenRunInfo message.
Definition at line 176 of file Readerprotobuf.cc.
References GenRunInfoData::attribute_name, GenRunInfoData::attribute_string, Readerprotobuf::buffer_message(), Readerprotobuf::close(), Readerprotobuf::m_msg_buffer, Readerprotobuf::m_msg_type, Reader::run_info(), Reader::set_run_info(), GenRunInfoData::tool_description, GenRunInfoData::tool_name, GenRunInfoData::tool_version, and GenRunInfoData::weight_names.
|
private |
Parse the next protobuf message as a Header message.
Definition at line 147 of file Readerprotobuf.cc.
References Readerprotobuf::buffer_message(), Readerprotobuf::close(), Readerprotobuf::m_file_header, Readerprotobuf::m_msg_buffer, and Readerprotobuf::m_msg_type.
|
inlinevirtualinherited |
Get the global GenRunInfo object.
Reimplemented in ReaderPlugin.
Definition at line 44 of file Reader.h.
References Reader::m_run_info.
|
inlinevirtualinherited |
Set options.
Reimplemented in ReaderPlugin.
Definition at line 51 of file Reader.h.
References Reader::m_options.
|
inlinevirtualinherited |
Set the global GenRunInfo object.
Reimplemented in ReaderPlugin.
Definition at line 56 of file Reader.h.
References Reader::m_run_info.
|
overridevirtual |
skips the next N events
[in] | the | number of events to skip |
Reimplemented from Reader.
Definition at line 374 of file Readerprotobuf.cc.
References Readerprotobuf::failed(), and Readerprotobuf::read_GenEvent().
|
private |
The total number of event bytes read, including message frames.
Definition at line 144 of file Readerprotobuf.h.
|
private |
The event data parsed from the message.
Definition at line 175 of file Readerprotobuf.h.
|
private |
A copy of the library version info stored in the proto file header.
This is a copy so as to avoid passing on protobuf header dependencies to files that include this header
Definition at line 182 of file Readerprotobuf.h.
|
private |
The file stream of the file being read.
This is non-null and owned by this class if constructed with the string constructor, otherwise it will be null
Definition at line 151 of file Readerprotobuf.h.
|
private |
The stream object that is read from.
If constructed with the string constructor, this just points to m_in_file.get())
Definition at line 157 of file Readerprotobuf.h.
|
private |
The buffer used to hold the current message digest binary (message frame)
Definition at line 166 of file Readerprotobuf.h.
|
private |
The buffer used to hold the current message binary (header/genruninfo/genevent/footer)
Definition at line 162 of file Readerprotobuf.h.
|
private |
The type of current message.
Defined in HepMC3_pb::MessageDigest::MessageType in the proto file
Definition at line 171 of file Readerprotobuf.h.
|
protectedinherited |
|
privateinherited |
The global GenRunInfo object.