HepMC3 event record library
ReaderAsciiHepMC2.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of HepMC
4// Copyright (C) 2014-2019 The HepMC collaboration (see AUTHORS for details)
5//
6#ifndef HEPMC3_READER_ASCII_HEPMC2_H
7#define HEPMC3_READER_ASCII_HEPMC2_H
8/**
9 * @file ReaderAsciiHepMC2.h
10 * @brief Definition of \b class ReaderAsciiHepMC2
11 *
12 * @class HepMC3::ReaderAsciiHepMC2
13 * @brief Parser for HepMC2 I/O files
14 *
15 * @ingroup IO
16 *
17 */
18#include "HepMC3/Reader.h"
19
20#include "HepMC3/GenEvent.h"
21
22#include <string>
23#include <fstream>
24#include <istream>
25
26namespace HepMC3 {
27
28
29
30class ReaderAsciiHepMC2 : public Reader {
31//
32// Constructors
33//
34public:
35 /** @brief Default constructor */
36 ReaderAsciiHepMC2(const std::string& filename);
37
38#ifndef HEPMC3_PYTHON_BINDINGS
39 /// The ctor to read from stdin
40 ReaderAsciiHepMC2(std::istream &);
41#endif
42
43 /// @brief Destructor
45//
46// Functions
47//
48public:
49 /// @brief skip events
50 bool skip(const int) override;
51
52 /** @brief Implementation of Reader::read_event */
53 bool read_event(GenEvent &evt) override;
54
55 /// @brief Return status of the stream
56 bool failed() override;
57
58 /// @brief Close file stream
59 void close() override;
60
61private:
62 /** @brief Parse event
63 *
64 * Helper routine for parsing event information
65 * @param[out] evt Event that will be filled with new data
66 * @param[in] buf Line of text that needs to be parsed
67 */
68 int parse_event_information(GenEvent &evt, const char *buf);
69
70 /** @brief Parse units
71 *
72 * Helper routine for parsing unit information
73 * @param[out] evt Event that will be filled with unit information
74 * @param[in] buf Line of text that needs to be parsed
75 */
76 bool parse_units(GenEvent &evt, const char *buf);
77
78 /** @brief Parse vertex
79 *
80 * Helper routine for parsing single event information
81 * @param[in] buf Line of text that needs to be parsed
82 */
83 int parse_vertex_information(const char *buf);
84
85 /** @brief Parse particle
86 *
87 * Helper routine for parsing single particle information
88 * @param[in] buf Line of text that needs to be parsed
89 */
90 int parse_particle_information(const char *buf);
91
92 /** @brief Parse weight names
93 *
94 * Helper routine for parsing weight names
95 * @param[in] buf Line of text that needs to be parsed
96 */
97 bool parse_weight_names(const char *buf);
98
99 /** @brief Parse heavy ion information
100 *
101 * Helper routine for parsing heavy ion information
102 * @param[out] evt Event that will be filled with new data
103 * @param[in] buf Line of text that needs to be parsed
104 */
105 bool parse_heavy_ion(GenEvent &evt, const char *buf);
106
107 /** @brief Parse pdf information
108 *
109 * Helper routine for parsing pdf information
110 * @param[out] evt Event that will be filled with new data
111 * @param[in] buf Line of text that needs to be parsed
112 */
113 bool parse_pdf_info(GenEvent &evt, const char *buf);
114
115
116 /** @brief Parse pdf information
117 *
118 * Helper routine for parsing cross-section information
119 * @param[out] evt Event that will be filled with new data
120 * @param[in] buf Line of text that needs to be parsed
121 */
122 bool parse_xs_info(GenEvent &evt, const char *buf);
123
124
125
126//
127// Fields
128//
129private:
130 std::ifstream m_file; //!< Input file
131 std::istream* m_stream; ///< For ctor when reading from stdin
132 bool m_isstream; ///< toggles usage of m_file or m_stream
133
134 std::vector<GenVertexPtr> m_vertex_cache; //!< Vertex cache
135 std::vector<int> m_vertex_barcodes; //!< Old vertex barcodes
136
137 std::vector<GenParticlePtr> m_particle_cache; //!< Particle cache
138 std::vector<int> m_end_vertex_barcodes; //!< Old end vertex barcodes
139
140 GenEvent* m_event_ghost; //!< To save particle and verstex attributes.
141 std::vector<GenParticlePtr> m_particle_cache_ghost;//!< Particle cache for attributes
142 std::vector<GenVertexPtr> m_vertex_cache_ghost; //!< Vertex cache for attributes
143};
144
145} // namespace HepMC3
146
147#endif
Definition of class GenEvent.
Definition of interface Reader.
Stores event-related information.
Definition: GenEvent.h:41
Parser for HepMC2 I/O files.
bool m_isstream
toggles usage of m_file or m_stream
bool read_event(GenEvent &evt) override
Implementation of Reader::read_event.
int parse_event_information(GenEvent &evt, const char *buf)
Parse event.
std::vector< int > m_vertex_barcodes
Old vertex barcodes.
bool failed() override
Return status of the stream.
bool parse_pdf_info(GenEvent &evt, const char *buf)
Parse pdf information.
bool skip(const int) override
skip events
std::ifstream m_file
Input file.
bool parse_units(GenEvent &evt, const char *buf)
Parse units.
int parse_particle_information(const char *buf)
Parse particle.
std::vector< GenParticlePtr > m_particle_cache_ghost
Particle cache for attributes.
void close() override
Close file stream.
std::vector< GenVertexPtr > m_vertex_cache
Vertex cache.
ReaderAsciiHepMC2(const std::string &filename)
Default constructor.
std::vector< GenParticlePtr > m_particle_cache
Particle cache.
bool parse_weight_names(const char *buf)
Parse weight names.
bool parse_xs_info(GenEvent &evt, const char *buf)
Parse pdf information.
std::istream * m_stream
For ctor when reading from stdin.
std::vector< GenVertexPtr > m_vertex_cache_ghost
Vertex cache for attributes.
int parse_vertex_information(const char *buf)
Parse vertex.
bool parse_heavy_ion(GenEvent &evt, const char *buf)
Parse heavy ion information.
GenEvent * m_event_ghost
To save particle and verstex attributes.
std::vector< int > m_end_vertex_barcodes
Old end vertex barcodes.
Base class for all I/O readers.
Definition: Reader.h:25
HepMC3 main namespace.