HepMC3 event record library: ReaderAscii Class Reference

HepMC3 event record library

Public Member Functions | Protected Attributes | Static Private Member Functions | Private Attributes
ReaderAscii Class Reference

## Detailed Description

GenEvent I/O parsing for structured text files.

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

Definition at line 31 of file ReaderAscii.h.

`#include <ReaderAscii.h>`

Inheritance diagram for ReaderAscii:
[legend]
Collaboration diagram for ReaderAscii:
[legend]

## Public Member Functions
| ReaderAscii (const std::string &filename)
| Constructor.
| ReaderAscii (std::istream &)
| The ctor to read from stream.
| ReaderAscii (std::shared_ptr< std::istream > s_stream)
| The ctor to read from stream. Useful for temp. streams.
| ~ReaderAscii ()
| Destructor.
bool | skip (const int) override
| skip events
bool | read_event (GenEvent &evt) override
| Load event from file.
bool | failed () override
| Return status of the stream.
void | close () override
| Close file stream.
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
| Get options.
virtual void | set_run_info (std::shared_ptr< GenRunInfo > run)
| Set the global GenRunInfo object.

## Protected Attributes
std::map< std::string, std::string > | m_options
| Options.

## Private Member Functions
Read helpers
std::pair< int, int > | parse_event_information (const char *buf)
| Parse event.
bool | parse_weight_values (const char *buf)
| Parse weight value lines.
bool | parse_units (const char *buf)
| Parse units.
bool | parse_pdf_info (const char *buf)
| Parse struct GenPdfInfo information.
bool | parse_heavy_ion (const char *buf)
| Parse struct GenHeavyIon information.
bool | parse_cross_section (const char *buf)
| Parse struct GenCrossSection information.
bool | parse_vertex_information (const char *buf)
| Parse vertex.
bool | parse_particle_information (const char *buf)
| Parse particle.
bool | parse_attribute (const char *buf)
| Parse attribute.
bool | parse_run_attribute (const char *buf)
| Parse run-level attribute.
bool | parse_weight_names (const char *buf)
| Parse run-level weight names.
bool | parse_tool (const char *buf)
| Parse run-level tool information.

## Static Private Member Functions
static std::string | unescape (const std::string &s)
| Unsecape '\' and ' ' characters in string.

## Private Attributes
std::ifstream | m_file
| Input file.
std::shared_ptr< std::istream > | m_shared_stream = nullptr
| For ctor when reading from temp. stream.
std::istream * | m_stream = nullptr
| For ctor when reading from stream.
bool | m_isstream
| toggles usage of m_file or m_stream
std::map< int, std::pair< std::set< int >, std::set< int > > > | m_io_explicit
| Temp storage for sets of incoming/outgoing ids for explicit vertices.
std::unordered_map< int, std::pair< std::set< int >, std::set< int > > > | m_io_implicit
| Temp storage for sets of incoming/outgoing ids for implicit vertices.
std::vector< int > | m_io_implicit_ids
| Temp storage to keep the order of implicit vertices.
std::set< int > | m_io_explicit_ids
| Temp storage to keep the order of explicit vertices.
GenEventData | m_data
| To hold event information.
std::shared_ptr< GenRunInfo > | m_run_info
| The global GenRunInfo object.

## Constructor & Destructor Documentation

## ◆ ReaderAscii() [1/3]

ReaderAscii | ( | const std::string & | filename | ) |

Constructor.

Definition at line 24 of file ReaderAscii.cc.

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

## ◆ ReaderAscii() [2/3]

ReaderAscii | ( | std::istream & | stream | ) |

The ctor to read from stream.

Definition at line 33 of file ReaderAscii.cc.

References m_isstream, m_stream, and Reader::set_run_info().

## ◆ ReaderAscii() [3/3]

ReaderAscii | ( | std::shared_ptr< std::istream > | s_stream | ) |

The ctor to read from stream. Useful for temp. streams.

Definition at line 43 of file ReaderAscii.cc.

References m_isstream, m_shared_stream, m_stream, and Reader::set_run_info().

## ◆ ~ReaderAscii()

~ReaderAscii | ( |  | ) |

Destructor.

Definition at line 52 of file ReaderAscii.cc.

References close(), and m_isstream.

## Member Function Documentation

## ◆ close()

void close | ( |  | ) |
| overridevirtual

Close file stream.

Implements Reader.

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

Definition at line 598 of file ReaderAscii.cc.

