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_WRITERHEPEVT_H
0007 #define HEPMC3_WRITERHEPEVT_H
0008 /**
0009  *  @file  WriterHEPEVT.h
0010  *  @brief Definition of \b class WriterHEPEVT
0011  *
0012  *  @class HepMC3::WriterHEPEVT
0013  *  @brief GenEvent I/O serialization for HEPEVT files
0014  *
0015  *
0016  *  @ingroup IO
0017  *
0018  */
0019 #include <fstream>
0020 #include "HepMC3/Writer.h"
0021 #include "HepMC3/GenEvent.h"
0022 #include "HepMC3/Data/GenEventData.h"
0023 #include "HepMC3/HEPEVT_Wrapper_Template.h"
0024 namespace HepMC3
0025 {
0026 
0027 class WriterHEPEVT : public Writer
0028 {
0029 //
0030 // Constructors
0031 //
0032 public:
0033     /** @brief Default constructor
0034      *  @warning If file exists, it will be overwritten
0035      */
0036     WriterHEPEVT(const std::string &filename,
0037                  std::shared_ptr<GenRunInfo> run = nullptr);
0038 
0039     /// @brief Constructor from ostream
0040     WriterHEPEVT(std::ostream& stream,
0041                  std::shared_ptr<GenRunInfo> run = nullptr);
0042     /// @brief Constructor from temp ostream
0043     WriterHEPEVT(std::shared_ptr<std::ostream> s_stream,
0044                  std::shared_ptr<GenRunInfo> run = nullptr);
0045 //
0046 // Functions
0047 //
0048 public:
0049 
0050     /** @brief Write particle to file
0051      *
0052      *  @param[in] index Particle to be serialized
0053      *  @param[in] iflong Format of record
0054      */
0055 
0056     virtual void write_hepevt_particle( int index, bool iflong = true );
0057     /** @brief Write event header to file
0058      *
0059      */
0060     virtual void write_hepevt_event_header();
0061 
0062     /** @brief Write event to file
0063      *
0064      *  @param[in] evt Event to be serialized
0065      */
0066     void write_event(const GenEvent &evt)  override;
0067 
0068     /** @brief Close file stream */
0069     void close()  override;
0070 
0071     /** @brief Get stream error state flag */
0072     bool failed()  override;
0073     /** @brief  set flag if vertex positions are available.
0074      *  Effectively this adds or removes key "vertices_positions_are_absent"
0075      *  to/from the m_options.*/
0076     void set_vertices_positions_present(bool iflong);
0077 
0078     /** @brief  get flag if vertex positions are available.
0079      * The flag is deduced from m_options. If the m_options have the key
0080      * "vertices_positions_are_absent" the result if false. True otherwise. */
0081     bool get_vertices_positions_present() const;
0082 
0083 protected:
0084     std::ofstream m_file; //!< Output file
0085     std::shared_ptr<std::ostream> m_shared_stream;///< Output temp. stream
0086     std::ostream* m_stream; //!< Output stream
0087     char* hepevtbuffer = nullptr;   //!< Pointer to HEPEVT Fortran common block/C struct
0088     int   m_events_count = 0; //!< Events count. Needed to generate unique object name
0089     HEPEVT_Wrapper_Template<100000> m_hepevt_interface; //!< Templated HEPEVT interface
0090 };
0091 
0092 } // namespace HepMC3
0093 #endif