![]() |
HepMC Reference DocumentationHepMC |
00001 //-------------------------------------------------------------------------- 00002 // 00003 // PdfInfo.cc 00004 // Author: Lynn Garren 00005 // 00006 // Implement operator >> and operator << 00007 // 00008 // ---------------------------------------------------------------------- 00009 00010 #include <iostream> 00011 #include <ostream> 00012 #include <istream> 00013 #include <sstream> 00014 00015 #include "HepMC/PdfInfo.h" 00016 #include "HepMC/StreamHelpers.h" 00017 #include "HepMC/IO_Exception.h" 00018 00019 namespace HepMC { 00020 00021 std::ostream & operator << ( std::ostream & os, PdfInfo const * pdf) 00022 { 00023 if ( !os ) { 00024 std::cerr << "operator << for PdfInfo: !os, " 00025 << " setting badbit" << std::endl; 00026 os.clear(std::ios::badbit); 00027 return os; 00028 } 00029 os << 'F'; 00030 // PdfInfo* is set to 0 by default 00031 if ( !pdf ) { 00032 detail::output( os, 0 ); 00033 detail::output( os, 0 ); 00034 detail::output( os, 0. ); 00035 detail::output( os, 0. ); 00036 detail::output( os, 0. ); 00037 detail::output( os, 0. ); 00038 detail::output( os, 0. ); 00039 detail::output( os, 0 ); 00040 detail::output( os, 0 ); 00041 detail::output( os,'\n'); 00042 return os; 00043 } 00044 // 00045 detail::output( os, pdf->id1() ); 00046 detail::output( os, pdf->id2() ); 00047 detail::output( os, pdf->x1() ); 00048 detail::output( os, pdf->x2() ); 00049 detail::output( os, pdf->scalePDF() ); 00050 detail::output( os, pdf->pdf1() ); 00051 detail::output( os, pdf->pdf2() ); 00052 detail::output( os, pdf->pdf_id1() ); 00053 detail::output( os, pdf->pdf_id2() ); 00054 detail::output( os,'\n'); 00055 00056 return os; 00057 } 00058 00059 std::istream & operator >> (std::istream & is, PdfInfo * pdf) 00060 { 00061 // make sure the stream is valid 00062 if ( !is ) { 00063 std::cerr << "PdfInfo input stream setting badbit." << std::endl; 00064 is.clear(std::ios::badbit); 00065 return is; 00066 } 00067 // 00068 // get the PdfInfo line 00069 std::string line; 00070 std::getline(is,line); 00071 std::istringstream iline(line); 00072 std::string firstc; 00073 iline >> firstc; 00074 // test to be sure the next entry is of type "F" then ignore it 00075 if ( firstc != "F" ) { 00076 std::cerr << "PdfInfo input stream invalid line type: " 00077 << firstc << std::endl; 00078 std::cerr << "PdfInfo input stream setting badbit." << std::endl; 00079 is.clear(std::ios::badbit); 00080 return is; 00081 } 00082 // read values into temp variables, then create a new PdfInfo object 00083 int id1 =0, id2 =0, pdf_id1=0, pdf_id2=0; 00084 double x1 = 0., x2 = 0., scale = 0., pdf1 = 0., pdf2 = 0.; 00085 iline >> id1 ; 00086 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00087 // check now for empty PdfInfo line 00088 if( id1 == 0 ) return is; 00089 // continue reading 00090 iline >> id2 ; 00091 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00092 iline >> x1 ; 00093 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00094 iline >> x2 ; 00095 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00096 iline >> scale ; 00097 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00098 iline >> pdf1 ; 00099 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00100 iline >> pdf2; 00101 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00102 // check to see if we are at the end of the line 00103 if( !iline.eof() ) { 00104 iline >> pdf_id1 ; 00105 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00106 iline >> pdf_id2; 00107 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); 00108 } 00109 pdf->set_id1( id1 ); 00110 pdf->set_id2( id2 ); 00111 pdf->set_pdf_id1( pdf_id1 ); 00112 pdf->set_pdf_id2( pdf_id2 ); 00113 pdf->set_x1( x1 ); 00114 pdf->set_x2( x2 ); 00115 pdf->set_scalePDF( scale ); 00116 pdf->set_pdf1( pdf1 ); 00117 pdf->set_pdf2( pdf2 ); 00118 00119 return is; 00120 } 00121 00122 } // HepMC