HepMC event record
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
ReaderAscii Class Reference

Detailed Description

GenEvent I/O parsing for structured text files.

Examples:
class_example_write.cc, HepMC3_fileIO_example.cc, LHEF_example_cat.cc, and rootIO_example_write.cc.

Definition at line 26 of file build/outputs/include/HepMC/ReaderAscii.h.

#include <ReaderAscii.h>

+ Inheritance diagram for ReaderAscii:
+ Collaboration diagram for ReaderAscii:

Public Member Functions

 ReaderAscii (const std::string &filename)
 Constructor. More...
 
 ReaderAscii (std::istream &)
 The ctor to read from stdin. More...
 
 ~ReaderAscii ()
 Destructor. More...
 
bool read_event (GenEvent &evt)
 Load event from file. More...
 
bool failed ()
 Return status of the stream. More...
 
void close ()
 Close file stream. More...
 
 ReaderAscii (const std::string &filename)
 Constructor. More...
 
 ReaderAscii (std::istream &)
 The ctor to read from stdin. More...
 
 ~ReaderAscii ()
 Destructor. More...
 
bool read_event (GenEvent &evt)
 Load event from file. More...
 
bool failed ()
 Return status of the stream. More...
 
void close ()
 Close file stream. More...
 
shared_ptr< GenRunInforun_info () const
 Get the global GenRunInfo object. More...
 
shared_ptr< GenRunInforun_info () const
 Get the global GenRunInfo object. More...
 

Protected Member Functions

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...
 

Private Member Functions

shared_ptr< Attributeget_global (std::string name)
 Get global attribute. More...
 
std::string unescape (const std::string s)
 Unsecape '\' and '
' characters in string. More...
 
shared_ptr< Attributeget_global (std::string name)
 Get global attribute. More...
 
std::string unescape (const std::string s)
 Unsecape '\' and '
' characters in string. More...
 
Read helpers
std::pair< int, int > parse_event_information (GenEvent &evt, const char *buf)
 Parse event. More...
 
bool parse_weight_values (GenEvent &evt, const char *buf)
 Parse weight value lines. More...
 
bool parse_units (GenEvent &evt, const char *buf)
 Parse units. More...
 
bool parse_pdf_info (GenEvent &evt, const char *buf)
 Parse struct GenPdfInfo information. More...
 
bool parse_heavy_ion (GenEvent &evt, const char *buf)
 Parse struct GenHeavyIon information. More...
 
bool parse_cross_section (GenEvent &evt, const char *buf)
 Parse struct GenCrossSection information. More...
 
bool parse_vertex_information (GenEvent &evt, const char *buf)
 Parse vertex. More...
 
bool parse_particle_information (GenEvent &evt, const char *buf)
 Parse particle. More...
 
bool parse_attribute (GenEvent &evt, const char *buf)
 Parse attribute. More...
 
bool parse_run_attribute (const char *buf)
 Parse run-level attribute. More...
 
bool parse_weight_names (const char *buf)
 Parse run-level weight names. More...
 
bool parse_tool (const char *buf)
 Parse run-level tool information. More...
 
std::pair< int, int > parse_event_information (GenEvent &evt, const char *buf)
 Parse event. More...
 
bool parse_weight_values (GenEvent &evt, const char *buf)
 Parse weight value lines. More...
 
bool parse_units (GenEvent &evt, const char *buf)
 Parse units. More...
 
bool parse_pdf_info (GenEvent &evt, const char *buf)
 Parse struct GenPdfInfo information. More...
 
bool parse_heavy_ion (GenEvent &evt, const char *buf)
 Parse struct GenHeavyIon information. More...
 
bool parse_cross_section (GenEvent &evt, const char *buf)
 Parse struct GenCrossSection information. More...
 
bool parse_vertex_information (GenEvent &evt, const char *buf)
 Parse vertex. More...
 
bool parse_particle_information (GenEvent &evt, const char *buf)
 Parse particle. More...
 
bool parse_attribute (GenEvent &evt, const char *buf)
 Parse attribute. More...
 
