HepMC event record
Public Member Functions | Private Attributes
WriterAscii Class Reference

Detailed Description

GenEvent I/O serialization for structured text files.

Examples:
class_example_read.cc, HepMC2_reader_example.cc, HepMC3_fileIO_example.cc, LHEF_example_cat.cc, pythia8_example.cc, and rootIO_example_read.cc.

Definition at line 25 of file build/outputs/include/HepMC/WriterAscii.h.

#include <WriterAscii.h>

+ Inheritance diagram for WriterAscii:
+ Collaboration diagram for WriterAscii:

Public Member Functions

 WriterAscii (const std::string &filename, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >())
 Constructor. More...
 
 WriterAscii (std::ostream &stream, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >())
 Constructor from ostream. More...
 
 ~WriterAscii ()
 Destructor. More...
 
void write_event (const GenEvent &evt)
 Write event to file. More...
 
void write_run_info ()
 Write the GenRunInfo object to file. More...
 
bool failed ()
 Return status of the stream. More...
 
void close ()
 Close file stream. More...
 
void set_precision (size_t prec)
 Set output precision. More...
 
 WriterAscii (const std::string &filename, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >())
 Constructor. More...
 
 WriterAscii (std::ostream &stream, shared_ptr< GenRunInfo > run=shared_ptr< GenRunInfo >())
 Constructor from ostream. More...
 
 ~WriterAscii ()
 Destructor. More...
 
void write_event (const GenEvent &evt)
 Write event to file. More...
 
void write_run_info ()
 Write the GenRunInfo object to file. More...
 
bool failed ()
 Return status of the stream. More...
 
void close ()
 Close file stream. More...
 
void set_precision (size_t prec)
 Set output precision. More...
 
void set_run_info (shared_ptr< GenRunInfo > run)
 Set the global GenRunInfo object. More...
 
void set_run_info (shared_ptr< GenRunInfo > run)
 Set the global GenRunInfo object. More...
 
shared_ptr< GenRunInforun_info () const
 Get the global GenRunInfo object. More...
 
shared_ptr< GenRunInforun_info () const
 Get the global GenRunInfo object. More...
 

Private Member Functions

Buffer management
void allocate_buffer ()
 Attempts to allocate buffer of the chosen size. More...
 
void set_buffer_size (size_t size)
 Set buffer size (in bytes) More...
 
std::string escape (const std::string s)
 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...
 
void allocate_buffer ()
 Attempts to allocate buffer of the chosen size. More...
 
void set_buffer_size (size_t size)
 Set buffer size (in bytes) More...
 
std::string escape (const std::string s)
 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 (const GenVertexPtr &v)
 Write vertex. More...
 
void write_particle (const GenParticlePtr &p, int second_field)
 Write particle. More...
 
void write_string (const std::string &str)
 Inline function for writing strings. More...
 
void write_vertex (const GenVertexPtr &v)
 Write vertex. More...
 
