| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

IO_ExtendedAscii.h

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 #ifndef HEPMC_IO_EXTENDEDASCII_H
00003 #define HEPMC_IO_EXTENDEDASCII_H
00004 
00006 // garren@fnal.gov, July 2006
00007 //
00008 // event input/output in ascii format for machine reading
00009 // extended format contains HeavyIon and PdfInfo classes
00011 //
00012 // Strategy for reading or writing events as machine readable
00013 //  ascii to a file. When instantiating, the mode of file to be created 
00014 //  must be specified. Options are:
00015 //      std::ios::in     open file for input 
00016 //      std::ios::out    open file for output
00017 //      std::ios::trunc  erase old file when opening (i.e. ios::out|ios::trunc
00018 //                    removes oldfile, and creates a new one for output )
00019 //      std::ios::app    append output to end of file
00020 //  for the purposes of this class, simultaneous input and output mode 
00021 //  ( std::ios::in | std::ios::out ) is not allowed.
00022 // 
00023 // Event listings are preceded by the key:
00024 //  "HepMC::IO_ExtendedAscii-START_EVENT_LISTING\n"
00025 //  and terminated by the key:
00026 //  "HepMC::IO_ExtendedAscii-END_EVENT_LISTING\n"
00027 // GenParticle Data tables are preceded by the key:
00028 //  "HepMC::IO_ExtendedAscii-START_PARTICLE_DATA\n"
00029 //  and terminated by the key:
00030 //  "HepMC::IO_ExtendedAscii-END_PARTICLE_DATA\n"
00031 // Comments are allowed. They need not be preceded by anything, though if
00032 //  a comment is written using write_comment( const string ) then it will be
00033 //  preceded by "HepMC::IO_ExtendedAscii-COMMENT\n"
00034 // Each event, vertex, particle, particle data, heavy ion, or pdf info line
00035 //  is preceded by   "E ","V ","P ","D ","H ","F "    respectively.
00036 // ExtendedAscii ignores particle data blocks
00037 // Comments may appear anywhere in the file -- so long as they do not contain
00038 //  any of the start/stop keys.
00039 //
00040 
00041 #include <fstream>
00042 #include <string>
00043 #include <map>
00044 #include <vector>
00045 #include "HepMC/IO_BaseClass.h"
00046 #include "HepMC/TempParticleMap.h"
00047 #include "HepMC/CommonIO.h"
00048 
00049 namespace HepMC {
00050 
00051     class GenEvent;
00052     class GenVertex;
00053     class GenParticle;
00054     class ParticleData;
00055     class HeavyIon;
00056     class PdfInfo;
00057 
00059 
00065     class IO_ExtendedAscii : public IO_BaseClass {
00066     public:
00068         IO_ExtendedAscii( const char* filename="IO_ExtendedAscii.dat", 
00069                   std::ios::openmode mode=std::ios::out );
00070         virtual       ~IO_ExtendedAscii();
00071 
00073         void          write_event( const GenEvent* evt );
00075         bool          fill_next_event( GenEvent* evt );
00076         void          write_particle_data_table(const ParticleDataTable*);
00077         bool          fill_particle_data_table( ParticleDataTable* );
00081         void          write_comment( const std::string comment );
00082 
00083         int           rdstate() const;  
00084         void          clear();  
00085 
00087         void          print( std::ostream& ostr = std::cout ) const;
00088 
00089     protected: // for internal use only
00091         void          write_vertex( GenVertex* );
00093         void          write_beam_particles( std::pair<HepMC::GenParticle *,HepMC::GenParticle *> );
00095         void          write_heavy_ion( HeavyIon const * );
00097         void          write_pdf_info( PdfInfo const * );
00099         void          write_particle( GenParticle* p );
00101         void          write_particle_data( const ParticleData* d );
00103         bool          write_end_listing();
00104 
00105         void          output( const double& );  
00106         void          output( const float& );  
00107         void          output( const int& ); 
00108         void          output( const long int& ); 
00109         void          output( const char& );  
00110     private: // use of copy constructor is not allowed
00111         IO_ExtendedAscii( const IO_ExtendedAscii& ) : IO_BaseClass() {}
00112     private: // data members
00113         std::ios::openmode  m_mode;
00114         std::fstream        m_file;
00115         bool                m_finished_first_event_io;
00116         CommonIO            m_common_io;
00117     };
00118 
00120     // Inlines  //
00122 
00123     inline void IO_ExtendedAscii::output( const double& d ) {
00124         if ( d == 0. ) {
00125             m_file << ' ' << (int)0;
00126         } else {
00127             m_file << ' ' << d;
00128         }
00129     }
00130     inline void IO_ExtendedAscii::output( const float& d ) {
00131         if ( d == 0. ) {
00132             m_file << ' ' << (int)0;
00133         } else {
00134             m_file << ' ' << d;
00135         }
00136     }
00137     inline void IO_ExtendedAscii::output( const int& i ) { m_file << ' ' << i; }
00138     inline void IO_ExtendedAscii::output( const long int& i ) { m_file << ' ' << i; }
00139     inline void IO_ExtendedAscii::output( const char& c ) { m_file << c; }
00140     inline int  IO_ExtendedAscii::rdstate() const { return (int)m_file.rdstate(); }
00141     inline void IO_ExtendedAscii::clear() { m_file.clear(); }
00142 
00143 } // HepMC
00144 
00145 #endif  // HEPMC_IO_EXTENDEDASCII_H
00146 //--------------------------------------------------------------------------
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:56:42 2011 for HepMC by doxygen 1.4.7