bool parse_run_attribute (const char *buf)
 Parse run-level attribute. More...
 
bool parse_weight_names (const char *buf)
 Parse run-level weight names. More...
 
bool parse_tool (const char *buf)
 Parse run-level tool information. More...
 

Private Attributes

std::ifstream m_file
 Input file. More...
 
std::istream * m_stream
 
bool m_isstream
 
std::map< std::string, shared_ptr< Attribute > > m_global_attributes
 Store attributes global to the run being written/read. More...
 

Constructor & Destructor Documentation

◆ ReaderAscii() [1/4]

ReaderAscii ( const std::string &  filename)

Constructor.

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

Definition at line 22 of file ReaderAscii.cc.

References ReaderAscii::m_file, and Reader::set_run_info().

◆ ReaderAscii() [2/4]

ReaderAscii ( std::istream &  stream)

The ctor to read from stdin.

Definition at line 33 of file ReaderAscii.cc.

References Reader::set_run_info().

◆ ~ReaderAscii() [1/2]

Destructor.

Definition at line 44 of file ReaderAscii.cc.

References ReaderAscii::close().

◆ ReaderAscii() [3/4]

ReaderAscii ( const std::string &  filename)

Constructor.

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

◆ ReaderAscii() [4/4]

ReaderAscii ( std::istream &  )

The ctor to read from stdin.

◆ ~ReaderAscii() [2/2]

Destructor.

Member Function Documentation

◆ close() [1/2]

void close ( )
virtual

Close file stream.

Implements Reader.

Examples:
class_example_write.cc, HepMC3_fileIO_example.cc, and rootIO_example_write.cc.

Definition at line 484 of file ReaderAscii.cc.

References ReaderAscii::m_file.

◆ close() [2/2]

void close ( )
virtual

Close file stream.

Implements Reader.

◆ failed() [1/2]

bool failed ( )
inlinevirtual

Return status of the stream.

Implements Reader.

Definition at line 45 of file include/HepMC/ReaderAscii.h.

References ReaderAscii::m_file.

◆ failed() [2/2]

bool failed ( )
inlinevirtual

Return status of the stream.

Implements Reader.

Examples:
class_example_write.cc, HepMC3_fileIO_example.cc, and rootIO_example_write.cc.

Definition at line 45 of file build/outputs/include/HepMC/ReaderAscii.h.

References ReaderAscii::m_file.

◆ get_global() [1/2]

shared_ptr<Attribute> get_global ( std::string  name)
private

Get global attribute.

Todo:
rewrite global attributes

◆ get_global() [2/2]

shared_ptr<Attribute> get_global ( std::string  name)
private

Get global attribute.

Todo:
rewrite global attributes

◆ parse_attribute() [1/2]

bool parse_attribute ( GenEvent evt,
const char *  buf 
)
private

Parse attribute.

Helper routine for parsing single attribute information

Parameters
[out]evtEvent that will contain parsed attribute
[in]bufLine of text that needs to be parsed

Definition at line 381 of file ReaderAscii.cc.

References GenEvent::add_attribute(), and ReaderAscii::unescape().

◆ parse_attribute() [2/2]

bool parse_attribute ( GenEvent evt,
const char *  buf 
)
private

Parse attribute.

Helper routine for parsing single attribute information

Parameters
[out]evtEvent that will contain parsed attribute
[in]bufLine of text that needs to be parsed

◆ parse_cross_section() [1/2]

bool parse_cross_section ( GenEvent evt,
const char *  buf 
)
private

Parse struct GenCrossSection information.

Helper routine for parsing cross-section information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_cross_section() [2/2]

bool parse_cross_section ( GenEvent evt,
const char *  buf 
)
private

Parse struct GenCrossSection information.

Helper routine for parsing cross-section information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_event_information() [1/2]

std::pair<int,int> parse_event_information ( GenEvent evt,
const char *  buf 
)
private

Parse event.

Helper routine for parsing event information

