HepMC3 event record library
|
GenEvent I/O serialization for structured text files.
Definition at line 25 of file WriterAscii.h.
#include <WriterAscii.h>
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< 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 | |
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 (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 |
Output precision. | |
char * | m_buffer |
Stream buffer. | |
char * | m_cursor |
Cursor inside stream buffer. | |
unsigned long | m_buffer_size |
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< GenRunInfo > | m_run_info |
The global GenRunInfo object. | |
WriterAscii | ( | const std::string & | filename, |
std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() ) |
Constructor.
Definition at line 25 of file WriterAscii.cc.
References HEPMC3_ERROR, m_buffer, m_buffer_size, m_cursor, m_file, m_float_printf_specifier, m_particle_printf_specifier, m_precision, m_stream, m_vertex_long_printf_specifier, m_vertex_short_printf_specifier, Writer::run_info(), Writer::set_run_info(), HepMC3::version(), and write_run_info().
WriterAscii | ( | std::ostream & | stream, |
std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() ) |
Constructor from ostream.
Definition at line 53 of file WriterAscii.cc.
References m_buffer, m_buffer_size, m_cursor, m_float_printf_specifier, m_particle_printf_specifier, m_precision, m_stream, m_vertex_long_printf_specifier, m_vertex_short_printf_specifier, Writer::run_info(), Writer::set_run_info(), HepMC3::version(), and write_run_info().
WriterAscii | ( | std::shared_ptr< std::ostream > | s_stream, |
std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() ) |
Constructor from temp ostream.
Definition at line 75 of file WriterAscii.cc.
References m_buffer, m_buffer_size, m_cursor, m_float_printf_specifier, m_particle_printf_specifier, m_precision, m_shared_stream, m_stream, m_vertex_long_printf_specifier, m_vertex_short_printf_specifier, Writer::run_info(), Writer::set_run_info(), HepMC3::version(), and write_run_info().
~WriterAscii | ( | ) |
|
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
Definition at line 220 of file WriterAscii.cc.
References HEPMC3_ERROR, HEPMC3_WARNING, m_buffer, m_buffer_size, and m_cursor.
|
overridevirtual |
Close file stream.
Implements Writer.
Definition at line 362 of file WriterAscii.cc.
References forced_flush(), and m_stream.
|
private |
Escape '\' and '
' characters in string.
Definition at line 240 of file WriterAscii.cc.
|
overridevirtual |
Return status of the stream.
Implements Writer.
Definition at line 370 of file WriterAscii.cc.
References m_file.
|
inlineprivate |
Inline function flushing buffer to output stream when close to buffer capacity.
Definition at line 278 of file WriterAscii.cc.
References m_buffer, m_buffer_size, m_cursor, and m_stream.
|
inlineprivate |
Inline function forcing flush to the output stream.
Definition at line 290 of file WriterAscii.cc.
|
inlinevirtualinherited |
Set options.
Reimplemented in WriterPlugin.
Definition at line 54 of file Writer.h.
References m_options.
int precision | ( | ) | const |
|
inlinevirtualinherited |
Get the global GenRunInfo object.
Reimplemented in WriterPlugin.
Definition at line 45 of file Writer.h.
References m_run_info.
|
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 381 of file WriterAscii.cc.
References m_buffer, and m_buffer_size.
|
inlinevirtualinherited |
Set options.
Reimplemented in WriterPlugin.
Definition at line 52 of file Writer.h.
References m_options.
void set_precision | ( | const int & | prec | ) |
Set output precision.
So far available range is [2,24]. Default is 16.
Definition at line 372 of file WriterAscii.cc.
References m_precision.
|
inlinevirtualinherited |
Set the global GenRunInfo object.
Reimplemented in WriterPlugin.
Definition at line 42 of file Writer.h.
References m_run_info.
|
overridevirtual |
Write event to file.
[in] | evt | Event to be serialized |
Implements Writer.
Definition at line 104 of file WriterAscii.cc.
References allocate_buffer(), GenEvent::attributes(), escape(), GenEvent::event_number(), GenEvent::event_pos(), flush(), forced_flush(), HEPMC3_DEBUG, HEPMC3_WARNING, FourVector::is_zero(), GenEvent::length_unit(), m_buffer, m_cursor, m_float_printf_specifier, Writer::m_options, m_particle_printf_specifier, m_precision, m_vertex_long_printf_specifier, m_vertex_short_printf_specifier, GenEvent::momentum_unit(), Units::name(), GenEvent::particles(), GenEvent::run_info(), Writer::run_info(), Writer::set_run_info(), FourVector::t(), GenEvent::vertices(), GenEvent::weights(), write_particle(), write_run_info(), write_string(), write_vertex(), FourVector::x(), FourVector::y(), and FourVector::z().
|
private |
Write particle.
Helper routine for writing single particle to file
Definition at line 340 of file WriterAscii.cc.
References flush(), m_cursor, and m_particle_printf_specifier.
void write_run_info | ( | ) |
Write the GenRunInfo object to file.
Definition at line 297 of file WriterAscii.cc.
References allocate_buffer(), escape(), flush(), HEPMC3_WARNING, m_cursor, Writer::run_info(), Writer::set_run_info(), and write_string().
|
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 347 of file WriterAscii.cc.
References flush(), forced_flush(), m_buffer, m_buffer_size, m_cursor, and m_stream.
|
private |
Write vertex.
Helper routine for writing single vertex to file
Definition at line 258 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().
|
private |
Stream buffer.
Definition at line 123 of file WriterAscii.h.
|
private |
Buffer size.
Definition at line 125 of file WriterAscii.h.
|
private |
Cursor inside stream buffer.
Definition at line 124 of file WriterAscii.h.
|
private |
Output file.
Definition at line 118 of file WriterAscii.h.
|
private |
the specifier of printf used for floats
Definition at line 126 of file WriterAscii.h.
|
protectedinherited |
|
private |
the specifier of printf used for floats
Definition at line 127 of file WriterAscii.h.
|
private |
Output precision.
Definition at line 122 of file WriterAscii.h.
|
privateinherited |
The global GenRunInfo object.
|
private |
Output temp. stream.
Definition at line 119 of file WriterAscii.h.
|
private |
Output stream.
Definition at line 120 of file WriterAscii.h.
|
private |
the specifier of printf used for vertices
Definition at line 129 of file WriterAscii.h.
|
private |
the specifier of printf used for zero vertices
Definition at line 128 of file WriterAscii.h.