Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:01:14

0001 // -*- C++ -*-
0002 //
0003 // This file is part of HepMC
0004 // Copyright (C) 2014-2023 The HepMC collaboration (see AUTHORS for details)
0005 //
0006 #ifndef HEPMC3_READER_ASCII_HEPMC2_H
0007 #define HEPMC3_READER_ASCII_HEPMC2_H
0008 /**
0009  *  @file  ReaderAsciiHepMC2.h
0010  *  @brief Definition of \b class ReaderAsciiHepMC2
0011  *
0012  *  @class HepMC3::ReaderAsciiHepMC2
0013  *  @brief Parser for HepMC2 I/O files
0014  *
0015  *  @ingroup IO
0016  *
0017  */
0018 #include "HepMC3/Reader.h"
0019 
0020 #include "HepMC3/GenEvent.h"
0021 
0022 #include <string>
0023 #include <fstream>
0024 #include <istream>
0025 
0026 namespace HepMC3 {
0027 
0028 
0029 
0030 class ReaderAsciiHepMC2 : public Reader {
0031 //
0032 // Constructors
0033 //
0034 public:
0035     /** @brief Default constructor */
0036     ReaderAsciiHepMC2(const std::string& filename);
0037 
0038     /// The ctor to read from stream
0039     ReaderAsciiHepMC2(std::istream &);
0040 
0041     /// The ctor to read from temp stream
0042     ReaderAsciiHepMC2(std::shared_ptr<std::istream> s_stream);
0043 
0044     /// @brief Destructor
0045     ~ReaderAsciiHepMC2();
0046 //
0047 // Functions
0048 //
0049 
0050     /// @brief skip events
0051     bool skip(const int)  override;
0052 
0053     /** @brief Implementation of Reader::read_event */
0054     bool read_event(GenEvent &evt)  override;
0055 
0056     /// @brief Return status of the stream
0057     bool failed()  override;
0058 
0059     /// @brief Close file stream
0060     void close()  override;
0061 
0062 private:
0063     /** @brief Parse event
0064      *
0065      *  Helper routine for parsing event information
0066      *  @param[out] evt Event that will be filled with new data
0067      *  @param[in]  buf Line of text that needs to be parsed
0068      */
0069     static int parse_event_information(GenEvent &evt, const char *buf);
0070 
0071     /** @brief Parse units
0072      *
0073      *  Helper routine for parsing unit information
0074      *  @param[out] evt Event that will be filled with unit information
0075      *  @param[in]  buf Line of text that needs to be parsed
0076      */
0077     static bool parse_units(GenEvent &evt, const char *buf);
0078 
0079     /** @brief Parse vertex
0080      *
0081      *  Helper routine for parsing single event information
0082      *  @param[in] buf Line of text that needs to be parsed
0083      */
0084     int parse_vertex_information(const char *buf);
0085 
0086     /** @brief Parse particle
0087      *
0088      *  Helper routine for parsing single particle information
0089      *  @param[in] buf Line of text that needs to be parsed
0090      */
0091     int parse_particle_information(const char *buf);
0092 
0093     /** @brief Parse weight names
0094      *
0095      *  Helper routine for parsing weight names
0096      *  @param[in] buf Line of text that needs to be parsed
0097      */
0098     bool parse_weight_names(const char *buf);
0099 
0100     /** @brief Parse heavy ion information
0101      *
0102      *  Helper routine for parsing heavy ion information
0103      *  @param[out] evt Event that will be filled with new data
0104      *  @param[in]  buf Line of text that needs to be parsed
0105      */
0106     static bool parse_heavy_ion(GenEvent &evt, const char *buf);
0107 
0108     /** @brief Parse pdf information
0109      *
0110      *  Helper routine for parsing pdf information
0111      *  @param[out] evt Event that will be filled with new data
0112      *  @param[in]  buf Line of text that needs to be parsed
0113      */
0114     static bool parse_pdf_info(GenEvent &evt, const char *buf);
0115 
0116 
0117     /** @brief Parse pdf information
0118     *
0119     *  Helper routine for parsing cross-section information
0120     *  @param[out] evt Event that will be filled with new data
0121     *  @param[in]  buf Line of text that needs to be parsed
0122     */
0123     bool parse_xs_info(GenEvent &evt, const char *buf);
0124 
0125 
0126 
0127 //
0128 // Fields
0129 //
0130 private:
0131     std::ifstream m_file; //!< Input file
0132     std::shared_ptr<std::istream> m_shared_stream = nullptr; ///< For ctor when reading from temp stream
0133     std::istream* m_stream = nullptr; ///< For ctor when reading from stream
0134     bool m_isstream; ///< toggles usage of m_file or m_stream
0135 
0136     std::vector<GenVertexPtr>   m_vertex_cache;        //!< Vertex cache
0137     std::vector<int>            m_vertex_barcodes;     //!< Old vertex barcodes
0138 
0139     std::vector<GenParticlePtr> m_particle_cache;      //!< Particle cache
0140     std::vector<int>            m_end_vertex_barcodes; //!< Old end vertex barcodes
0141 
0142     GenEvent*              m_event_ghost = nullptr;                      //!< To save particle and verstex attributes.
0143     std::vector<GenParticlePtr> m_particle_cache_ghost;//!< Particle cache for attributes
0144     std::vector<GenVertexPtr>   m_vertex_cache_ghost;        //!< Vertex cache for attributes
0145 };
0146 
0147 } // namespace HepMC3
0148 
0149 #endif