HepMC Reference Documentation

HepMC

PdfInfo.cc

Go to the documentation of this file.
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         // this is non-recoverable, so throw here 
00079         throw IO_Exception("PdfInfo input stream encounterd invalid data");
00080     } 
00081     // read values into temp variables, then create a new PdfInfo object
00082     int id1 =0, id2 =0, pdf_id1=0, pdf_id2=0;
00083     double  x1 = 0., x2 = 0., scale = 0., pdf1 = 0., pdf2 = 0.; 
00084     iline >> id1 ;
00085     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00086     // check now for empty PdfInfo line
00087     if( id1 == 0 ) return is;
00088     // continue reading
00089     iline >> id2 ;
00090     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00091     iline >> x1 ;
00092     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00093     iline >> x2 ;
00094     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00095     iline >> scale ;
00096     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00097     iline >> pdf1 ;
00098     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00099     iline >> pdf2;
00100     if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00101     // check to see if we are at the end of the line
00102     if( !iline.eof() ) {
00103         iline >> pdf_id1 ;
00104         if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00105         iline >> pdf_id2;
00106         if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
00107     }
00108     pdf->set_id1( id1 );
00109     pdf->set_id2( id2 );
00110     pdf->set_pdf_id1( pdf_id1 );
00111     pdf->set_pdf_id2( pdf_id2 );
00112     pdf->set_x1( x1 );
00113     pdf->set_x2( x2 );
00114     pdf->set_scalePDF( scale );
00115     pdf->set_pdf1( pdf1 );
00116     pdf->set_pdf2( pdf2 );
00117 
00118     return is;
00119 }
00120 
00121 } // HepMC

Generated on Fri Feb 17 00:31:25 2012 for HepMC by  doxygen 1.4.7