Parameters
[out]evtEvent that will be filled with new data
[in]bufLine of text that needs to be parsed
Returns
vertices count and particles count for verification

◆ parse_event_information() [2/2]

pair< int, int > parse_event_information ( GenEvent evt,
const char *  buf 
)
private

Parse event.

Helper routine for parsing event information

Parameters
[out]evtEvent that will be filled with new data
[in]bufLine of text that needs to be parsed
Returns
vertices count and particles count for verification

Definition at line 151 of file ReaderAscii.cc.

References GenEvent::set_event_number(), FourVector::setT(), FourVector::setX(), FourVector::setY(), FourVector::setZ(), and GenEvent::shift_position_to().

◆ parse_heavy_ion() [1/2]

bool parse_heavy_ion ( GenEvent evt,
const char *  buf 
)
private

Parse struct GenHeavyIon information.

Helper routine for parsing heavy ion information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_heavy_ion() [2/2]

bool parse_heavy_ion ( GenEvent evt,
const char *  buf 
)
private

Parse struct GenHeavyIon information.

Helper routine for parsing heavy ion information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_particle_information() [1/2]

bool parse_particle_information ( GenEvent evt,
const char *  buf 
)
private

Parse particle.

Helper routine for parsing single particle information

Parameters
[out]evtEvent that will contain parsed particle
[in]bufLine of text that needs to be parsed
Todo:
Should be an exception

Definition at line 306 of file ReaderAscii.cc.

References GenEvent::add_particle(), GenEvent::add_vertex(), GenEvent::particles(), and GenEvent::vertices().

◆ parse_particle_information() [2/2]

bool parse_particle_information ( GenEvent evt,
const char *  buf 
)
private

Parse particle.

Helper routine for parsing single particle information

Parameters
[out]evtEvent that will contain parsed particle
[in]bufLine of text that needs to be parsed

◆ parse_pdf_info() [1/2]

bool parse_pdf_info ( GenEvent evt,
const char *  buf 
)
private

Parse struct GenPdfInfo information.

Helper routine for parsing PDF information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_pdf_info() [2/2]

bool parse_pdf_info ( GenEvent evt,
const char *  buf 
)
private

Parse struct GenPdfInfo information.

Helper routine for parsing PDF information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_run_attribute() [1/2]

bool parse_run_attribute ( const char *  buf)
private

Parse run-level attribute.

Helper routine for parsing single attribute information

Parameters
[in]bufLine of text that needs to be parsed

◆ parse_run_attribute() [2/2]

bool parse_run_attribute ( const char *  buf)
private

Parse run-level attribute.

Helper routine for parsing single attribute information

Parameters
[in]bufLine of text that needs to be parsed

Definition at line 406 of file ReaderAscii.cc.

References Reader::run_info(), and ReaderAscii::unescape().

◆ parse_tool() [1/2]

bool parse_tool ( const char *  buf)
private

Parse run-level tool information.

Helper routine for parsing a line with information about tools being used.

Parameters
[in]bufLine of text that needs to be parsed

Definition at line 446 of file ReaderAscii.cc.

References GenRunInfo::ToolInfo::description, GenRunInfo::ToolInfo::name, Reader::run_info(), ReaderAscii::unescape(), and GenRunInfo::ToolInfo::version.

◆ parse_tool() [2/2]

bool parse_tool ( const char *  buf)
private

Parse run-level tool information.

Helper routine for parsing a line with information about tools being used.

Parameters
[in]bufLine of text that needs to be parsed

◆ parse_units() [1/2]

bool parse_units ( GenEvent evt,
const char *  buf 
)
private

Parse units.

Helper routine for parsing units information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

Definition at line 215 of file ReaderAscii.cc.

References Units::length_unit(), GenEvent::length_unit(), Units::momentum_unit(), GenEvent::momentum_unit(), Units::name(), and GenEvent::set_units().

◆ parse_units() [2/2]

bool parse_units ( GenEvent evt,
const char *  buf 
)
private

Parse units.

Helper routine for parsing units information

