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-2021 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 /// The ctor to read from stream
39 ReaderAsciiHepMC2(std::istream &);
40
41 /// The ctor to read from temp stream
42 ReaderAsciiHepMC2(std::shared_ptr<std::istream> s_stream);
43
44 /// @brief Destructor
46//
47// Functions
48//
49
50 /// @brief skip events
51 bool skip(const int) override;
52
53 /** @brief Implementation of Reader::read_event */
54 bool read_event(GenEvent &evt) override;
55
56 /// @brief Return status of the stream
57 bool failed() override;
58
59 /// @brief Close file stream
60 void close() override;
61
62private:
63 /** @brief Parse event
64 *
65 * Helper routine for parsing event information
66 * @param[out] evt Event that will be filled with new data
67 * @param[in] buf Line of text that needs to be parsed
68 */
69 int parse_event_information(GenEvent &evt, const char *buf);
70
71 /** @brief Parse units
72 *
73 * Helper routine for parsing unit information
74 * @param[out] evt Event that will be filled with unit information
75 * @param[in] buf Line of text that needs to be parsed
76 */
77 bool parse_units(GenEvent &evt, const char *buf);
78
79 /** @brief Parse vertex
80 *
81 * Helper routine for parsing single event information
82 * @param[in] buf Line of text that needs to be parsed
83 */
84 int parse_vertex_information(const char *buf);
85
86 /** @brief Parse particle
87 *
88 * Helper routine for parsing single particle information
89 * @param[in] buf Line of text that needs to be parsed
90 */
91 int parse_particle_information(const char *buf);
92
93 /** @brief Parse weight names
94 *
95 * Helper routine for parsing weight names
96 * @param[in] buf Line of text that needs to be parsed
97 */
98 bool parse_weight_names(const char *buf);
99
100 /** @brief Parse heavy ion information
101 *
102 * Helper routine for parsing heavy ion information
103 * @param[out] evt Event that will be filled with new data
104 * @param[in] buf Line of text that needs to be parsed
105 */
106 bool parse_heavy_ion(GenEvent &evt, const char *buf);
107
108 /** @brief Parse pdf information
109 *
110 * Helper routine for parsing pdf information
111 * @param[out] evt Event that will be filled with new data
112 * @param[in] buf Line of text that needs to be parsed
113 */
114 bool parse_pdf_info(GenEvent &evt, const char *buf);
115
116
117 /** @brief Parse pdf information
118 *
119 * Helper routine for parsing cross-section information
120 * @param[out] evt Event that will be filled with new data
121 * @param[in] buf Line of text that needs to be parsed
122 */
123 bool parse_xs_info(GenEvent &evt, const char *buf);
124
125
126
127//
128// Fields
129//
130private:
131 std::ifstream m_file; //!< Input file
132 std::shared_ptr<std::istream> m_shared_stream; ///< For ctor when reading from temp stream
133 std::istream* m_stream; ///< For ctor when reading from stream
134 bool m_isstream; ///< toggles usage of m_file or m_stream
135
136 std::vector<GenVertexPtr> m_vertex_cache; //!< Vertex cache
137 std::vector<int> m_vertex_barcodes; //!< Old vertex barcodes
138
139 std::vector<GenParticlePtr> m_particle_cache; //!< Particle cache
140 std::vector<int> m_end_vertex_barcodes; //!< Old end vertex barcodes
141
142 GenEvent* m_event_ghost; //!< To save particle and verstex attributes.
143 std::vector<GenParticlePtr> m_particle_cache_ghost;//!< Particle cache for attributes
144 std::vector<GenVertexPtr> m_vertex_cache_ghost; //!< Vertex cache for attributes
145};
146
147} // namespace HepMC3
148
149#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.
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 stream.
std::shared_ptr< std::istream > m_shared_stream
For ctor when reading from temp stream.
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.