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:
+ Collaboration diagram for WriterAsciiHepMC2:

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.
 
void set_run_info (std::shared_ptr< GenRunInfo > run)
 Set the global GenRunInfo object.
 
std::shared_ptr< GenRunInforun_info () const
 Get the global GenRunInfo object.
 
void set_options (const std::map< std::string, std::string > &options)
 Set options.
 
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

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)
 
std::string escape (const std::string &s) const
 Escape '\' and '
' characters in string.
 
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.
 
Write helpers
void write_string (const std::string &str)
 Inline function for writing strings.
 
void write_vertex (ConstGenVertexPtr v)
 Write vertex.
 
void write_particle (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
 Output precision.
 
char * m_buffer
 Stream buffer.
 
char * m_cursor
 Cursor inside stream buffer.
 
unsigned long m_buffer_size
 Buffer size.
 
unsigned long m_particle_counter
 Used to set bar codes.
 
std::string m_float_printf_specifier
 the specifier of printf used for floats
 
std::shared_ptr< GenRunInfom_run_info
 The global GenRunInfo object.
 

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, HEPMC3_WARNING, WriterAsciiHepMC2::m_file, WriterAsciiHepMC2::m_float_printf_specifier, WriterAsciiHepMC2::m_precision, 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>() 
)

◆ WriterAsciiHepMC2() [3/3]

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

◆ ~WriterAsciiHepMC2()

Destructor.

Definition at line 84 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::close(), and WriterAsciiHepMC2::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 263 of file WriterAsciiHepMC2.cc.

References HEPMC3_ERROR, HEPMC3_WARNING, WriterAsciiHepMC2::m_buffer, WriterAsciiHepMC2::m_buffer_size, and WriterAsciiHepMC2::m_cursor.

◆ close()

void close ( )
overridevirtual

Close file stream.

Implements Writer.

Definition at line 447 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::forced_flush(), and WriterAsciiHepMC2::m_stream.

◆ escape()

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

Escape '\' and '
' characters in string.

Definition at line 286 of file WriterAsciiHepMC2.cc.

◆ failed()

bool failed ( )
overridevirtual

Return status of the stream.

Implements Writer.

Definition at line 456 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_file.

◆ flush()

void flush ( )
inlineprivate

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

Definition at line 353 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_buffer, WriterAsciiHepMC2::m_buffer_size, WriterAsciiHepMC2::m_cursor, and WriterAsciiHepMC2::m_stream.

◆ forced_flush()

void forced_flush ( )
inlineprivate

Inline function forcing flush to the output stream.

Definition at line 366 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_buffer, WriterAsciiHepMC2::m_cursor, and WriterAsciiHepMC2::m_stream.

◆ get_options()

std::map< std::string, std::string > get_options ( ) const
inlineinherited

Set options.

Definition at line 61 of file Writer.h.

References Writer::m_options.

◆ precision()

int precision ( ) const

Return output precision.

Definition at line 463 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_precision.

◆ run_info()

std::shared_ptr< GenRunInfo > run_info ( ) const
inlineinherited

Get the global GenRunInfo object.

Definition at line 47 of file Writer.h.

References Writer::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 467 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_buffer, and WriterAsciiHepMC2::m_buffer_size.

◆ set_options()

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

Set options.

Definition at line 56 of file Writer.h.

References Writer::m_options.

◆ set_precision()

void set_precision ( const int &  prec)

Set output precision.

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

Definition at line 458 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_precision.

◆ set_run_info()

void set_run_info ( std::shared_ptr< GenRunInfo run)
inlineinherited

Set the global GenRunInfo object.

Definition at line 42 of file Writer.h.

References Writer::m_run_info.

◆ write_event()

void write_event ( const GenEvent evt)
overridevirtual

◆ write_particle()

void write_particle ( ConstGenParticlePtr  p,
int  second_field 
)
private

◆ write_run_info()

void write_run_info ( )

Write the GenRunInfo object to file.

Definition at line 374 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 429 of file WriterAsciiHepMC2.cc.

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

◆ write_vertex()

void write_vertex ( ConstGenVertexPtr  v)
private

Field Documentation

◆ m_buffer

char* m_buffer
private

Stream buffer.

Definition at line 125 of file WriterAsciiHepMC2.h.

◆ m_buffer_size

unsigned long m_buffer_size
private

Buffer size.

Definition at line 127 of file WriterAsciiHepMC2.h.

◆ m_cursor

char* m_cursor
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 68 of file Writer.h.

◆ m_particle_counter

unsigned long m_particle_counter
private

Used to set bar codes.

Definition at line 128 of file WriterAsciiHepMC2.h.

◆ m_precision

int m_precision
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 73 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: