HepMC3 event record library: WriterAsciiHepMC2 Class Reference

HepMC3 event record library

Public Member Functions | Protected Attributes | Private Attributes
WriterAsciiHepMC2 Class Reference

## Detailed Description

GenEvent I/O serialization for structured text files.

Definition at line 26 of file WriterAsciiHepMC2.h.

`#include <WriterAsciiHepMC2.h>`

Inheritance diagram for WriterAsciiHepMC2:
[legend]
Collaboration diagram for WriterAsciiHepMC2:
[legend]

## Public Member Functions
| WriterAsciiHepMC2 (const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
| Constructor.
| WriterAsciiHepMC2 (std::ostream &stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
| Constructor from ostream.
| WriterAsciiHepMC2 (std::shared_ptr< std::ostream > s_stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
| Constructor from temp ostream.
| ~WriterAsciiHepMC2 ()
| Destructor.
void | write_event (const GenEvent &evt) override
| Write event to file.
void | write_run_info ()
| Write the GenRunInfo object to file.
bool | failed () override
| Return status of the stream.
void | close () override
| Close file stream.
void | set_precision (const int &prec)
| Set output precision.
int | precision () const
| Return output precision.
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
Write helpers
void | write_string (const std::string &str)
| Inline function for writing strings.
void | write_vertex (const ConstGenVertexPtr &v)
| Write vertex.
void | write_particle (const ConstGenParticlePtr &p, int second_field)
| Write particle.

## Private Attributes
std::ofstream | m_file
| Output file.
std::shared_ptr< std::ostream > | m_shared_stream
| Output temp. stream.
std::ostream * | m_stream
| Output stream.
int | m_precision = 16
| Output precision.
char * | m_buffer = nullptr
| Stream buffer.
char * | m_cursor = nullptr
| Cursor inside stream buffer.
unsigned long | m_buffer_size = 262144
| Buffer size.
unsigned long | m_particle_counter = 0
| Used to set bar codes.
std::string | m_float_printf_specifier
| the specifier of printf used for floats
std::shared_ptr< GenRunInfo > | m_run_info
| The global GenRunInfo object.

## Buffer management
void | allocate_buffer ()
| Attempts to allocate buffer of the chosen size.
void | set_buffer_size (const size_t &size)
| Set buffer size (in bytes).
void | flush ()
| Inline function flushing buffer to output stream when close to buffer capacity.
void | forced_flush ()
| Inline function forcing flush to the output stream.
static std::string | escape (const std::string &s)
| Escape '\' and ' ' characters in string.

## Constructor & Destructor Documentation

## ◆ WriterAsciiHepMC2() [1/3]

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

Constructor.

Warning
  If file already exists, it will be cleared before writing

Definition at line 24 of file WriterAsciiHepMC2.cc.

References HEPMC3_ERROR_LEVEL, HEPMC3_WARNING_LEVEL, m_file, m_float_printf_specifier, m_precision, m_stream, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().

## ◆ WriterAsciiHepMC2() [2/3]

WriterAsciiHepMC2 | ( | std::ostream & | stream,
|  | std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() )

Constructor from ostream.

Definition at line 43 of file WriterAsciiHepMC2.cc.

References HEPMC3_WARNING_LEVEL, m_float_printf_specifier, m_precision, m_stream, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().

## ◆ WriterAsciiHepMC2() [3/3]

WriterAsciiHepMC2 | ( | std::shared_ptr< std::ostream > | s_stream,
|  | std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() )

Constructor from temp ostream.

Definition at line 54 of file WriterAsciiHepMC2.cc.

References HEPMC3_WARNING_LEVEL, m_float_printf_specifier, m_precision, m_shared_stream, m_stream, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().

## ◆ ~WriterAsciiHepMC2()

~WriterAsciiHepMC2 | ( |  | ) |

Destructor.

Definition at line 67 of file WriterAsciiHepMC2.cc.

References close(), and m_buffer.

## Member Function Documentation

## ◆ allocate_buffer()

void allocate_buffer | ( |  | ) |
| private

Attempts to allocate buffer of the chosen size.

This function can be called manually by the user or will be called before first read/write operation

Note
  If buffer size is too large it will be divided by 2 until it is small enough for system to allocate

Definition at line 248 of file WriterAsciiHepMC2.cc.

References HEPMC3_ERROR_LEVEL, HEPMC3_WARNING_LEVEL, m_buffer, m_buffer_size, and m_cursor.

## ◆ close()

void close | ( |  | ) |
| overridevirtual

Close file stream.

Implements Writer.

Definition at line 432 of file WriterAsciiHepMC2.cc.

References forced_flush(), and m_stream.

## ◆ escape()

std::string escape | ( | const std::string & | s | ) |
| staticprivate

Escape '\' and '
' characters in string.

Definition at line 271 of file WriterAsciiHepMC2.cc.

## ◆ failed()

bool failed | ( |  | ) |
| overridevirtual

Return status of the stream.

Implements Writer.

Definition at line 443 of file WriterAsciiHepMC2.cc.

References m_file.

## ◆ flush()

void flush | ( |  | ) |
| inlineprivate

Inline function flushing buffer to output stream when close to buffer capacity.

Definition at line 338 of file WriterAsciiHepMC2.cc.

References m_buffer, m_buffer_size, m_cursor, and m_stream.

## ◆ forced_flush()

void forced_flush | ( |  | ) |
| inlineprivate

Inline function forcing flush to the output stream.

Definition at line 351 of file WriterAsciiHepMC2.cc.

References m_buffer, m_cursor, and m_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.

## ◆ precision()

int precision | ( |  | ) | const

Return output precision.

Definition at line 450 of file WriterAsciiHepMC2.cc.

References m_precision.

## ◆ 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_buffer_size()

void set_buffer_size | ( | const size_t & | size | ) |
| private

Set buffer size (in bytes).

Default is 256kb. Minimum is 256b. Size can only be changed before first read/write operation.

Definition at line 454 of file WriterAsciiHepMC2.cc.

References m_buffer, and m_buffer_size.

## ◆ 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_precision()

void set_precision | ( | const int & | prec | ) |

Set output precision.

Available range is [2,24]. Default is 16.

Definition at line 445 of file WriterAsciiHepMC2.cc.

References m_precision.

## ◆ 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.

## ◆ 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 74 of file WriterAsciiHepMC2.cc.

References allocate_buffer(), GenEvent::attribute(), escape(), GenEvent::event_number(), flush(), forced_flush(), HEPMC3_WARNING_LEVEL, GenEvent::length_unit(), m_buffer, m_cursor, m_float_printf_specifier, Writer::m_options, m_particle_counter, m_precision, GenEvent::momentum_unit(), Units::name(), GenEvent::run_info(), Writer::run_info(), Writer::set_run_info(), GenEvent::vertices(), GenEvent::weights(), write_particle(), write_string(), and write_vertex().

## ◆ write_particle()

void write_particle | ( | const ConstGenParticlePtr & | p,
|  | int | second_field )
| private

Write particle.

Helper routine for writing single particle to file

Definition at line 361 of file WriterAsciiHepMC2.cc.

References flush(), m_cursor, m_float_printf_specifier, m_particle_counter, and write_string().

## ◆ write_run_info()

void write_run_info | ( |  | ) |

Write the GenRunInfo object to file.

Definition at line 359 of file WriterAsciiHepMC2.cc.

## ◆ write_string()

void write_string | ( | const std::string & | str | ) |
| inlineprivate

Inline function for writing strings.

Since strings can be long (maybe even longer than buffer) they have to be dealt with separately.

Definition at line 414 of file WriterAsciiHepMC2.cc.

References flush(), forced_flush(), m_buffer, m_buffer_size, m_cursor, and m_stream.

## ◆ write_vertex()

void write_vertex | ( | const ConstGenVertexPtr & | v | ) |
| private

Write vertex.

Helper routine for writing single vertex to file

Definition at line 292 of file WriterAsciiHepMC2.cc.

References flush(), FourVector::is_zero(), m_cursor, m_float_printf_specifier, FourVector::t(), FourVector::x(), FourVector::y(), and FourVector::z().

## Field Documentation

## ◆ m_buffer

char* m_buffer = nullptr
| private

Stream buffer.

Definition at line 125 of file WriterAsciiHepMC2.h.

## ◆ m_buffer_size

unsigned long m_buffer_size = 262144
| private

Buffer size.

Definition at line 127 of file WriterAsciiHepMC2.h.

## ◆ m_cursor

char* m_cursor = nullptr
| private

Cursor inside stream buffer.

Definition at line 126 of file WriterAsciiHepMC2.h.

## ◆ m_file

std::ofstream m_file
| private

Output file.

Definition at line 121 of file WriterAsciiHepMC2.h.

## ◆ m_float_printf_specifier

std::string m_float_printf_specifier
| private

the specifier of printf used for floats

Definition at line 129 of file WriterAsciiHepMC2.h.

## ◆ m_options

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

options

Definition at line 59 of file Writer.h.

## ◆ m_particle_counter

unsigned long m_particle_counter = 0
| private

Used to set bar codes.

Definition at line 128 of file WriterAsciiHepMC2.h.

## ◆ m_precision

int m_precision = 16
| private

Output precision.

Definition at line 124 of file WriterAsciiHepMC2.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

Output temp. stream.

Definition at line 122 of file WriterAsciiHepMC2.h.

## ◆ m_stream

std::ostream* m_stream
| private

Output stream.

Definition at line 123 of file WriterAsciiHepMC2.h.

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

- WriterAsciiHepMC2.h
- WriterAsciiHepMC2.cc