HepMC3 event record library
|
GenEvent I/O serialization for structured text files.
Definition at line 26 of file WriterAsciiHepMC2.h.
#include <WriterAsciiHepMC2.h>
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< GenRunInfo > | run_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< GenRunInfo > | m_run_info |
The global GenRunInfo object. | |
WriterAsciiHepMC2 | ( | const std::string & | filename, |
std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() |
||
) |
Constructor.
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 | ( | std::ostream & | stream, |
std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() |
||
) |
Constructor from ostream.
Definition at line 48 of file WriterAsciiHepMC2.cc.
References HEPMC3_WARNING, WriterAsciiHepMC2::m_float_printf_specifier, WriterAsciiHepMC2::m_precision, WriterAsciiHepMC2::m_stream, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().
WriterAsciiHepMC2 | ( | std::shared_ptr< std::ostream > | s_stream, |
std::shared_ptr< GenRunInfo > | run = std::shared_ptr<GenRunInfo>() |
||
) |
Constructor from temp ostream.
Definition at line 65 of file WriterAsciiHepMC2.cc.
References HEPMC3_WARNING, WriterAsciiHepMC2::m_float_printf_specifier, WriterAsciiHepMC2::m_precision, WriterAsciiHepMC2::m_stream, Writer::run_info(), Writer::set_run_info(), and HepMC3::version().
~WriterAsciiHepMC2 | ( | ) |
Destructor.
Definition at line 84 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::close(), and WriterAsciiHepMC2::m_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
Definition at line 263 of file WriterAsciiHepMC2.cc.
References HEPMC3_ERROR, HEPMC3_WARNING, WriterAsciiHepMC2::m_buffer, WriterAsciiHepMC2::m_buffer_size, and WriterAsciiHepMC2::m_cursor.
|
overridevirtual |
Close file stream.
Implements Writer.
Definition at line 447 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::forced_flush(), and WriterAsciiHepMC2::m_stream.
|
private |
Escape '\' and '
' characters in string.
Definition at line 286 of file WriterAsciiHepMC2.cc.
|
overridevirtual |
Return status of the stream.
Implements Writer.
Definition at line 456 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::m_file.
|
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.
|
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.
|
inlineinherited |
int precision | ( | ) | const |
Return output precision.
Definition at line 463 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::m_precision.
|
inlineinherited |
Get the global GenRunInfo object.
Definition at line 47 of file Writer.h.
References Writer::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 467 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::m_buffer, and WriterAsciiHepMC2::m_buffer_size.
|
inlineinherited |
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.
|
inlineinherited |
Set the global GenRunInfo object.
Definition at line 42 of file Writer.h.
References Writer::m_run_info.
|
overridevirtual |
Write event to file.
[in] | evt | Event to be serialized |
Implements Writer.
Definition at line 91 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::allocate_buffer(), GenEvent::attribute(), WriterAsciiHepMC2::escape(), GenEvent::event_number(), WriterAsciiHepMC2::flush(), WriterAsciiHepMC2::forced_flush(), HEPMC3_WARNING, GenEvent::length_unit(), WriterAsciiHepMC2::m_buffer, WriterAsciiHepMC2::m_cursor, WriterAsciiHepMC2::m_float_printf_specifier, Writer::m_options, WriterAsciiHepMC2::m_particle_counter, WriterAsciiHepMC2::m_precision, GenEvent::momentum_unit(), Units::name(), GenEvent::run_info(), Writer::run_info(), Writer::set_run_info(), GenPdfInfo::to_string(), VectorLongIntAttribute::value(), GenEvent::vertices(), GenEvent::weights(), WriterAsciiHepMC2::write_particle(), WriterAsciiHepMC2::write_string(), and WriterAsciiHepMC2::write_vertex().
|
private |
Write particle.
Helper routine for writing single particle to file
Definition at line 376 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::flush(), WriterAsciiHepMC2::m_cursor, WriterAsciiHepMC2::m_float_printf_specifier, WriterAsciiHepMC2::m_particle_counter, VectorIntAttribute::value(), and WriterAsciiHepMC2::write_string().
void write_run_info | ( | ) |
Write the GenRunInfo object to file.
Definition at line 374 of file WriterAsciiHepMC2.cc.
|
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.
|
private |
Write vertex.
Helper routine for writing single vertex to file
Definition at line 307 of file WriterAsciiHepMC2.cc.
References WriterAsciiHepMC2::flush(), FourVector::is_zero(), WriterAsciiHepMC2::m_cursor, WriterAsciiHepMC2::m_float_printf_specifier, FourVector::t(), VectorDoubleAttribute::value(), FourVector::x(), FourVector::y(), and FourVector::z().
|
private |
Stream buffer.
Definition at line 125 of file WriterAsciiHepMC2.h.
|
private |
Buffer size.
Definition at line 127 of file WriterAsciiHepMC2.h.
|
private |
Cursor inside stream buffer.
Definition at line 126 of file WriterAsciiHepMC2.h.
|
private |
Output file.
Definition at line 121 of file WriterAsciiHepMC2.h.
|
private |
the specifier of printf used for floats
Definition at line 129 of file WriterAsciiHepMC2.h.
|
protectedinherited |
|
private |
Used to set bar codes.
Definition at line 128 of file WriterAsciiHepMC2.h.
|
private |
Output precision.
Definition at line 124 of file WriterAsciiHepMC2.h.
|
privateinherited |
The global GenRunInfo object.
|
private |
Output temp. stream.
Definition at line 122 of file WriterAsciiHepMC2.h.
|
private |
Output stream.
Definition at line 123 of file WriterAsciiHepMC2.h.