00001 //-------------------------------------------------------------------------- 00002 #ifndef HEPMC_IO_GENEVENT_H 00003 #define HEPMC_IO_GENEVENT_H 00004 00006 // garren@fnal.gov, July 2007 00007 // with input from Gavin Salam, salam@lpthe.jussieu.fr 00008 // 00009 // event input/output in ascii format for machine reading 00010 // This class persists all information found in a GenEvent 00012 00013 #include <fstream> 00014 #include <string> 00015 #include <map> 00016 #include <vector> 00017 #include "HepMC/IO_BaseClass.h" 00018 #include "HepMC/TempParticleMap.h" 00019 #include "HepMC/CommonIO.h" 00020 00021 namespace HepMC { 00022 00023 class GenEvent; 00024 class GenVertex; 00025 class GenParticle; 00026 class ParticleData; 00027 class HeavyIon; 00028 class PdfInfo; 00029 00031 00065 class IO_GenEvent : public IO_BaseClass { 00066 public: 00068 IO_GenEvent( const char* filename="IO_GenEvent.dat", 00069 std::ios::openmode mode=std::ios::out ); 00071 IO_GenEvent( std::istream & ); 00073 IO_GenEvent( std::ostream & ); 00074 virtual ~IO_GenEvent(); 00075 00077 void write_event( const GenEvent* evt ); 00079 bool fill_next_event( GenEvent* evt ); 00080 void write_particle_data_table(const ParticleDataTable*); 00081 bool fill_particle_data_table( ParticleDataTable* ); 00085 void write_comment( const std::string comment ); 00086 00087 int rdstate() const; 00088 void clear(); 00089 00091 void print( std::ostream& ostr = std::cout ) const; 00092 00093 protected: // for internal use only 00095 void write_vertex( GenVertex* ); 00097 void write_beam_particles( std::pair<HepMC::GenParticle *,HepMC::GenParticle *> ); 00099 void write_heavy_ion( HeavyIon const * ); 00101 void write_pdf_info( PdfInfo const * ); 00103 void write_particle( GenParticle* p ); 00105 void write_particle_data( const ParticleData* d ); 00107 GenVertex* read_vertex( TempParticleMap& particle_to_end_vertex ); 00109 GenParticle* read_particle( TempParticleMap& particle_to_end_vertex ); 00111 ParticleData* read_particle_data( ParticleDataTable* ); 00113 HeavyIon* read_heavy_ion( ); 00115 PdfInfo* read_pdf_info( ); 00117 bool write_end_listing(); 00118 00119 void output( const double& ); 00120 void output( const float& ); 00121 void output( const int& ); 00122 void output( const long& ); 00123 void output( const char& ); 00124 private: // use of copy constructor is not allowed 00125 IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {} 00126 private: // data members 00127 std::ios::openmode m_mode; 00128 std::fstream m_file; 00129 std::ostream * m_ostr; 00130 std::istream * m_istr; 00131 std::ios * m_iostr; 00132 bool m_finished_first_event_io; 00133 bool m_have_file; 00134 CommonIO m_common_io; 00135 }; 00136 00138 // Inlines // 00140 00141 inline void IO_GenEvent::output( const double& d ) { 00142 if( m_ostr ) { 00143 if ( d == 0. ) { 00144 *m_ostr << ' ' << (int)0; 00145 } else { 00146 *m_ostr << ' ' << d; 00147 } 00148 } 00149 } 00150 inline void IO_GenEvent::output( const float& d ) { 00151 if( m_ostr ) { 00152 if ( d == 0. ) { 00153 *m_ostr << ' ' << (int)0; 00154 } else { 00155 *m_ostr << ' ' << d; 00156 } 00157 } 00158 } 00159 inline void IO_GenEvent::output( const int& i ) { 00160 if( m_ostr ) { 00161 if ( i == 0. ) { 00162 *m_ostr << ' ' << (int)0; 00163 } else { 00164 *m_ostr << ' ' << i; 00165 } 00166 } 00167 } 00168 inline void IO_GenEvent::output( const long& i ) { 00169 if( m_ostr ) { 00170 if ( i == 0. ) { 00171 *m_ostr << ' ' << (int)0; 00172 } else { 00173 *m_ostr << ' ' << i; 00174 } 00175 } 00176 } 00177 inline void IO_GenEvent::output( const char& c ) { 00178 if( m_ostr ) { 00179 if ( c ) { 00180 *m_ostr << c; 00181 } else { 00182 *m_ostr << ' ' ; 00183 } 00184 } 00185 } 00186 inline int IO_GenEvent::rdstate() const { 00187 int state; 00188 if( m_istr ) { 00189 state = (int)m_istr->rdstate(); 00190 } else { 00191 state = (int)m_ostr->rdstate(); 00192 } 00193 return state; 00194 } 00195 inline void IO_GenEvent::clear() { 00196 if( m_istr ) { 00197 m_istr->clear(); 00198 } else { 00199 m_ostr->clear(); 00200 } 00201 } 00202 // these are required by IO_BaseClass, but not used here 00203 inline void IO_GenEvent::write_particle_data_table(const ParticleDataTable*) {;} 00204 inline bool IO_GenEvent::fill_particle_data_table( ParticleDataTable* ) 00205 { return false;} 00206 00207 } // HepMC 00208 00209 #endif // HEPMC_IO_GENEVENT_H 00210 //--------------------------------------------------------------------------