StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
GenCrossSection.cc
1 //--------------------------------------------------------------------------
3 // garren@fnal.gov, January 2009
4 //
5 // The singleton GenCrossSection class holds run level information,
6 // such as the cross section.
7 //
9 //--------------------------------------------------------------------------
10 
11 #include <iostream>
12 #include <sstream>
13 
14 #include "HepMC/GenCrossSection.h"
15 #include "HepMC/IO_Exception.h"
16 
17 namespace HepMC {
18 
19 GenCrossSection::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 
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 
33 {
34  GenCrossSection tmp( rhs );
35  swap( tmp );
36  return *this;
37 }
38 
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 
47 {
48  return !( rhs == *this );
49 }
50 
51 
53 {
54  m_cross_section = 0.0;
55  m_cross_section_error = 0.0;
56  m_is_set = false;
57 }
58 
59 std::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 
76 std::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
IO exception handling.
Definition: IO_Exception.h:28
void set_cross_section(double xs, double xs_err)
Set cross section and error in pb.
The GenCrossSection class stores the generated cross section.
bool operator==(const GenCrossSection &) const
check for equality
GenCrossSection & operator=(GenCrossSection const &rhs)
std::istream & read(std::istream &)
read from an input stream
bool operator!=(const GenCrossSection &) const
check for inequality
std::ostream & write(std::ostream &) const
write to an output stream
double cross_section_error() const
error associated with this cross section in pb
double cross_section() const
cross section in pb
bool is_set() const
True if the cross section has been set. False by default.
void swap(GenCrossSection &other)
swap