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 40 of file Readerprotobuf.h.

#include <Readerprotobuf.h>

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

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< 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 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< 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 37 of file Readerprotobuf.cc.

References HEPMC3_ERROR_LEVEL, m_in_zcstream, m_inf_zcstream, 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 62 of file Readerprotobuf.cc.

References m_in_stream, m_in_zcistream, m_in_zcstream, 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 76 of file Readerprotobuf.cc.

References m_shared_stream, and Readerprotobuf().

Member Function Documentation

◆ close()

void close ( )
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.

◆ failed()

bool failed ( )
overridevirtual

Get stream error state.

Implements Reader.

Definition at line 224 of file Readerprotobuf.cc.

References m_in_stream, and m_inf_zcstream.

◆ 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_digest()

bool read_digest ( )
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.

◆ 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 203 of file Readerprotobuf.cc.

References 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 81 of file Readerprotobuf.cc.

References HEPMC3_ERROR_LEVEL, m_in_zcstream, m_md_pb, HepMC3::ProtobufMagicHeader, HepMC3::ProtobufMagicHeaderBytes, read_GenRunInfo(), and read_Header().

◆ read_GenEvent()

bool read_GenEvent ( bool skip,
GenEvent & evt )
private

Parse the next protobuf message as a GenEvent message.

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

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().

◆ read_GenRunInfo()

bool read_GenRunInfo ( )
private

Parse the next protobuf message as a GenRunInfo message.

Returns
Whether the reader can still be read from after reading

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().

◆ 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 131 of file Readerprotobuf.cc.

References close(), m_hdr_pb, m_in_zcstream, m_md_pb, and read_digest().

◆ run_info()

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

Get the global GenRunInfo object.

Reimplemented in ReaderGZ< T >, and 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 ReaderGZ< T >, and ReaderPlugin.

Definition at line 56 of file Reader.h.

References m_run_info.

◆ skip()

bool skip ( const int n)
overridevirtual

skips the next n events

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

Reimplemented from Reader.

Definition at line 193 of file Readerprotobuf.cc.

References failed(), and read_GenEvent().

Field Documentation

◆ m_evt_pb

HepMC3_pb::GenEventData m_evt_pb
private

GenEventInfo data.

Definition at line 147 of file Readerprotobuf.h.

◆ m_gri_pb

HepMC3_pb::GenRunInfoData m_gri_pb
private

GenRunInfo data.

Definition at line 146 of file Readerprotobuf.h.

◆ m_hdr_pb

HepMC3_pb::Header m_hdr_pb
private

Header.

Definition at line 145 of file Readerprotobuf.h.

◆ m_in_stream

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

◆ m_in_zcistream

std::unique_ptr<google::protobuf::io::IstreamInputStream> m_in_zcistream
private

Stream input.

Definition at line 141 of file Readerprotobuf.h.

◆ m_in_zcstream

google::protobuf::io::ZeroCopyInputStream* m_in_zcstream = nullptr
private

Zero copy input stream.

Definition at line 142 of file Readerprotobuf.h.

◆ m_inf_zcstream

std::unique_ptr<google::protobuf::io::FileInputStream> m_inf_zcstream
private

File input.

Definition at line 140 of file Readerprotobuf.h.

◆ m_md_pb

HepMC3_pb::MessageDigest m_md_pb
private

Message digest.

Definition at line 144 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.

◆ m_shared_stream

std::shared_ptr<std::istream> m_shared_stream
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.


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