void write_particle (const GenParticlePtr &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...
 

Constructor & Destructor Documentation

◆ WriterAscii() [1/4]

WriterAscii ( const std::string &  filename,
shared_ptr< GenRunInfo run = shared_ptr<GenRunInfo>() 
)

Constructor.

Warning
If file already exists, it will be cleared before writing

Definition at line 22 of file WriterAscii.cc.

References WriterAscii::m_file, Writer::run_info(), Writer::set_run_info(), HepMC::version(), and WriterAscii::write_run_info().

◆ WriterAscii() [2/4]

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

Constructor from ostream.

Definition at line 41 of file WriterAscii.cc.

References Writer::run_info(), Writer::set_run_info(), HepMC::version(), and WriterAscii::write_run_info().

◆ ~WriterAscii() [1/2]

Destructor.

Definition at line 62 of file WriterAscii.cc.

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

◆ WriterAscii() [3/4]

WriterAscii ( const std::string &  filename,
shared_ptr< GenRunInfo run = shared_ptr< GenRunInfo >() 
)

Constructor.

Warning
If file already exists, it will be cleared before writing

◆ WriterAscii() [4/4]

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

Constructor from ostream.

◆ ~WriterAscii() [2/2]

Destructor.

Member Function Documentation

◆ allocate_buffer() [1/2]

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 177 of file WriterAscii.cc.

References WriterAscii::m_buffer, WriterAscii::m_buffer_size, and WriterAscii::m_cursor.

◆ allocate_buffer() [2/2]

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

◆ close() [1/2]

void close ( )
virtual

Close file stream.

Implements Writer.

◆ close() [2/2]

void close ( )
virtual

◆ escape() [1/2]

string escape ( const std::string  s)
private

Escape '\' and '
' characters in string.

Definition at line 196 of file WriterAscii.cc.

◆ escape() [2/2]

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

Escape '\' and '
' characters in string.

◆ failed() [1/2]

bool failed ( )
inlinevirtual

Return status of the stream.

Implements Writer.

Definition at line 49 of file build/outputs/include/HepMC/WriterAscii.h.

References WriterAscii::m_file.

◆ failed() [2/2]

bool failed ( )
inlinevirtual

Return status of the stream.

Implements Writer.

Definition at line 49 of file include/HepMC/WriterAscii.h.

References WriterAscii::m_file.

◆ flush() [1/2]

void flush ( )
inlineprivate

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

Definition at line 245 of file WriterAscii.cc.

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

◆ flush() [2/2]

void flush ( )
private

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

◆ forced_flush() [1/2]

void forced_flush ( )
inlineprivate

Inline function forcing flush to the output stream.

Definition at line 258 of file WriterAscii.cc.

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

◆ forced_flush() [2/2]

void forced_flush ( )
private

Inline function forcing flush to the output stream.

◆ run_info() [1/2]

shared_ptr<GenRunInfo> run_info ( ) const
inlineinherited

Get the global GenRunInfo object.

Definition at line 42 of file build/outputs/include/HepMC/Writer.h.

References Writer::m_run_info.

◆ run_info() [2/2]

shared_ptr<GenRunInfo> run_info ( ) const
inlineinherited

Get the global GenRunInfo object.

Definition at line 42 of file include/HepMC/Writer.h.

References Writer::m_run_info.

◆ set_buffer_size() [1/2]

void set_buffer_size ( size_t  size)
inlineprivate

Set buffer size (in bytes)

Default is 256kb. Minimum is 256b. Size can only be changed before first read/write operation.

Definition at line 80 of file include/HepMC/WriterAscii.h.

References WriterAscii::m_buffer, and WriterAscii::m_buffer_size.

◆ set_buffer_size() [2/2]

void set_buffer_size ( size_t  size)
inlineprivate

Set buffer size (in bytes)

Default is 256kb. Minimum is 256b. Size can only be changed before first read/write operation.

Definition at line 80 of file build/outputs/include/HepMC/WriterAscii.h.

References WriterAscii::m_buffer, and WriterAscii::m_buffer_size.

◆ set_precision() [1/2]

void set_precision ( size_t  prec)
inline

Set output precision.

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

Definition at line 57 of file include/HepMC/WriterAscii.h.

References WriterAscii::m_precision.

◆ set_precision() [2/2]

void set_precision ( size_t  prec)
inline

Set output precision.

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

Definition at line 57 of file build/outputs/include/HepMC/WriterAscii.h.

References WriterAscii::m_precision.

◆ set_run_info() [1/2]

void set_run_info ( shared_ptr< GenRunInfo run)
inlineinherited

Set the global GenRunInfo object.

Definition at line 37 of file include/HepMC/Writer.h.

References Writer::m_run_info.

◆ set_run_info() [2/2]

void set_run_info ( shared_ptr< GenRunInfo run)
inlineinherited

Set the global GenRunInfo object.

Definition at line 37 of file build/outputs/include/HepMC/Writer.h.

References Writer::m_run_info.

◆ write_event() [1/2]

void write_event ( const GenEvent evt)
virtual

◆ write_event() [2/2]

void write_event ( const GenEvent evt)
virtual

Write event to file.

Parameters
[in]evtEvent to be serialized

Implements Writer.

◆ write_particle() [1/2]

void write_particle ( const GenParticlePtr p,
int  second_field 
)
private

Write particle.

Helper routine for writing single particle to file

◆ write_particle() [2/2]

void write_particle ( const GenParticlePtr p,
int  second_field 
)
private

Write particle.

Helper routine for writing single particle to file

Definition at line 309 of file WriterAscii.cc.

References WriterAscii::flush(), WriterAscii::m_cursor, and WriterAscii::m_precision.

◆ write_run_info() [1/2]

void write_run_info ( )

◆ write_run_info() [2/2]

void write_run_info ( )

Write the GenRunInfo object to file.

◆ write_string() [1/2]

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 333 of file WriterAscii.cc.

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

◆ write_string() [2/2]

void write_string ( const std::string &  str)
private

Inline function for writing strings.

Since strings can be long (maybe even longer than buffer) they have to be dealt with separately.

◆ write_vertex() [1/2]

void write_vertex ( const GenVertexPtr v)
private

Write vertex.

Helper routine for writing single vertex to file

Definition at line 209 of file WriterAscii.cc.

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

◆ write_vertex() [2/2]

void write_vertex ( const GenVertexPtr v)
private

Write vertex.

Helper routine for writing single vertex to file

Field Documentation

◆ m_buffer

char * m_buffer
private

Stream buffer.

Definition at line 124 of file build/outputs/include/HepMC/WriterAscii.h.

◆ m_buffer_size

unsigned long m_buffer_size
private

Buffer size.

Definition at line 126 of file build/outputs/include/HepMC/WriterAscii.h.

◆ m_cursor

char * m_cursor
private

Cursor inside stream buffer.

Definition at line 125 of file build/outputs/include/HepMC/WriterAscii.h.

◆ m_file

std::ofstream m_file
private

Output file.

Definition at line 121 of file build/outputs/include/HepMC/WriterAscii.h.

◆ m_precision

int m_precision
private

Output precision.

Definition at line 123 of file build/outputs/include/HepMC/WriterAscii.h.

◆ m_stream

std::ostream * m_stream
private

Output stream.

Definition at line 122 of file build/outputs/include/HepMC/WriterAscii.h.


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