|
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, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >()) | |
| Constructor. | |
| WriterAsciiHepMC2 (std::ostream &stream, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >()) | |
| Constructor from ostream. | |
| ~WriterAsciiHepMC2 () | |
| Destructor. | |
| void | write_event (const GenEvent &evt) |
| Write event to file. | |
| void | write_run_info () |
| Write the GenRunInfo object to file. | |
| bool | failed () |
| Return status of the stream. | |
| void | close () |
| Close file stream. | |
| void | set_precision (const int &prec) |
| Set output precision. | |
| int | precision () const |
| Return output precision. | |
| void | set_run_info (shared_ptr< GenRunInfo > run) |
| Set the global GenRunInfo object. | |
| shared_ptr< GenRunInfo > | run_info () const |
| Get the global GenRunInfo object. | |
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. | |
Private Attributes | |
| shared_ptr< GenRunInfo > | m_run_info |
| The global GenRunInfo object. | |
Write helpers | |
| std::ofstream | m_file |
| Output file. | |
| 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. | |
| 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. | |
| WriterAsciiHepMC2 | ( | const std::string & | filename, |
| shared_ptr< GenRunInfo > | run = shared_ptr<GenRunInfo>() ) |
Constructor.
Definition at line 23 of file WriterAsciiHepMC2.cc.
References ERROR, m_buffer, m_buffer_size, m_cursor, m_file, m_particle_counter, m_precision, m_stream, Writer::run_info(), Writer::set_run_info(), HepMC3::version(), and WARNING.
| WriterAsciiHepMC2 | ( | std::ostream & | stream, |
| shared_ptr< GenRunInfo > | run = shared_ptr<GenRunInfo>() ) |
Constructor from ostream.
Definition at line 46 of file WriterAsciiHepMC2.cc.
References m_buffer, m_buffer_size, m_cursor, m_file, m_particle_counter, m_precision, m_stream, Writer::run_info(), Writer::set_run_info(), HepMC3::version(), and WARNING.
| ~WriterAsciiHepMC2 | ( | ) |
|
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 216 of file WriterAsciiHepMC2.cc.
References ERROR, m_buffer, m_buffer_size, m_cursor, and WARNING.
|
virtual |
Close file stream.
Implements Writer.
Definition at line 399 of file WriterAsciiHepMC2.cc.
References forced_flush(), and m_stream.
|
private |
Escape '\' and '
' characters in string.
Definition at line 239 of file WriterAsciiHepMC2.cc.
|
virtual |
Return status of the stream.
Implements Writer.
Definition at line 407 of file WriterAsciiHepMC2.cc.
References m_file.
|
inlineprivate |
Inline function flushing buffer to output stream when close to buffer capacity.
Definition at line 305 of file WriterAsciiHepMC2.cc.
References m_buffer, m_buffer_size, m_cursor, and m_stream.
|
inlineprivate |
Inline function forcing flush to the output stream.
Definition at line 319 of file WriterAsciiHepMC2.cc.
| int precision | ( | ) | const |
Return output precision.
Definition at line 414 of file WriterAsciiHepMC2.cc.
References m_precision.
|
inlineinherited |
|
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 418 of file WriterAsciiHepMC2.cc.
References m_buffer, and m_buffer_size.
| void set_precision | ( | const int & | prec | ) |
Set output precision.
Available range is [2,24]. Default is 16.
Definition at line 409 of file WriterAsciiHepMC2.cc.
References m_precision.
|
inlineinherited |
|
virtual |
Write event to file.
| [in] | evt | Event to be serialized |
Implements Writer.
Definition at line 70 of file WriterAsciiHepMC2.cc.
References allocate_buffer(), GenEvent::attribute(), GenEvent::attributes(), escape(), GenEvent::event_number(), flush(), forced_flush(), GenEvent::length_unit(), m_buffer, m_cursor, m_particle_counter, m_precision, GenEvent::momentum_unit(), Units::name(), GenEvent::run_info(), Writer::run_info(), Writer::set_run_info(), GenEvent::vertices(), WARNING, GenEvent::weights(), write_particle(), write_string(), and write_vertex().
|
private |
Write particle.
Helper routine for writing single particle to file
Definition at line 329 of file WriterAsciiHepMC2.cc.
References flush(), m_cursor, m_particle_counter, and m_precision.
| void write_run_info | ( | ) |
Write the GenRunInfo object to file.
Definition at line 327 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 378 of file WriterAsciiHepMC2.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 260 of file WriterAsciiHepMC2.cc.
References flush(), FourVector::is_zero(), m_cursor, m_precision, FourVector::t(), FourVector::x(), FourVector::y(), and FourVector::z().
|
private |
Stream buffer.
Definition at line 121 of file WriterAsciiHepMC2.h.
|
private |
Buffer size.
Definition at line 123 of file WriterAsciiHepMC2.h.
|
private |
Cursor inside stream buffer.
Definition at line 122 of file WriterAsciiHepMC2.h.
|
private |
Output file.
Definition at line 118 of file WriterAsciiHepMC2.h.
|
private |
Used to set bar codes.
Definition at line 124 of file WriterAsciiHepMC2.h.
|
private |
Output precision.
Definition at line 120 of file WriterAsciiHepMC2.h.
|
privateinherited |
The global GenRunInfo object.
|
private |
Output stream.
Definition at line 119 of file WriterAsciiHepMC2.h.