HepMC3 event record library
Public Member Functions | Protected Attributes | Private Attributes
WriterAsciiHepMC2 Class Reference

GenEvent I/O serialization for structured text files. More...

#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. More...
 
 WriterAsciiHepMC2 (std::ostream &stream, std::shared_ptr< GenRunInfo > run=std::shared_ptr< GenRunInfo >())
 Constructor from ostream. More...
 
 ~WriterAsciiHepMC2 ()
 Destructor. More...
 
void write_event (const GenEvent &evt) override
 Write event to file. More...
 
void write_run_info ()
 Write the GenRunInfo object to file. More...
 
bool failed () override
 Return status of the stream. More...
 
void close () override
 Close file stream. More...
 
void set_precision (const int &prec)
 Set output precision. More...
 
int precision () const
 Return output precision. More...
 
void set_run_info (std::shared_ptr< GenRunInfo > run)
 Set the global GenRunInfo object. More...
 
std::shared_ptr< GenRunInforun_info () const
 Get the global GenRunInfo object. More...
 
void set_options (const std::map< std::string, std::string > &options)
 Set options. More...
 
std::map< std::string,
std::string > 
get_options () const
 Set options. More...
 

Protected Attributes

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

Private Member Functions

Buffer management
void allocate_buffer ()
 Attempts to allocate buffer of the chosen size. More...
 
void set_buffer_size (const size_t &size)
 Set buffer size (in bytes) More...
 
std::string escape (const std::string &s) const
 Escape '\' and '
' characters in string. More...
 
void flush ()
 Inline function flushing buffer to output stream when close to buffer capacity. More...
 
void forced_flush ()
 Inline function forcing flush to the output stream. More...
 
Write helpers
void write_string (const std::string &str)
 Inline function for writing strings. More...
 
void write_vertex (ConstGenVertexPtr v)
 Write vertex. More...
 
void write_particle (ConstGenParticlePtr p, int second_field)
 Write particle. More...
 

Private Attributes

std::ofstream m_file
 Output file. More...
 
std::ostream * m_stream
 Output stream. More...
 
int m_precision
 Output precision. More...
 
char * m_buffer
 Stream buffer. More...
 
char * m_cursor
 Cursor inside stream buffer. More...
 
unsigned long m_buffer_size
 Buffer size. More...
 
unsigned long m_particle_counter
 Used to set bar codes. More...
 

Detailed Description

GenEvent I/O serialization for structured text files.

Definition at line 26 of file WriterAsciiHepMC2.h.

Constructor & Destructor Documentation

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 23 of file WriterAsciiHepMC2.cc.

References HEPMC3_ERROR, HEPMC3_WARNING, WriterAsciiHepMC2::m_file, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().

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

Constructor from ostream.

Definition at line 46 of file WriterAsciiHepMC2.cc.

References HEPMC3_WARNING, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().

Destructor.

Definition at line 63 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::close(), and WriterAsciiHepMC2::m_buffer.

Member Function Documentation

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 217 of file WriterAsciiHepMC2.cc.

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

void close ( )
overridevirtual

Close file stream.

Implements Writer.

Definition at line 413 of file WriterAsciiHepMC2.cc.

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

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

Escape '\' and '
' characters in string.

Definition at line 240 of file WriterAsciiHepMC2.cc.

bool failed ( )
overridevirtual

Return status of the stream.

Implements Writer.

Definition at line 421 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_file.

void flush ( )
inlineprivate

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

Definition at line 306 of file WriterAsciiHepMC2.cc.

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

void forced_flush ( )
inlineprivate

Inline function forcing flush to the output stream.

Definition at line 320 of file WriterAsciiHepMC2.cc.

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

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

Set options.

Definition at line 61 of file Writer.h.

References Writer::m_options.

int precision ( ) const

Return output precision.

Definition at line 428 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_precision.

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.

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 432 of file WriterAsciiHepMC2.cc.

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

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.

void set_precision ( const int &  prec)

Set output precision.

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

Definition at line 423 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::m_precision.

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.

void write_event ( const GenEvent evt)
overridevirtual
void write_particle ( ConstGenParticlePtr  p,
int  second_field 
)
private

Write particle.

Helper routine for writing single particle to file

Definition at line 330 of file WriterAsciiHepMC2.cc.

References WriterAsciiHepMC2::flush(), WriterAsciiHepMC2::m_cursor, WriterAsciiHepMC2::m_particle_counter, WriterAsciiHepMC2::m_precision, and VectorIntAttribute::value().

void write_run_info ( )

Write the GenRunInfo object to file.

Definition at line 328 of file WriterAsciiHepMC2.cc.

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 392 of file WriterAsciiHepMC2.cc.

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

void write_vertex ( ConstGenVertexPtr  v)
private

Write vertex.

Helper routine for writing single vertex to file

Definition at line 261 of file WriterAsciiHepMC2.cc.

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

Field Documentation

char* m_buffer
private

Stream buffer.

Definition at line 120 of file WriterAsciiHepMC2.h.

unsigned long m_buffer_size
private

Buffer size.

Definition at line 122 of file WriterAsciiHepMC2.h.

char* m_cursor
private

Cursor inside stream buffer.

Definition at line 121 of file WriterAsciiHepMC2.h.

std::ofstream m_file
private

Output file.

Definition at line 117 of file WriterAsciiHepMC2.h.

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

options

Definition at line 68 of file Writer.h.

unsigned long m_particle_counter
private

Used to set bar codes.

Definition at line 123 of file WriterAsciiHepMC2.h.

int m_precision
private

Output precision.

Definition at line 119 of file WriterAsciiHepMC2.h.

std::ostream* m_stream
private

Output stream.

Definition at line 118 of file WriterAsciiHepMC2.h.


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