Parameters
[out]evtEvent that will be filled with unit information
[in]bufLine of text that needs to be parsed

◆ parse_vertex_information() [1/2]

bool parse_vertex_information ( GenEvent evt,
const char *  buf 
)
private

Parse vertex.

Helper routine for parsing single event information

Parameters
[out]evtEvent that will contain parsed vertex
[in]bufLine of text that needs to be parsed

◆ parse_vertex_information() [2/2]

bool parse_vertex_information ( GenEvent evt,
const char *  buf 
)
private

Parse vertex.

Helper routine for parsing single event information

Parameters
[out]evtEvent that will contain parsed vertex
[in]bufLine of text that needs to be parsed

Definition at line 236 of file ReaderAscii.cc.

References GenEvent::add_vertex(), and GenEvent::particles().

◆ parse_weight_names() [1/2]

bool parse_weight_names ( const char *  buf)
private

Parse run-level weight names.

Helper routine for parsing a line with information about weight names.

Parameters
[in]bufLine of text that needs to be parsed

◆ parse_weight_names() [2/2]

bool parse_weight_names ( const char *  buf)
private

Parse run-level weight names.

Helper routine for parsing a line with information about weight names.

Parameters
[in]bufLine of text that needs to be parsed

Definition at line 429 of file ReaderAscii.cc.

References Reader::run_info(), and ReaderAscii::unescape().

◆ parse_weight_values() [1/2]

bool parse_weight_values ( GenEvent evt,
const char *  buf 
)
private

Parse weight value lines.

Helper routine for parsing weight value information

Parameters
[out]evtEvent whose GenWeights will be filled with weight values
[in]bufLine of text that needs to be parsed

◆ parse_weight_values() [2/2]

bool parse_weight_values ( GenEvent evt,
const char *  buf 
)
private

Parse weight value lines.

Helper routine for parsing weight value information

Parameters
[out]evtEvent whose GenWeights will be filled with weight values
[in]bufLine of text that needs to be parsed

Definition at line 198 of file ReaderAscii.cc.

References Reader::run_info(), and GenEvent::weights().

◆ read_event() [1/2]

bool read_event ( GenEvent evt)
virtual

◆ read_event() [2/2]

bool read_event ( GenEvent evt)
virtual

Load event from file.

Parameters
[out]evtEvent to be filled

Implements Reader.

◆ run_info() [1/2]

shared_ptr<GenRunInfo> run_info ( ) const
inlineinherited

Get the global GenRunInfo object.

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

References Reader::m_run_info.

◆ run_info() [2/2]

shared_ptr<GenRunInfo> run_info ( ) const
inlineinherited

Get the global GenRunInfo object.

Examples:
LHEF_example_cat.cc.

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

References Reader::m_run_info.

◆ set_run_info() [1/2]

void set_run_info ( shared_ptr< GenRunInfo run)
inlineprotectedinherited

Set the global GenRunInfo object.

Definition at line 44 of file include/HepMC/Reader.h.

References Reader::m_run_info.

◆ set_run_info() [2/2]

void set_run_info ( shared_ptr< GenRunInfo run)
inlineprotectedinherited

Set the global GenRunInfo object.

Definition at line 44 of file build/outputs/include/HepMC/Reader.h.

References Reader::m_run_info.

◆ unescape() [1/2]

string unescape ( const std::string  s)
private

Unsecape '\' and '
' characters in string.

Definition at line 466 of file ReaderAscii.cc.

◆ unescape() [2/2]

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

Unsecape '\' and '
' characters in string.

Field Documentation

◆ m_file

std::ifstream m_file
private

Input file.

Todo:
Unify file/stream treatment
Todo:
Unify file/stream treatment

Definition at line 155 of file build/outputs/include/HepMC/ReaderAscii.h.

◆ m_global_attributes

std::map< std::string, shared_ptr< Attribute > > m_global_attributes
private

Store attributes global to the run being written/read.

Definition at line 161 of file build/outputs/include/HepMC/ReaderAscii.h.


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