HepMC3 event record library
WriterAscii Class Reference

Detailed Description

#include <WriterAscii.h>

+ Inheritance diagram for WriterAscii:
+ Collaboration diagram for WriterAscii:

Public Member Functions

 WriterAscii (const std::string &filename, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 Constructor.
 
 WriterAscii (std::ostream &stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 Constructor from ostream.
 
 WriterAscii (std::shared_ptr< std::ostream > s_stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 Constructor from temp ostream.
 
 ~WriterAscii ()
 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< 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

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 = nullptr
 Output temp. stream.
 
std::ostream * m_stream = nullptr
 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.
 
std::string m_float_printf_specifier
 the specifier of printf used for floats
 
std::string m_particle_printf_specifier
 the specifier of printf used for floats
 
std::string m_vertex_short_printf_specifier
 the specifier of printf used for zero vertices
 
std::string m_vertex_long_printf_specifier
 the specifier of printf used for vertices
 
std::shared_ptr< GenRunInfom_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

◆ WriterAscii() [1/3]

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

◆ WriterAscii() [2/3]

◆ WriterAscii() [3/3]

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

◆ ~WriterAscii()

Destructor.

Definition at line 86 of file WriterAscii.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 206 of file WriterAscii.cc.

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

◆ close()

void close ( )
overridevirtual

◆ escape()

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

Escape '\' and '
' characters in string.

Definition at line 226 of file WriterAscii.cc.

◆ failed()

bool failed ( )
overridevirtual

Return status of the stream.

Implements Writer.

Definition at line 358 of file WriterAscii.cc.

References m_file.

◆ flush()

void flush ( )
inlineprivate

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

Definition at line 264 of file WriterAscii.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 276 of file WriterAscii.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 365 of file WriterAscii.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 369 of file WriterAscii.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.

So far available range is [2,24]. Default is 16.

Definition at line 360 of file WriterAscii.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()

◆ 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 326 of file WriterAscii.cc.

References flush(), m_cursor, and m_particle_printf_specifier.

◆ write_run_info()

void write_run_info ( )

◆ 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 333 of file WriterAscii.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 244 of file WriterAscii.cc.

References flush(), FourVector::is_zero(), m_cursor, m_vertex_long_printf_specifier, m_vertex_short_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 123 of file WriterAscii.h.

◆ m_buffer_size

unsigned long m_buffer_size = 262144
private

Buffer size.

Definition at line 125 of file WriterAscii.h.

◆ m_cursor

char* m_cursor = nullptr
private

Cursor inside stream buffer.

Definition at line 124 of file WriterAscii.h.

◆ m_file

std::ofstream m_file
private

Output file.

Definition at line 118 of file WriterAscii.h.

◆ m_float_printf_specifier

std::string m_float_printf_specifier
private

the specifier of printf used for floats

Definition at line 126 of file WriterAscii.h.

◆ m_options

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

options

Definition at line 59 of file Writer.h.

◆ m_particle_printf_specifier

std::string m_particle_printf_specifier
private

the specifier of printf used for floats

Definition at line 127 of file WriterAscii.h.

◆ m_precision

int m_precision = 16
private

Output precision.

Definition at line 122 of file WriterAscii.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 = nullptr
private

Output temp. stream.

Definition at line 119 of file WriterAscii.h.

◆ m_stream

std::ostream* m_stream = nullptr
private

Output stream.

Definition at line 120 of file WriterAscii.h.

◆ m_vertex_long_printf_specifier

std::string m_vertex_long_printf_specifier
private

the specifier of printf used for vertices

Definition at line 129 of file WriterAscii.h.

◆ m_vertex_short_printf_specifier

std::string m_vertex_short_printf_specifier
private

the specifier of printf used for zero vertices

Definition at line 128 of file WriterAscii.h.


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