References m_file.

## ◆ failed()

bool failed | ( |  | ) |
| overridevirtual

Return status of the stream.

Implements Reader.

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

Definition at line 596 of file ReaderAscii.cc.

References m_file, m_isstream, and m_stream.

## ◆ get_options()

virtual std::map< std::string, std::string > get_options | ( |  | ) | const
| inlinevirtualinherited

Get options.

Reimplemented in ReaderPlugin.

Definition at line 53 of file Reader.h.

References m_options.

## ◆ parse_attribute()

bool parse_attribute | ( | const char * | buf | ) |
| private

Parse attribute.

Helper routine for parsing single attribute information

Parameters

  [in] | buf | Line of text that needs to be parsed

Definition at line 496 of file ReaderAscii.cc.

References m_data, and unescape().

## ◆ parse_cross_section()

bool parse_cross_section | ( | const char * | buf | ) |
| private

Parse struct GenCrossSection information.

Helper routine for parsing cross-section information

Parameters

  [in] | buf | Line of text that needs to be parsed

## ◆ parse_event_information()

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

Parse event.

Helper routine for parsing event information

Parameters

  [in] | buf | Line of text that needs to be parsed

Returns
  vertices count and particles count for verification

Definition at line 285 of file ReaderAscii.cc.

References HEPMC3_DEBUG, m_data, m_io_implicit_ids, FourVector::setT(), FourVector::setX(), FourVector::setY(), and FourVector::setZ().

## ◆ parse_heavy_ion()

bool parse_heavy_ion | ( | const char * | buf | ) |
| private

Parse struct GenHeavyIon information.

Helper routine for parsing heavy ion information

Parameters

  [in] | buf | Line of text that needs to be parsed

## ◆ parse_particle_information()

bool parse_particle_information | ( | const char * | buf | ) |
| private

Parse particle.

Helper routine for parsing single particle information

Parameters

  [in] | buf | Line of text that needs to be parsed

Parent object is a particle, i.e. the vertex is implicit. If the vertex is not known – mark its first appearence.

Definition at line 431 of file ReaderAscii.cc.

References HEPMC3_ERROR_LEVEL, m_data, m_io_explicit, m_io_explicit_ids, m_io_implicit, m_io_implicit_ids, FourVector::setE(), FourVector::setPx(), FourVector::setPy(), and FourVector::setPz().

## ◆ parse_pdf_info()

bool parse_pdf_info | ( | const char * | buf | ) |
| private

Parse struct GenPdfInfo information.

Helper routine for parsing PDF information

Parameters

  [in] | buf | Line of text that needs to be parsed

## ◆ parse_run_attribute()

bool parse_run_attribute | ( | const char * | buf | ) |
| private

Parse run-level attribute.

Helper routine for parsing single attribute information

Parameters

  [in] | buf | Line of text that needs to be parsed

Definition at line 520 of file ReaderAscii.cc.

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

## ◆ parse_tool()

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] | buf | Line of text that needs to be parsed

Definition at line 558 of file ReaderAscii.cc.

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

## ◆ parse_units()

bool parse_units | ( | const char * | buf | ) |
| private

Parse units.

Helper routine for parsing units information

Parameters

  [in] | buf | Line of text that needs to be parsed

Definition at line 353 of file ReaderAscii.cc.

References HEPMC3_DEBUG, Units::length_unit(), m_data, Units::momentum_unit(), and Units::name().

## ◆ parse_vertex_information()

bool parse_vertex_information | ( | const char * | buf | ) |
| private

Parse vertex.

Helper routine for parsing single event information

Parameters

  [in] | buf | Line of text that needs to be parsed

Definition at line 372 of file ReaderAscii.cc.

References m_data, m_io_explicit, FourVector::setT(), FourVector::setX(), FourVector::setY(), and FourVector::setZ().

## ◆ parse_weight_names()

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] | buf | Line of text that needs to be parsed

Definition at line 542 of file ReaderAscii.cc.

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

## ◆ parse_weight_values()

bool parse_weight_values | ( | const char * | buf | ) |
| private

Parse weight value lines.

Helper routine for parsing weight value information

Parameters

  [in] | buf | Line of text that needs to be parsed

Definition at line 336 of file ReaderAscii.cc.

References m_data, and Reader::run_info().

## ◆ read_event()

bool read_event | ( | GenEvent & | evt | ) |
| overridevirtual

Load event from file.

Parameters

  [out] | evt | Event to be filled

