HepMC Reference Documentation

HepMC

IO_Ascii.h

Go to the documentation of this file.
00001 //--------------------------------------------------------------------------
00002 #ifndef HEPMC_IO_ASCII_H
00003 #define HEPMC_IO_ASCII_H
00004 
00006 // Matt.Dobbs@Cern.CH, January 2000, refer to:
00007 // M. Dobbs and J.B. Hansen, "The HepMC C++ Monte Carlo Event Record for
00008 // High Energy Physics", Computer Physics Communications (to be published).
00009 //
00010 // event input/output in ascii format for machine reading
00012 //
00013 // Strategy for reading or writing events/particleData as machine readable
00014 //  ascii to a file. When instantiating, the mode of file to be created 
00015 //  must be specified. Options are:
00016 //      std::ios::in     open file for input 
00017 //      std::ios::out    open file for output
00018 //      std::ios::trunc  erase old file when opening (i.e. ios::out|ios::trunc
00019 //                    removes oldfile, and creates a new one for output )
00020 //      std::ios::app    append output to end of file
00021 //  for the purposes of this class, simultaneous input and output mode 
00022 //  ( std::ios::in | std::ios::out ) is not allowed.
00023 // 
00024 // Event listings are preceded by the key:
00025 //  "HepMC::IO_Ascii-START_EVENT_LISTING\n"
00026 //  and terminated by the key:
00027 //  "HepMC::IO_Ascii-END_EVENT_LISTING\n"
00028 // GenParticle Data tables are preceded by the key:
00029 //  "HepMC::IO_Ascii-START_PARTICLE_DATA\n"
00030 //  and terminated by the key:
00031 //  "HepMC::IO_Ascii-END_PARTICLE_DATA\n"
00032 // Comments are allowed. They need not be preceded by anything, though if
00033 //  a comment is written using write_comment( const string ) then it will be
00034 //  preceded by "HepMC::IO_Ascii-COMMENT\n"
00035 // Each event, vertex, particle, particle data is preceded by 
00036 //  "E ","V ","P ","D "    respectively.
00037 // Comments may appear anywhere in the file -- so long as they do not contain
00038 //  any of the 4 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 
00048 namespace HepMC {
00049 
00050     class GenEvent;
00051     class GenVertex;
00052     class GenParticle;
00053     class ParticleData;
00054 
00056 
00063     class IO_Ascii : public IO_BaseClass {
00064     public:
00066         IO_Ascii( const char* filename="IO_Ascii.dat", 
00067                   std::ios::openmode mode=std::ios::out );
00068         virtual       ~IO_Ascii();
00069 
00071         void          write_event( const GenEvent* evt );
00073         bool          fill_next_event( GenEvent* evt );
00074         void          write_particle_data_table(const ParticleDataTable*);
00075         bool          fill_particle_data_table( ParticleDataTable* );
00079         void          write_comment( const std::string comment );
00080 
00081         int           rdstate() const;  
00082         void          clear();  
00083 
00085         void          print( std::ostream& ostr = std::cout ) const;
00086 
00087     protected: // for internal use only
00089         void          write_vertex( GenVertex* );
00091         void          write_particle( GenParticle* p );
00093         void          write_particle_data( const ParticleData* d );
00095         GenVertex*    read_vertex( TempParticleMap& particle_to_end_vertex );
00097         GenParticle*  read_particle( TempParticleMap& particle_to_end_vertex );
00099         ParticleData* read_particle_data( ParticleDataTable* );
00101         bool          write_end_listing();
00103         bool          search_for_key_end( std::istream& in, 
00104                                           const char* key);
00106         bool          search_for_key_beginning( std::istream& in, 
00107                                                 const char* key );
00109         bool          eat_key( std::iostream& in, const char* key );
00111         int           find_in_map( const std::map<GenVertex*,int>& m, 
00112                                    GenVertex* v) const;
00113 
00114         void          output( const double& );  
00115         void          output( const int& );  
00116         void          output( const long int& );  
00117         void          output( const char& );  
00118     private: // use of copy constructor is not allowed
00119         IO_Ascii( const IO_Ascii& ) : IO_BaseClass() {}
00120     private: // data members
00121         std::ios::openmode  m_mode;
00122         std::fstream        m_file;
00123         bool                m_finished_first_event_io;
00124     };
00125 
00127     // Inlines  //
00129 
00130     inline void IO_Ascii::output( const double& d ) {
00131         if ( d == 0. ) {
00132             m_file << ' ' << (int)0;
00133         } else {
00134             m_file << ' ' << d;
00135         }
00136     }
00137     inline void IO_Ascii::output( const int& i ) { m_file << ' ' << i; }
00138     inline void IO_Ascii::output( const long int& i ) { m_file << ' ' << i; }
00139     inline void IO_Ascii::output( const char& c ) { m_file << c; }
00140     inline int  IO_Ascii::rdstate() const { return (int)m_file.rdstate(); }
00141     inline void IO_Ascii::clear() { m_file.clear(); }
00142 
00143 } // HepMC
00144 
00145 #endif  // HEPMC_IO_ASCII_H
00146 //--------------------------------------------------------------------------
00147 
00148 
00149 

Generated on Tue Feb 5 13:25:44 2008 for HepMC by  doxygen 1.5.1-3