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 
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 #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 //
48 public:
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 
61 private:
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 //
129 private:
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
HepMC3::ReaderAsciiHepMC2::parse_event_information
int parse_event_information(GenEvent &evt, const char *buf)
Parse event.
Definition: ReaderAsciiHepMC2.cc:296
GenEvent.h
Definition of class GenEvent.
HepMC3::ReaderAsciiHepMC2::parse_xs_info
bool parse_xs_info(GenEvent &evt, const char *buf)
Parse pdf information.
Definition: ReaderAsciiHepMC2.cc:576
HepMC3::ReaderAsciiHepMC2::close
void close() override
Close file stream.
Definition: ReaderAsciiHepMC2.cc:718
HepMC3::ReaderAsciiHepMC2::m_vertex_cache
std::vector< GenVertexPtr > m_vertex_cache
Vertex cache.
Definition: ReaderAsciiHepMC2.h:134
HepMC3::ReaderAsciiHepMC2::parse_units
bool parse_units(GenEvent &evt, const char *buf)
Parse units.
Definition: ReaderAsciiHepMC2.cc:385
HepMC3::ReaderAsciiHepMC2::skip
bool skip(const int) override
skip events
Definition: ReaderAsciiHepMC2.cc:44
HepMC3::ReaderAsciiHepMC2::failed
bool failed() override
Return status of the stream.
Definition: ReaderAsciiHepMC2.cc:716
HepMC3::ReaderAsciiHepMC2::m_particle_cache
std::vector< GenParticlePtr > m_particle_cache
Particle cache.
Definition: ReaderAsciiHepMC2.h:137
HepMC3::GenEvent
Stores event-related information.
Definition: GenEvent.h:41
HepMC3
HepMC3 main namespace.
Definition: AnalysisExample.h:19
HepMC3::ReaderAsciiHepMC2::m_event_ghost
GenEvent * m_event_ghost
To save particle and verstex attributes.
Definition: ReaderAsciiHepMC2.h:140
HepMC3::ReaderAsciiHepMC2::~ReaderAsciiHepMC2
~ReaderAsciiHepMC2()
Destructor.
Definition: ReaderAsciiHepMC2.cc:42
HepMC3::ReaderAsciiHepMC2::m_stream
std::istream * m_stream
For ctor when reading from stdin.
Definition: ReaderAsciiHepMC2.h:131
HepMC3::ReaderAsciiHepMC2::m_vertex_barcodes
std::vector< int > m_vertex_barcodes
Old vertex barcodes.
Definition: ReaderAsciiHepMC2.h:135
HepMC3::ReaderAsciiHepMC2::parse_heavy_ion
bool parse_heavy_ion(GenEvent &evt, const char *buf)
Parse heavy ion information.
Definition: ReaderAsciiHepMC2.cc:626
HepMC3::Reader
Base class for all I/O readers.
Definition: Reader.h:25
HepMC3::ReaderAsciiHepMC2::parse_vertex_information
int parse_vertex_information(const char *buf)
Parse vertex.
Definition: ReaderAsciiHepMC2.cc:405
HepMC3::ReaderAsciiHepMC2::m_end_vertex_barcodes
std::vector< int > m_end_vertex_barcodes
Old end vertex barcodes.
Definition: ReaderAsciiHepMC2.h:138
HepMC3::ReaderAsciiHepMC2::ReaderAsciiHepMC2
ReaderAsciiHepMC2(const std::string &filename)
Default constructor.
Definition: ReaderAsciiHepMC2.cc:23
HepMC3::ReaderAsciiHepMC2::parse_particle_information
int parse_particle_information(const char *buf)
Parse particle.
Definition: ReaderAsciiHepMC2.cc:481
HepMC3::ReaderAsciiHepMC2::m_isstream
bool m_isstream
toggles usage of m_file or m_stream
Definition: ReaderAsciiHepMC2.h:132
HepMC3::ReaderAsciiHepMC2::parse_weight_names
bool parse_weight_names(const char *buf)
Parse weight names.
Definition: ReaderAsciiHepMC2.cc:592
HepMC3::ReaderAsciiHepMC2
Parser for HepMC2 I/O files.
Definition: ReaderAsciiHepMC2.h:30
HepMC3::ReaderAsciiHepMC2::m_file
std::ifstream m_file
Input file.
Definition: ReaderAsciiHepMC2.h:130
HepMC3::ReaderAsciiHepMC2::m_particle_cache_ghost
std::vector< GenParticlePtr > m_particle_cache_ghost
Particle cache for attributes.
Definition: ReaderAsciiHepMC2.h:141
HepMC3::ReaderAsciiHepMC2::m_vertex_cache_ghost
std::vector< GenVertexPtr > m_vertex_cache_ghost
Vertex cache for attributes.
Definition: ReaderAsciiHepMC2.h:142
HepMC3::ReaderAsciiHepMC2::parse_pdf_info
bool parse_pdf_info(GenEvent &evt, const char *buf)
Parse pdf information.
Definition: ReaderAsciiHepMC2.cc:677
Reader.h
Definition of interface Reader.
HepMC3::ReaderAsciiHepMC2::read_event
bool read_event(GenEvent &evt) override
Implementation of Reader::read_event.
Definition: ReaderAsciiHepMC2.cc:60