1 //--------------------------------------------------------------------------
2 #ifndef HEPMC_IO_GENEVENT_H
3 #define HEPMC_IO_GENEVENT_H
5 //////////////////////////////////////////////////////////////////////////
6 // garren@fnal.gov, July 2007
7 // with input from Gavin Salam, salam@lpthe.jussieu.fr
9 // event input/output in ascii format for machine reading
10 // This class persists all information found in a GenEvent
11 //////////////////////////////////////////////////////////////////////////
17 #include "HepMC/IO_BaseClass.h"
18 #include "HepMC/IO_Exception.h"
19 #include "HepMC/Units.h"
29 //! IO_GenEvent also deals with HeavyIon and PdfInfo
32 /// \class IO_GenEvent
33 /// event input/output in ascii format for machine reading
34 /// extended format contains HeavyIon and PdfInfo classes
36 /// Strategy for reading or writing events using iostreams
37 /// When instantiating with a file name, the mode of file to be created
38 /// must be specified. Options are:
39 /// std::ios::in open file for input
40 /// std::ios::out open file for output
41 /// std::ios::trunc erase old file when opening (i.e. ios::out|ios::trunc
42 /// removes oldfile, and creates a new one for output )
43 /// std::ios::app append output to end of file
44 /// for the purposes of this class, simultaneous input and output mode
45 /// ( std::ios::in | std::ios::out ) is not allowed.
47 /// Event listings are preceded by the key:
48 /// "HepMC::IO_GenEvent-START_EVENT_LISTING\n"
49 /// and terminated by the key:
50 /// "HepMC::IO_GenEvent-END_EVENT_LISTING\n"
51 /// GenParticle Data tables are preceded by the key:
52 /// "HepMC::IO_GenEvent-START_PARTICLE_DATA\n"
53 /// and terminated by the key:
54 /// "HepMC::IO_GenEvent-END_PARTICLE_DATA\n"
55 /// Comments are allowed. They need not be preceded by anything, though if
56 /// a comment is written using write_comment( const string ) then it will be
57 /// preceded by "HepMC::IO_GenEvent-COMMENT\n"
58 /// Each event, vertex, particle, particle data, heavy ion, or pdf info line
59 /// is preceded by "E ","V ","P ","D ","H ","F " respectively.
60 /// Comments may appear anywhere in the file -- so long as they do not contain
61 /// any of the start/stop keys.
63 class IO_GenEvent : public IO_BaseClass {
65 /// constructor requiring a file name and std::ios mode
66 IO_GenEvent( const std::string& filename="IO_GenEvent.dat",
67 std::ios::openmode mode=std::ios::out );
68 /// constructor requiring an input stream
69 IO_GenEvent( std::istream & );
70 /// constructor requiring an output stream
71 IO_GenEvent( std::ostream & );
72 virtual ~IO_GenEvent();
75 void write_event( const GenEvent* evt );
76 /// get the next event
77 bool fill_next_event( GenEvent* evt );
78 /// insert a comment directly into the output file --- normally you
79 /// only want to do this at the beginning or end of the file. All
80 /// comments are preceded with "HepMC::IO_GenEvent-COMMENT\n"
81 void write_comment( const std::string comment );
83 int rdstate() const; //!< check the state of the IO stream
84 void clear(); //!< clear the IO stream
87 void print( std::ostream& ostr = std::cout ) const;
89 /// needed when reading a file without units if those units are
90 /// different than the declared default units
91 /// (e.g., the default units are MeV, but the file was written with GeV)
92 /// This method is not necessary if the units are written in the file
93 void use_input_units( Units::MomentumUnit, Units::LengthUnit );
95 /// set output precision
96 /// The default precision is 16.
97 void precision( int );
99 /// integer (enum) associated with read error
100 int error_type() const;
101 /// the read error message string
102 const std::string & error_message() const;
104 private: // use of copy constructor is not allowed
105 IO_GenEvent( const IO_GenEvent& ) : IO_BaseClass() {}
107 private: // data members
108 std::ios::openmode m_mode;
110 std::ostream * m_ostr;
111 std::istream * m_istr;
114 IO_Exception::ErrorType m_error_type;
115 std::string m_error_message;
123 inline int IO_GenEvent::rdstate() const {
126 state = (int)m_istr->rdstate();
128 state = (int)m_ostr->rdstate();
133 inline void IO_GenEvent::clear() {
141 inline int IO_GenEvent::error_type() const {
145 inline const std::string & IO_GenEvent::error_message() const {
146 return m_error_message;
151 #endif // HEPMC_IO_GENEVENT_H
152 //--------------------------------------------------------------------------