|
||||
File indexing completed on 2025-01-18 10:01:10
0001 //-------------------------------------------------------------------------- 0002 #ifndef HEPMC_IO_ASCIIPARTICLES_H 0003 #define HEPMC_IO_ASCIIPARTICLES_H 0004 0005 ////////////////////////////////////////////////////////////////////////// 0006 // Mikhail.Kirsanov@Cern.CH, 2006 0007 // event input/output in ascii format for eye and machine reading 0008 ////////////////////////////////////////////////////////////////////////// 0009 // 0010 // Strategy for reading or writing events as machine readable 0011 // ascii to a file. When instantiating, the mode of file to be created 0012 // must be specified. Options are: 0013 // std::ios::in open file for input 0014 // std::ios::out open file for output 0015 // std::ios::trunc erase old file when opening (i.e. ios::out|ios::trunc 0016 // removes oldfile, and creates a new one for output ) 0017 // std::ios::app append output to end of file 0018 // for the purposes of this class, simultaneous input and output mode 0019 // ( std::ios::in | std::ios::out ) is not allowed. 0020 // 0021 // Event listings are preceded by the key: 0022 // "HepMC::IO_AsciiParticles-START_EVENT_LISTING\n" 0023 // and terminated by the key: 0024 // "HepMC::IO_AsciiParticles-END_EVENT_LISTING\n" 0025 // Comments are allowed. They need not be preceded by anything, though if 0026 // a comment is written using write_comment( const string ) then it will be 0027 // preceded by "HepMC::IO_AsciiParticles-COMMENT\n" 0028 // Each event, vertex, particle, particle data is preceded by 0029 // "E ","V ","P ","D " respectively. 0030 // Comments may appear anywhere in the file -- so long as they do not contain 0031 // any of the 4 start/stop keys. 0032 // 0033 0034 #include <fstream> 0035 #include <string> 0036 #include <map> 0037 #include <vector> 0038 #include "HepMC/IO_BaseClass.h" 0039 0040 namespace HepMC { 0041 0042 class GenEvent; 0043 class GenVertex; 0044 class GenParticle; 0045 0046 //! event input/output in ascii format for eye and machine reading 0047 0048 /// 0049 /// \class IO_AsciiParticles 0050 /// Strategy for reading or writing events as machine readable 0051 /// ascii to a file. When instantiating, the mode of file to be created 0052 /// must be specified. 0053 /// 0054 class IO_AsciiParticles : public IO_BaseClass { 0055 public: 0056 /// constructor requiring a file name and std::ios mode 0057 IO_AsciiParticles( const char* filename="IO_AsciiParticles.dat", 0058 std::ios::openmode mode=std::ios::out ); 0059 virtual ~IO_AsciiParticles(); 0060 0061 /// write this event 0062 void write_event( const GenEvent* evt ); 0063 /// get the next event 0064 bool fill_next_event( GenEvent* evt ); 0065 /// insert a comment directly into the output file --- normally you 0066 /// only want to do this at the beginning or end of the file. All 0067 /// comments are preceded with "HepMC::IO_AsciiParticles-COMMENT\n" 0068 void write_comment( const std::string comment ); 0069 0070 /// set output precision 0071 void setPrecision(int iprec); 0072 0073 int rdstate() const; //!< check the state of the IO stream 0074 void clear(); //!< clear the IO stream 0075 0076 /// write to ostr 0077 void print( std::ostream& ostr = std::cout ) const; 0078 0079 protected: // for internal use only 0080 /// write end tag 0081 bool write_end_listing(); 0082 private: // use of copy constructor is not allowed 0083 IO_AsciiParticles( const IO_AsciiParticles& ) : IO_BaseClass() {} 0084 private: // data members 0085 int m_precision; 0086 std::ios::openmode m_mode; 0087 std::fstream* m_file; 0088 std::ostream* m_outstream; 0089 bool m_finished_first_event_io; 0090 }; 0091 0092 ////////////// 0093 // Inlines // 0094 ////////////// 0095 0096 inline int IO_AsciiParticles::rdstate() const { return (int)m_file->rdstate(); } 0097 inline void IO_AsciiParticles::clear() { m_file->clear(); } 0098 inline void IO_AsciiParticles::setPrecision(int iprec) { m_precision=iprec; } 0099 0100 } // HepMC 0101 0102 #endif // HEPMC_IO_ASCIIPARTICLES_H 0103 //--------------------------------------------------------------------------
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |