9 #include "HepMC/IO_GenEvent.h"
10 #include "HepMC/IO_Exception.h"
11 #include "HepMC/GenEvent.h"
12 #include "HepMC/StreamHelpers.h"
18 m_file(filename.c_str(), mode),
26 if ( (m_mode&std::ios::out && m_mode&std::ios::in) ||
27 (m_mode&std::ios::app && m_mode&std::ios::in) ) {
28 m_error_type = IO_Exception::InputAndOutput;
29 m_error_message =
"IO_GenEvent::IO_GenEvent Error, open of file requested of input AND output type. Not allowed. Closing file.";
30 std::cerr << m_error_message << std::endl;
36 if ( m_mode&std::ios::in ) {
39 detail::establish_input_stream_info(m_file);
41 if ( m_mode&std::ios::out ) {
44 detail::establish_output_stream_info(m_file);
58 detail::establish_input_stream_info( istr );
69 detail::establish_output_stream_info( ostr );
72 IO_GenEvent::~IO_GenEvent() {
73 if ( m_ostr != NULL ) {
76 if(m_have_file) m_file.close();
80 Units::LengthUnit len ) {
81 if( m_istr != NULL ) {
87 ostr <<
"IO_GenEvent: unformated ascii file IO for machine reading.\n";
88 if(m_have_file) ostr <<
"\tFile openmode: " << m_mode ;
89 ostr <<
" stream state: " << m_ostr->rdstate()
90 <<
" bad:" << (m_ostr->rdstate()&std::ios::badbit)
91 <<
" eof:" << (m_ostr->rdstate()&std::ios::eofbit)
92 <<
" fail:" << (m_ostr->rdstate()&std::ios::failbit)
93 <<
" good:" << (m_ostr->rdstate()&std::ios::goodbit) << std::endl;
98 std::cerr <<
"IO_GenEvent::precision Error, "
99 <<
"precision is greater than 16. "
100 <<
"Not allowed. Using default precision of 16."
105 m_ostr->precision(size);
112 m_error_type = IO_Exception::OK;
116 m_error_type = IO_Exception::NullEvent;
117 m_error_message =
"IO_GenEvent::fill_next_event error - passed null event.";
118 std::cerr << m_error_message << std::endl;
122 if ( !(*m_istr) )
return false;
124 m_error_type = IO_Exception::WrongFileType;
125 m_error_message =
"HepMC::IO_GenEvent::fill_next_event attempt to read from output file.";
126 std::cerr << m_error_message << std::endl;
134 m_error_type = IO_Exception::InvalidData;
135 m_error_message = e.what();
148 if ( m_ostr == NULL ) {
149 m_error_type = IO_Exception::WrongFileType;
150 m_error_message =
"HepMC::IO_GenEvent::write_event attempt to write to input file.";
151 std::cerr << m_error_message << std::endl;
164 if ( !(*m_ostr) )
return;
165 if ( m_ostr == NULL ) {
166 m_error_type = IO_Exception::WrongFileType;
167 m_error_message =
"HepMC::IO_GenEvent::write_event attempt to write to input file.";
168 std::cerr << m_error_message << std::endl;
174 *m_ostr <<
"\n" <<
"HepMC::IO_GenEvent-COMMENT\n";
175 *m_ostr << comment << std::endl;
void write_event(const GenEvent *evt)
write this event
IO_GenEvent(const std::string &filename="IO_GenEvent.dat", std::ios::openmode mode=std::ios::out)
constructor requiring a file name and std::ios mode
std::istream & set_input_units(std::istream &, Units::MomentumUnit, Units::LengthUnit)
set the units for this input stream
The GenEvent class is the core of HepMC.
void print(std::ostream &ostr=std::cout) const
write to ostr
bool fill_next_event(GenEvent *evt)
get the next event
void clear()
empties the entire event
std::ostream & write_HepMC_IO_block_begin(std::ostream &)
Explicitly write the begin block lines that IO_GenEvent uses.
void write_comment(const std::string comment)
void use_input_units(Units::MomentumUnit, Units::LengthUnit)
std::ostream & write_HepMC_IO_block_end(std::ostream &)
Explicitly write the end block line that IO_GenEvent uses.