|
||||
File indexing completed on 2025-01-18 10:01:10
0001 //-------------------------------------------------------------------------- 0002 #ifndef HEPMC_IO_GENEVENT_H 0003 #define HEPMC_IO_GENEVENT_H 0004 0005 ////////////////////////////////////////////////////////////////////////// 0006 // garren@fnal.gov, July 2007 0007 // with input from Gavin Salam, salam@lpthe.jussieu.fr 0008 // 0009 // event input/output in ascii format for machine reading 0010 // This class persists all information found in a GenEvent 0011 ////////////////////////////////////////////////////////////////////////// 0012 0013 #include <fstream> 0014 #include <string> 0015 #include <map> 0016 #include <vector> 0017 #include "HepMC/IO_BaseClass.h" 0018 #include "HepMC/IO_Exception.h" 0019 #include "HepMC/Units.h" 0020 0021 namespace HepMC { 0022 0023 class GenEvent; 0024 class GenVertex; 0025 class GenParticle; 0026 class HeavyIon; 0027 class PdfInfo; 0028 0029 //! IO_GenEvent also deals with HeavyIon and PdfInfo 0030 0031 /// 0032 /// \class IO_GenEvent 0033 /// event input/output in ascii format for machine reading 0034 /// extended format contains HeavyIon and PdfInfo classes 0035 /// 0036 /// Strategy for reading or writing events using iostreams 0037 /// When instantiating with a file name, the mode of file to be created 0038 /// must be specified. Options are: 0039 /// std::ios::in open file for input 0040 /// std::ios::out open file for output 0041 /// std::ios::trunc erase old file when opening (i.e. ios::out|ios::trunc 0042 /// removes oldfile, and creates a new one for output ) 0043 /// std::ios::app append output to end of file 0044 /// for the purposes of this class, simultaneous input and output mode 0045 /// ( std::ios::in | std::ios::out ) is not allowed. 0046 /// 0047 /// Event listings are preceded by the key: 0048 /// "HepMC::IO_GenEvent-START_EVENT_LISTING\n" 0049 /// and terminated by the key: 0050 /// "HepMC::IO_GenEvent-END_EVENT_LISTING\n" 0051 /// GenParticle Data tables are preceded by the key: 0052 /// "HepMC::IO_GenEvent-START_PARTICLE_DATA\n" 0053 /// and terminated by the key: 0054 /// "HepMC::IO_GenEvent-END_PARTICLE_DATA\n" 0055 /// Comments are allowed. They need not be preceded by anything, though if 0056 /// a comment is written using write_comment( const string ) then it will be 0057 /// preceded by "HepMC::IO_GenEvent-COMMENT\n" 0058 /// Each event, vertex, particle, particle data, heavy ion, or pdf info line 0059 /// is preceded by "E ","V ","P ","D ","H ","F " respectively. 0060 /// Comments may appear anywhere in the file -- so long as they do not contain 0061 /// any of the start/stop keys. 0062 /// 0063 class IO_GenEvent : public IO_BaseClass { 0064 public: 0065 /// constructor requiring a file name and std::ios mode 0066 IO_GenEvent( const std::string& filename="IO_GenEvent.dat", 0067 std::ios::openmode mode=std::ios::out ); 0068 /// constructor requiring an input stream 0069 IO_GenEvent( std::istream & ); 0070 /// constructor requiring an output stream 0071 IO_GenEvent( std::ostream & ); 0072 virtual ~IO_GenEvent(); 0073 0074 /// write this event 0075 void write_event( const GenEvent* evt ); 0076 /// get the next event 0077 bool fill_next_event( GenEvent* evt ); 0078 /// insert a comment directly into the output file --- normally you 0079 /// only want to do this at the beginning or end of the file. All 0080 /// comments are preceded with "HepMC::IO_GenEvent-COMMENT\n" 0081 void write_comment( const std::string comment ); 0082 0083 int rdstate() const; //!< check the state of the IO stream 0084 void clear(); //!< clear the IO stream 0085 0086 /// write to ostr 0087 void print( std::ostream& ostr = std::cout ) const; 0088 0089 /// needed when reading a file without units if those units are 0090 /// different than the declared default units 0091 /// (e.g., the default units are MeV, but the file was written with GeV) 0092 /// This method is not necessary if the units are written in the file 0093 void use_input_units( Units::MomentumUnit, Units::LengthUnit ); 0094 0095 /// set output precision 0096 /// The default precision is 16. 0097 void precision( int ); 0098 0099 /// integer (enum) associated with read error 0100 int error_type() const; 0101 /// the read error message string 0102 const std::string & error_message() const; 0103 0104 private: // use of copy constructor is not allowed 0105 IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {} 0106 0107 private: // data members 0108 std::ios::openmode m_mode; 0109 std::fstream m_file; 0110 std::ostream * m_ostr; 0111 std::istream * m_istr; 0112 std::ios * m_iostr; 0113 bool m_have_file; 0114 IO_Exception::ErrorType m_error_type; 0115 std::string m_error_message; 0116 0117 }; 0118 0119 ////////////// 0120 // Inlines // 0121 ////////////// 0122 0123 inline int IO_GenEvent::rdstate() const { 0124 int state; 0125 if( m_istr ) { 0126 state = (int)m_istr->rdstate(); 0127 } else { 0128 state = (int)m_ostr->rdstate(); 0129 } 0130 return state; 0131 } 0132 0133 inline void IO_GenEvent::clear() { 0134 if( m_istr ) { 0135 m_istr->clear(); 0136 } else { 0137 m_ostr->clear(); 0138 } 0139 } 0140 0141 inline int IO_GenEvent::error_type() const { 0142 return m_error_type; 0143 } 0144 0145 inline const std::string & IO_GenEvent::error_message() const { 0146 return m_error_message; 0147 } 0148 0149 } // HepMC 0150 0151 #endif // HEPMC_IO_GENEVENT_H 0152 //--------------------------------------------------------------------------
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |