1 //--------------------------------------------------------------------------
6 // Implement operator >> and operator <<
8 // ----------------------------------------------------------------------
15 #include "HepMC/PdfInfo.h"
16 #include "HepMC/StreamHelpers.h"
17 #include "HepMC/IO_Exception.h"
21 std::ostream & operator << ( std::ostream & os, PdfInfo const * pdf)
24 std::cerr << "operator << for PdfInfo: !os, "
25 << " setting badbit" << std::endl;
26 os.clear(std::ios::badbit);
30 // PdfInfo* is set to 0 by default
32 detail::output( os, 0 );
33 detail::output( os, 0 );
34 detail::output( os, 0. );
35 detail::output( os, 0. );
36 detail::output( os, 0. );
37 detail::output( os, 0. );
38 detail::output( os, 0. );
39 detail::output( os, 0 );
40 detail::output( os, 0 );
41 detail::output( os,'\n');
45 detail::output( os, pdf->id1() );
46 detail::output( os, pdf->id2() );
47 detail::output( os, pdf->x1() );
48 detail::output( os, pdf->x2() );
49 detail::output( os, pdf->scalePDF() );
50 detail::output( os, pdf->pdf1() );
51 detail::output( os, pdf->pdf2() );
52 detail::output( os, pdf->pdf_id1() );
53 detail::output( os, pdf->pdf_id2() );
54 detail::output( os,'\n');
59 std::istream & operator >> (std::istream & is, PdfInfo * pdf)
61 // make sure the stream is valid
63 std::cerr << "PdfInfo input stream setting badbit." << std::endl;
64 is.clear(std::ios::badbit);
68 // get the PdfInfo line
70 std::getline(is,line);
71 std::istringstream iline(line);
74 // test to be sure the next entry is of type "F" then ignore it
75 if ( firstc != "F" ) {
76 std::cerr << "PdfInfo input stream invalid line type: "
77 << firstc << std::endl;
78 // this is non-recoverable, so throw here
79 throw IO_Exception("PdfInfo input stream encounterd invalid data");
81 // read values into temp variables, then create a new PdfInfo object
82 int id1 =0, id2 =0, pdf_id1=0, pdf_id2=0;
83 double x1 = 0., x2 = 0., scale = 0., pdf1 = 0., pdf2 = 0.;
85 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
86 // check now for empty PdfInfo line
87 if( id1 == 0 ) return is;
90 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
92 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
94 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
96 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
98 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
100 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
101 // check to see if we are at the end of the line
104 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
106 if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
110 pdf->set_pdf_id1( pdf_id1 );
111 pdf->set_pdf_id2( pdf_id2 );
114 pdf->set_scalePDF( scale );
115 pdf->set_pdf1( pdf1 );
116 pdf->set_pdf2( pdf2 );