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 
26 namespace HepMC3 {
27 
28 
29 
30 class ReaderAsciiHepMC2 : public Reader {
31 //
32 // Constructors
33 //
34 public:
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 
62 private:
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 //
130 private:
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
std::ifstream m_file
Input file.
Definition of interface Reader.
bool m_isstream
toggles usage of m_file or m_stream
std::vector< GenParticlePtr > m_particle_cache_ghost
Particle cache for attributes.
int parse_particle_information(const char *buf)
Parse particle.
bool failed() override
Return status of the stream.
GenEvent * m_event_ghost
To save particle and verstex attributes.
bool parse_xs_info(GenEvent &evt, const char *buf)
Parse pdf information.
void close() override
Close file stream.
Parser for HepMC2 I/O files.
ReaderAsciiHepMC2(const std::string &filename)
Default constructor.
Stores event-related information.
Definition: GenEvent.h:41
bool parse_weight_names(const char *buf)
Parse weight names.
std::vector< int > m_end_vertex_barcodes
Old end vertex barcodes.
std::shared_ptr< std::istream > m_shared_stream
For ctor when reading from temp stream.
std::istream * m_stream
For ctor when reading from stream.
std::vector< GenVertexPtr > m_vertex_cache_ghost
Vertex cache for attributes.
Definition of class GenEvent.
bool read_event(GenEvent &evt) override
Implementation of Reader::read_event.
Base class for all I/O readers.
Definition: Reader.h:25
std::vector< int > m_vertex_barcodes
Old vertex barcodes.
std::vector< GenVertexPtr > m_vertex_cache
Vertex cache.
std::vector< GenParticlePtr > m_particle_cache
Particle cache.
int parse_event_information(GenEvent &evt, const char *buf)
Parse event.
bool parse_units(GenEvent &evt, const char *buf)
Parse units.
bool parse_heavy_ion(GenEvent &evt, const char *buf)
Parse heavy ion information.
bool parse_pdf_info(GenEvent &evt, const char *buf)
Parse pdf information.
int parse_vertex_information(const char *buf)
Parse vertex.
bool skip(const int) override
skip events