![]() |
HepMC Reference DocumentationHepMC |
00001 //-------------------------------------------------------------------------- 00003 // garren@fnal.gov, January 2009 00004 // 00005 // The singleton GenCrossSection class holds run level information, 00006 // such as the cross section. 00007 // 00009 //-------------------------------------------------------------------------- 00010 00011 #include <iostream> 00012 #include <sstream> 00013 00014 #include "HepMC/GenCrossSection.h" 00015 #include "HepMC/IO_Exception.h" 00016 00017 namespace HepMC { 00018 00019 GenCrossSection::GenCrossSection( GenCrossSection const & orig ) 00020 : m_cross_section( orig.cross_section() ), 00021 m_cross_section_error( orig.cross_section_error() ), 00022 m_is_set( orig.is_set() ) 00023 {} 00024 00025 void GenCrossSection::swap( GenCrossSection & other) 00026 { 00027 std::swap( m_cross_section, other.m_cross_section ); 00028 std::swap( m_cross_section_error, other.m_cross_section_error ); 00029 std::swap( m_is_set, other.m_is_set ); 00030 } 00031 00032 GenCrossSection & GenCrossSection::operator = ( GenCrossSection const & rhs ) 00033 { 00034 GenCrossSection tmp( rhs ); 00035 swap( tmp ); 00036 return *this; 00037 } 00038 00039 bool GenCrossSection::operator==( const GenCrossSection& rhs ) const 00040 { 00041 if( rhs.cross_section() != this->cross_section() ) return false; 00042 if( rhs.cross_section_error() != this->cross_section_error() ) return false; 00043 return true; 00044 } 00045 00046 bool GenCrossSection::operator!=( const GenCrossSection& rhs ) const 00047 { 00048 return !( rhs == *this ); 00049 } 00050 00051 00052 void GenCrossSection::clear() 00053 { 00054 m_cross_section = 0.0; 00055 m_cross_section_error = 0.0; 00056 m_is_set = false; 00057 } 00058 00059 std::ostream & GenCrossSection::write( std::ostream & os ) const 00060 { 00061 // make sure the stream is valid 00062 if ( !os ) { 00063 std::cerr << "GenCrossSection::print !os, setting badbit" << std::endl; 00064 os.clear(std::ios::badbit); 00065 return os; 00066 } 00067 // write the GenCrossSection information if the cross section was set 00068 if( is_set() ) { 00069 os << "C " << m_cross_section 00070 << " " << m_cross_section_error 00071 << "\n"; 00072 } 00073 return os; 00074 } 00075 00076 std::istream & GenCrossSection::read( std::istream & is ) 00077 { 00078 // make sure the stream is valid 00079 if ( !is ) { 00080 std::cerr << "GenCrossSection stream input setting badbit." << std::endl; 00081 is.clear(std::ios::badbit); 00082 return is; 00083 } 00084 // check to see if we have a GenCrossSection line 00085 // This line is optional and may not exist 00086 if ( is.peek()!='C' ) { 00087 return is; 00088 } 00089 // get the GenCrossSection line 00090 std::string line, firstc; 00091 std::getline(is,line); 00092 std::istringstream iline(line); 00093 // Get first character and throw it away 00094 iline >> firstc; 00095 // Now get the numbers 00096 double xs = 0., xserr = 0.; 00097 iline >> xs ; 00098 if(!iline) throw IO_Exception("GenCrossSection::read encounterd invalid data"); 00099 iline >> xserr ; 00100 if(!iline) throw IO_Exception("GenCrossSection::read encounterd invalid data"); 00101 // set the data members 00102 set_cross_section( xs, xserr ); 00103 return is; 00104 } 00105 00106 } // HepMC