HepMC3 event record library: Writerprotobuf Class Reference

HepMC3 event record library

Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes
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:
[legend]
Collaboration diagram for Writerprotobuf:
[legend]

## 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< 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
| 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::shared_ptr< std::ostream > | m_shared_stream
| Passed in shared_ptr to an output 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< GenRunInfo > | m_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 51 of file Writerprotobuf.cc.

References HEPMC3_ERROR_LEVEL, m_event_bytes_written, m_events_written, m_out_file, m_out_stream, Writer::set_run_info(), and 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 74 of file Writerprotobuf.cc.

References m_event_bytes_written, m_events_written, m_out_file, m_out_stream, Writer::set_run_info(), and 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 92 of file Writerprotobuf.cc.

References m_shared_stream, and Writerprotobuf().

## ◆ ~Writerprotobuf()

virtual ~Writerprotobuf | ( |  | ) |
| inlinevirtual

Standard destructor.

Definition at line 78 of file Writerprotobuf.h.

References close().

## Member Function Documentation

## ◆ close()

void close | ( |  | ) |
| overridevirtual

Close file stream.

Implements Writer.

Definition at line 132 of file Writerprotobuf.cc.

References failed(), HEPMC3_ERROR_LEVEL, m_event_bytes_written, m_events_written, m_out_file, m_out_stream, and HepMC3::write_message().

## ◆ failed()

bool failed | ( |  | ) |
| overridevirtual

Get stream error state flag.

Implements Writer.

Definition at line 156 of file Writerprotobuf.cc.

References m_out_file, and 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 m_options.

## ◆ run_info()

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

Get the global GenRunInfo object.

Reimplemented in WriterGZ< T, C >, and WriterPlugin.

Definition at line 45 of file Writer.h.

References 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 m_options.

## ◆ set_run_info()

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

Set the global GenRunInfo object.

Reimplemented in WriterGZ< T, C >, and WriterPlugin.

Definition at line 42 of file Writer.h.

References m_run_info.

## ◆ start_file()

void start_file | ( |  | ) |
| private

Write non-event front matter to the output stream.

Definition at line 98 of file Writerprotobuf.cc.

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

## ◆ write_event()

void write_event | ( | const GenEvent & | evt | ) |
| overridevirtual

Write event to file.

Parameters

  [in] | evt | Event to be serialized

Implements Writer.

Definition at line 121 of file Writerprotobuf.cc.

References m_event_bytes_written, m_events_written, m_out_stream, and HepMC3::write_message().

## ◆ write_run_info()

void write_run_info | ( |  | ) |

Write the GenRunInfo object to file.

Definition at line 127 of file Writerprotobuf.cc.

References m_out_stream, Writer::run_info(), and HepMC3::write_message().

## 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 109 of file Writerprotobuf.h.

## ◆ m_events_written

size_t m_events_written
| private

The number of events written to the stream.

Definition at line 107 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 92 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 104 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.

## ◆ m_shared_stream

std::shared_ptr<std::ostream> m_shared_stream
| private

Passed in shared_ptr to an output stream.

This is non-null and shared by this class if constructed with the stream constructor

Definition at line 98 of file Writerprotobuf.h.

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

- Writerprotobuf.h
- Writerprotobuf.cc