Insert the implicit vertices in the gaps of explicit vertices: Find the gaps looping over the explicit vertices

Found a gap in ids, insert an implicit vertex into a list of gaps.

Implements Reader.

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

Definition at line 90 of file ReaderAscii.cc.

References GenEvent::clear(), failed(), HEPMC3_DEBUG, HEPMC3_ERROR_LEVEL, HEPMC3_WARNING_LEVEL, m_data, m_file, m_io_explicit, m_io_explicit_ids, m_io_implicit, m_io_implicit_ids, m_isstream, m_stream, parse_attribute(), parse_event_information(), parse_particle_information(), parse_run_attribute(), parse_tool(), parse_units(), parse_vertex_information(), parse_weight_names(), parse_weight_values(), GenEvent::particles(), GenEvent::read_data(), Reader::run_info(), GenEvent::set_run_info(), Reader::set_run_info(), and GenEvent::vertices().

## ◆ run_info()

virtual std::shared_ptr< GenRunInfo > run_info | ( |  | ) | const
| inlinevirtualinherited

Get the global GenRunInfo object.

Reimplemented in ReaderGZ< T >, and ReaderPlugin.

Examples
  LHEF_example_cat.cc.

Definition at line 44 of file Reader.h.

References m_run_info.

## ◆ set_options()

virtual void set_options | ( | const std::map< std::string, std::string > & | options | ) |
| inlinevirtualinherited

Set options.

Reimplemented in ReaderPlugin.

Definition at line 51 of file Reader.h.

References m_options.

## ◆ set_run_info()

virtual void set_run_info | ( | std::shared_ptr< GenRunInfo > | run | ) |
| inlinevirtualinherited

Set the global GenRunInfo object.

Reimplemented in ReaderGZ< T >, and ReaderPlugin.

Definition at line 56 of file Reader.h.

References m_run_info.

## ◆ skip()

bool skip | ( | const int | n | ) |
| overridevirtual

skip events

Reimplemented from Reader.

Definition at line 54 of file ReaderAscii.cc.

References failed(), m_file, m_isstream, m_stream, parse_run_attribute(), parse_tool(), parse_weight_names(), and Reader::set_run_info().

## ◆ unescape()

std::string unescape | ( | const std::string & | s | ) |
| staticprivate

Unsecape '\' and '
' characters in string.

Definition at line 577 of file ReaderAscii.cc.

## Field Documentation

## ◆ m_data

GenEventData m_data
| private

To hold event information.

Definition at line 161 of file ReaderAscii.h.

## ◆ m_file

std::ifstream m_file
| private

Input file.

Definition at line 147 of file ReaderAscii.h.

## ◆ m_io_explicit

std::map<int, std::pair< std::set<int>, std::set<int> > > m_io_explicit
| private

Temp storage for sets of incoming/outgoing ids for explicit vertices.

Definition at line 153 of file ReaderAscii.h.

## ◆ m_io_explicit_ids

std::set<int> m_io_explicit_ids
| private

Temp storage to keep the order of explicit vertices.

Definition at line 159 of file ReaderAscii.h.

## ◆ m_io_implicit

std::unordered_map<int, std::pair< std::set<int>, std::set<int> > > m_io_implicit
| private

Temp storage for sets of incoming/outgoing ids for implicit vertices.

Definition at line 155 of file ReaderAscii.h.

## ◆ m_io_implicit_ids

std::vector<int> m_io_implicit_ids
| private

Temp storage to keep the order of implicit vertices.

Definition at line 157 of file ReaderAscii.h.

## ◆ m_isstream

bool m_isstream
| private

toggles usage of m_file or m_stream

Definition at line 150 of file ReaderAscii.h.

## ◆ m_options

std::map<std::string, std::string> m_options
| protectedinherited

Options.

Definition at line 60 of file Reader.h.

## ◆ m_run_info

std::shared_ptr<GenRunInfo> m_run_info
| privateinherited

The global GenRunInfo object.

Definition at line 63 of file Reader.h.

## ◆ m_shared_stream

std::shared_ptr<std::istream> m_shared_stream = nullptr
| private

For ctor when reading from temp. stream.

Definition at line 148 of file ReaderAscii.h.

## ◆ m_stream

std::istream* m_stream = nullptr
| private

For ctor when reading from stream.

Definition at line 149 of file ReaderAscii.h.

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

- ReaderAscii.h
- ReaderAscii.cc