Fork me on GitHub

source: svn/trunk/Utilities/HepMC/src/GenCrossSection.cc@ 633

Last change on this file since 633 was 571, checked in by cp3-support, 13 years ago

upgrade HepMC to version 2.06.05

File size: 3.0 KB
Line 
1//--------------------------------------------------------------------------
2//////////////////////////////////////////////////////////////////////////
3// garren@fnal.gov, January 2009
4//
5// The singleton GenCrossSection class holds run level information,
6// such as the cross section.
7//
8//////////////////////////////////////////////////////////////////////////
9//--------------------------------------------------------------------------
10
11#include <iostream>
12#include <sstream>
13
14#include "GenCrossSection.h"
15#include "IO_Exception.h"
16
17namespace HepMC {
18
19GenCrossSection::GenCrossSection( GenCrossSection const & orig )
20 : m_cross_section( orig.cross_section() ),
21 m_cross_section_error( orig.cross_section_error() ),
22 m_is_set( orig.is_set() )
23{}
24
25void GenCrossSection::swap( GenCrossSection & other)
26{
27 std::swap( m_cross_section, other.m_cross_section );
28 std::swap( m_cross_section_error, other.m_cross_section_error );
29 std::swap( m_is_set, other.m_is_set );
30}
31
32GenCrossSection & GenCrossSection::operator = ( GenCrossSection const & rhs )
33{
34 GenCrossSection tmp( rhs );
35 swap( tmp );
36 return *this;
37}
38
39bool GenCrossSection::operator==( const GenCrossSection& rhs ) const
40{
41 if( rhs.cross_section() != this->cross_section() ) return false;
42 if( rhs.cross_section_error() != this->cross_section_error() ) return false;
43 return true;
44}
45
46bool GenCrossSection::operator!=( const GenCrossSection& rhs ) const
47{
48 return !( rhs == *this );
49}
50
51
52void GenCrossSection::clear()
53{
54 m_cross_section = 0.0;
55 m_cross_section_error = 0.0;
56 m_is_set = false;
57}
58
59std::ostream & GenCrossSection::write( std::ostream & os ) const
60{
61 // make sure the stream is valid
62 if ( !os ) {
63 std::cerr << "GenCrossSection::print !os, setting badbit" << std::endl;
64 os.clear(std::ios::badbit);
65 return os;
66 }
67 // write the GenCrossSection information if the cross section was set
68 if( is_set() ) {
69 os << "C " << m_cross_section
70 << " " << m_cross_section_error
71 << "\n";
72 }
73 return os;
74}
75
76std::istream & GenCrossSection::read( std::istream & is )
77{
78 // make sure the stream is valid
79 if ( !is ) {
80 std::cerr << "GenCrossSection stream input setting badbit." << std::endl;
81 is.clear(std::ios::badbit);
82 return is;
83 }
84 // check to see if we have a GenCrossSection line
85 // This line is optional and may not exist
86 if ( is.peek()!='C' ) {
87 return is;
88 }
89 // get the GenCrossSection line
90 std::string line, firstc;
91 std::getline(is,line);
92 std::istringstream iline(line);
93 // Get first character and throw it away
94 iline >> firstc;
95 // Now get the numbers
96 double xs = 0., xserr = 0.;
97 iline >> xs ;
98 if(!iline) throw IO_Exception("GenCrossSection::read encounterd invalid data");
99 iline >> xserr ;
100 if(!iline) throw IO_Exception("GenCrossSection::read encounterd invalid data");
101 // set the data members
102 set_cross_section( xs, xserr );
103 return is;
104}
105
106} // HepMC
Note: See TracBrowser for help on using the repository browser.