HepMC3 event record library
Readerprotobuf Class Reference

Detailed Description

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>

+ Inheritance diagram for Readerprotobuf:
+ Collaboration diagram for Readerprotobuf:

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< GenRunInforun_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< GenRunInfom_run_info
 The global GenRunInfo object.
 

Constructor & Destructor Documentation

◆ Readerprotobuf() [1/3]

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, m_in_file, m_in_stream, m_md_buffer, m_msg_type, HepMC3::MDBytesLength, read_file_start(), and Readerprotobuf().

◆ Readerprotobuf() [2/3]

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 m_in_stream, m_md_buffer, m_msg_type, HepMC3::MDBytesLength, and read_file_start().

◆ Readerprotobuf() [3/3]

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.

References Readerprotobuf().

Member Function Documentation

◆ buffer_message()

bool buffer_message ( )
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 close(), failed(), m_bytes_read, m_in_stream, m_md_buffer, m_msg_buffer, m_msg_type, and HepMC3::MDBytesLength.

◆ close()

void close ( )
overridevirtual

Close file stream.

Implements Reader.

Definition at line 396 of file Readerprotobuf.cc.

References m_in_file, m_in_stream, and m_msg_buffer.

◆ failed()

bool failed ( )
overridevirtual

Get stream error state.

Implements Reader.

Definition at line 405 of file Readerprotobuf.cc.

References m_in_file, and m_in_stream.

◆ file_header()

FileHeader const & file_header ( )
inline

Get the header information read from the protobuf file.

Definition at line 101 of file Readerprotobuf.h.

References m_file_header.

◆ get_options()

virtual std::map< std::string, std::string > get_options ( ) const
inlinevirtualinherited

Get options.

Reimplemented in ReaderPlugin.

Definition at line 53 of file Reader.h.

References m_options.

◆ read_event()

bool read_event ( GenEvent & evt)
overridevirtual

Read event from file.

Parameters
[out]evtContains parsed event
Returns
Whether the reader can still be read from after reading

Implements Reader.

Definition at line 384 of file Readerprotobuf.cc.

References m_evdata, GenEvent::read_data(), read_GenEvent(), Reader::run_info(), and GenEvent::set_run_info().

◆ read_file_start()

bool read_file_start ( )
private

Parse the front matter of the protobuf message stream before the events.

Definition at line 70 of file Readerprotobuf.cc.

References HEPMC3_ERROR, m_in_stream, m_msg_type, HepMC3::ProtobufMagicHeader, HepMC3::ProtobufMagicHeaderBytes, read_GenRunInfo(), and read_Header().

◆ read_GenEvent()

bool read_GenEvent ( bool skip = false)
private

Parse the next protobuf message as a GenEvent message.

Parameters
[in]skipWhether to bother actually parsing this message to a GenEvent
Returns
Whether the reader can still be read from after reading

Definition at line 234 of file Readerprotobuf.cc.

References buffer_message(), close(), HEPMC3_ERROR, GenParticleData::is_mass_set, m_evdata, m_msg_buffer, m_msg_type, GenParticleData::mass, GenParticleData::momentum, GenParticleData::pid, GenVertexData::position, skip(), GenParticleData::status, and GenVertexData::status.

◆ read_GenRunInfo()

bool read_GenRunInfo ( )
private

◆ read_Header()

bool read_Header ( )
private

Parse the next protobuf message as a Header message.

Returns
Whether the reader can still be read from after reading

Definition at line 147 of file Readerprotobuf.cc.

References buffer_message(), close(), m_file_header, m_msg_buffer, and m_msg_type.

◆ run_info()

virtual std::shared_ptr< GenRunInfo > run_info ( ) const
inlinevirtualinherited

Get the global GenRunInfo object.

Reimplemented in ReaderPlugin.

Examples
LHEF_example_cat.cc.

Definition at line 44 of file Reader.h.

References m_run_info.

◆ set_options()

virtual void set_options ( const std::map< std::string, std::string > & options)
inlinevirtualinherited

Set options.

Reimplemented in ReaderPlugin.

Definition at line 51 of file Reader.h.

References m_options.

◆ set_run_info()

virtual void set_run_info ( std::shared_ptr< GenRunInfo > run)
inlinevirtualinherited

Set the global GenRunInfo object.

Reimplemented in ReaderPlugin.

Definition at line 56 of file Reader.h.

References m_run_info.

◆ skip()

bool skip ( const int the)
overridevirtual

skips the next N events

Parameters
[in]thenumber of events to skip
Returns
Whether the reader can still be read from after skipping

Reimplemented from Reader.

Definition at line 374 of file Readerprotobuf.cc.

References failed(), and read_GenEvent().

Field Documentation

◆ m_bytes_read

size_t m_bytes_read = 0
private

The total number of event bytes read, including message frames.

Definition at line 144 of file Readerprotobuf.h.

◆ m_evdata

HepMC3::GenEventData m_evdata
private

The event data parsed from the message.

Definition at line 175 of file Readerprotobuf.h.

◆ m_file_header

FileHeader m_file_header
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.

◆ m_in_file

std::unique_ptr<std::ifstream> m_in_file
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.

◆ m_in_stream

std::istream* m_in_stream = nullptr
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.

◆ m_md_buffer

std::string m_md_buffer
private

The buffer used to hold the current message digest binary (message frame)

Definition at line 166 of file Readerprotobuf.h.

◆ m_msg_buffer

std::string m_msg_buffer
private

The buffer used to hold the current message binary (header/genruninfo/genevent/footer)

Definition at line 162 of file Readerprotobuf.h.

◆ m_msg_type

int m_msg_type
private

The type of current message.

Defined in HepMC3_pb::MessageDigest::MessageType in the proto file

Definition at line 171 of file Readerprotobuf.h.

◆ m_options

std::map<std::string, std::string> m_options
protectedinherited

Options.

Definition at line 60 of file Reader.h.

◆ m_run_info

std::shared_ptr<GenRunInfo> m_run_info
privateinherited

The global GenRunInfo object.

Definition at line 63 of file Reader.h.


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