HepMC3 event record library: ReaderAsciiHepMC2.h Source File

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-2023 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
30 class 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
45 ~ReaderAsciiHepMC2();
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 static 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 static 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 static 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 static 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 = nullptr; ///< For ctor when reading from temp stream
133 std::istream* m_stream = nullptr; ///< 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 = nullptr; //!< 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
GenEvent.h
Definition of class GenEvent.
Reader.h
Definition of interface Reader.
HepMC3::GenEvent
Stores event-related information.
Definition GenEvent.h:47
HepMC3::ReaderAsciiHepMC2::m_isstream
bool m_isstream
toggles usage of m_file or m_stream
Definition ReaderAsciiHepMC2.h:134
HepMC3::ReaderAsciiHepMC2::read_event
bool read_event(GenEvent &evt) override
Implementation of Reader::read_event.
Definition ReaderAsciiHepMC2.cc:72
HepMC3::ReaderAsciiHepMC2::parse_event_information
static int parse_event_information(GenEvent &evt, const char *buf)
Parse event.
Definition ReaderAsciiHepMC2.cc:343
HepMC3::ReaderAsciiHepMC2::m_vertex_barcodes
std::vector< int > m_vertex_barcodes
Old vertex barcodes.
Definition ReaderAsciiHepMC2.h:137
HepMC3::ReaderAsciiHepMC2::failed
bool failed() override
Return status of the stream.
Definition ReaderAsciiHepMC2.cc:747
HepMC3::ReaderAsciiHepMC2::parse_pdf_info
static bool parse_pdf_info(GenEvent &evt, const char *buf)
Parse pdf information.
Definition ReaderAsciiHepMC2.cc:708
HepMC3::ReaderAsciiHepMC2::skip
bool skip(const int) override
skip events
Definition ReaderAsciiHepMC2.cc:57
HepMC3::ReaderAsciiHepMC2::m_file
std::ifstream m_file
Input file.
Definition ReaderAsciiHepMC2.h:131
HepMC3::ReaderAsciiHepMC2::parse_units
static bool parse_units(GenEvent &evt, const char *buf)
Parse units.
Definition ReaderAsciiHepMC2.cc:424
HepMC3::ReaderAsciiHepMC2::parse_particle_information
int parse_particle_information(const char *buf)
Parse particle.
Definition ReaderAsciiHepMC2.cc:511
HepMC3::ReaderAsciiHepMC2::m_particle_cache_ghost
std::vector< GenParticlePtr > m_particle_cache_ghost
Particle cache for attributes.
Definition ReaderAsciiHepMC2.h:143
HepMC3::ReaderAsciiHepMC2::close
void close() override
Close file stream.
Definition ReaderAsciiHepMC2.cc:749
HepMC3::ReaderAsciiHepMC2::m_vertex_cache
std::vector< GenVertexPtr > m_vertex_cache
Vertex cache.
Definition ReaderAsciiHepMC2.h:136
HepMC3::ReaderAsciiHepMC2::ReaderAsciiHepMC2
ReaderAsciiHepMC2(const std::string &filename)
Default constructor.
Definition ReaderAsciiHepMC2.cc:25
HepMC3::ReaderAsciiHepMC2::m_particle_cache
std::vector< GenParticlePtr > m_particle_cache
Particle cache.
Definition ReaderAsciiHepMC2.h:139
HepMC3::ReaderAsciiHepMC2::parse_weight_names
bool parse_weight_names(const char *buf)
Parse weight names.
Definition ReaderAsciiHepMC2.cc:623
HepMC3::ReaderAsciiHepMC2::parse_xs_info
bool parse_xs_info(GenEvent &evt, const char *buf)
Parse pdf information.
Definition ReaderAsciiHepMC2.cc:603
HepMC3::ReaderAsciiHepMC2::m_stream
std::istream * m_stream
For ctor when reading from stream.
Definition ReaderAsciiHepMC2.h:133
HepMC3::ReaderAsciiHepMC2::m_shared_stream
std::shared_ptr< std::istream > m_shared_stream
For ctor when reading from temp stream.
Definition ReaderAsciiHepMC2.h:132
HepMC3::ReaderAsciiHepMC2::m_vertex_cache_ghost
std::vector< GenVertexPtr > m_vertex_cache_ghost
Vertex cache for attributes.
Definition ReaderAsciiHepMC2.h:144
HepMC3::ReaderAsciiHepMC2::~ReaderAsciiHepMC2
~ReaderAsciiHepMC2()
Destructor.
Definition ReaderAsciiHepMC2.cc:55
HepMC3::ReaderAsciiHepMC2::parse_vertex_information
int parse_vertex_information(const char *buf)
Parse vertex.
Definition ReaderAsciiHepMC2.cc:444
HepMC3::ReaderAsciiHepMC2::parse_heavy_ion
static bool parse_heavy_ion(GenEvent &evt, const char *buf)
Parse heavy ion information.
Definition ReaderAsciiHepMC2.cc:657
HepMC3::ReaderAsciiHepMC2::m_event_ghost
GenEvent * m_event_ghost
To save particle and verstex attributes.
Definition ReaderAsciiHepMC2.h:142
HepMC3::ReaderAsciiHepMC2::m_end_vertex_barcodes
std::vector< int > m_end_vertex_barcodes
Old end vertex barcodes.
Definition ReaderAsciiHepMC2.h:140
HepMC3::Reader::Reader
Reader()
Constructor.
Definition Reader.h:28
HepMC3
HepMC3 main namespace.
Definition AnalysisExample.h:24