HepMC3 event record library
Writerprotobuf Class Reference

Detailed Description

GenEvent I/O serialization for protobuf-based binary files.

If HepMC was compiled with protobuf available, this class can be used for writing in the same manner as with HepMC::WriterAscii class.

Definition at line 32 of file Writerprotobuf.h.

#include <Writerprotobuf.h>

+ Inheritance diagram for Writerprotobuf:
+ Collaboration diagram for Writerprotobuf:

Public Member Functions

 Writerprotobuf (const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 New file constructor.
 
 Writerprotobuf (std::ostream &out_stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 ostream constructor
 
 Writerprotobuf (std::shared_ptr< std::ostream > out_stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 ostream constructor
 
void write_event (const GenEvent &evt) override
 Write event to file.
 
void close () override
 Close file stream.
 
bool failed () override
 Get stream error state flag.
 
virtual ~Writerprotobuf ()
 Standard destructor.
 
void write_run_info ()
 Write the GenRunInfo object to file.
 
virtual void set_run_info (std::shared_ptr< GenRunInfo > run)
 Set the global GenRunInfo object.
 
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
 Set options.
 

Protected Attributes

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

Private Member Functions

void start_file ()
 Write non-event front matter to the output stream.
 

Private Attributes

std::unique_ptr< std::ofstream > m_out_file
 The output file stream.
 
std::ostream * m_out_stream
 The stream object that is written to.
 
size_t m_events_written
 The number of events written to the stream.
 
size_t m_event_bytes_written
 The number of event bytes written to the stream.
 
std::shared_ptr< GenRunInfom_run_info
 The global GenRunInfo object.
 

Constructor & Destructor Documentation

◆ Writerprotobuf() [1/3]

Writerprotobuf ( const std::string & filename,
std::shared_ptr< GenRunInfo > run = std::shared_ptr<GenRunInfo>() )

New file constructor.

Warning
If file exists, it will be overwritten

Definition at line 59 of file Writerprotobuf.cc.

References HEPMC3_ERROR, Writerprotobuf::m_out_file, Writerprotobuf::m_out_stream, Writer::set_run_info(), and Writerprotobuf::start_file().

◆ Writerprotobuf() [2/3]

Writerprotobuf ( std::ostream & out_stream,
std::shared_ptr< GenRunInfo > run = std::shared_ptr<GenRunInfo>() )

ostream constructor

Attempts to write a binary HepMC3 protobuf event stream to the passed ostream object

Definition at line 82 of file Writerprotobuf.cc.

References Writerprotobuf::m_out_stream, Writer::set_run_info(), and Writerprotobuf::start_file().

◆ Writerprotobuf() [3/3]

Writerprotobuf ( std::shared_ptr< std::ostream > out_stream,
std::shared_ptr< GenRunInfo > run = std::shared_ptr<GenRunInfo>() )

ostream constructor

Attempts to write a binary HepMC3 protobuf event stream to the passed ostream object

Definition at line 101 of file Writerprotobuf.cc.

◆ ~Writerprotobuf()

virtual ~Writerprotobuf ( )
inlinevirtual

Standard destructor.

Definition at line 78 of file Writerprotobuf.h.

References Writerprotobuf::close().

Member Function Documentation

◆ close()

◆ failed()

bool failed ( )
overridevirtual

Get stream error state flag.

Implements Writer.

Definition at line 270 of file Writerprotobuf.cc.

References Writerprotobuf::m_out_file, and Writerprotobuf::m_out_stream.

◆ get_options()

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

Set options.

Reimplemented in WriterPlugin.

Definition at line 54 of file Writer.h.

References Writer::m_options.

◆ run_info()

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

Get the global GenRunInfo object.

Reimplemented in WriterPlugin.

Definition at line 45 of file Writer.h.

References Writer::m_run_info.

◆ set_options()

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

Set options.

Reimplemented in WriterPlugin.

Definition at line 52 of file Writer.h.

References Writer::m_options.

◆ set_run_info()

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

Set the global GenRunInfo object.

Reimplemented in WriterPlugin.

Definition at line 42 of file Writer.h.

References Writer::m_run_info.

◆ start_file()

void start_file ( )
private

Write non-event front matter to the output stream.

Definition at line 105 of file Writerprotobuf.cc.

References Writerprotobuf::m_out_stream, HepMC3::ProtobufMagicHeader, HepMC3::version(), HepMC3::write_message(), and Writerprotobuf::write_run_info().

◆ write_event()

◆ write_run_info()

Field Documentation

◆ m_event_bytes_written

size_t m_event_bytes_written
private

The number of event bytes written to the stream.

Definition at line 105 of file Writerprotobuf.h.

◆ m_events_written

size_t m_events_written
private

The number of events written to the stream.

Definition at line 103 of file Writerprotobuf.h.

◆ m_options

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

options

Definition at line 59 of file Writer.h.

◆ m_out_file

std::unique_ptr<std::ofstream> m_out_file
private

The output file stream.

This is non-null and owned by this class if the instance was constructed with the string constructor, it is null otherwise.

Definition at line 94 of file Writerprotobuf.h.

◆ m_out_stream

std::ostream* m_out_stream
private

The stream object that is written to.

If constructed with the string constructor, this just points to m_out_file.get())

Definition at line 100 of file Writerprotobuf.h.

◆ m_run_info

std::shared_ptr<GenRunInfo> m_run_info
privateinherited

The global GenRunInfo object.

Definition at line 64 of file Writer.h.


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