Line data Source code
1 : //--------------------------------------------------------------------------
2 : //
3 : // PdfInfo.cc
4 : // Author: Lynn Garren
5 : //
6 : // Implement operator >> and operator <<
7 : //
8 : // ----------------------------------------------------------------------
9 :
10 : #include <iostream>
11 : #include <ostream>
12 : #include <istream>
13 : #include <sstream>
14 :
15 : #include "HepMC/PdfInfo.h"
16 : #include "HepMC/StreamHelpers.h"
17 : #include "HepMC/IO_Exception.h"
18 :
19 : namespace HepMC {
20 :
21 : std::ostream & operator << ( std::ostream & os, PdfInfo const * pdf)
22 : {
23 0 : if ( !os ) {
24 0 : std::cerr << "operator << for PdfInfo: !os, "
25 0 : << " setting badbit" << std::endl;
26 0 : os.clear(std::ios::badbit);
27 0 : return os;
28 : }
29 0 : os << 'F';
30 : // PdfInfo* is set to 0 by default
31 0 : if ( !pdf ) {
32 0 : detail::output( os, 0 );
33 0 : detail::output( os, 0 );
34 0 : detail::output( os, 0. );
35 0 : detail::output( os, 0. );
36 0 : detail::output( os, 0. );
37 0 : detail::output( os, 0. );
38 0 : detail::output( os, 0. );
39 0 : detail::output( os, 0 );
40 0 : detail::output( os, 0 );
41 0 : detail::output( os,'\n');
42 0 : return os;
43 : }
44 : //
45 0 : detail::output( os, pdf->id1() );
46 0 : detail::output( os, pdf->id2() );
47 0 : detail::output( os, pdf->x1() );
48 0 : detail::output( os, pdf->x2() );
49 0 : detail::output( os, pdf->scalePDF() );
50 0 : detail::output( os, pdf->pdf1() );
51 0 : detail::output( os, pdf->pdf2() );
52 0 : detail::output( os, pdf->pdf_id1() );
53 0 : detail::output( os, pdf->pdf_id2() );
54 0 : detail::output( os,'\n');
55 :
56 0 : return os;
57 0 : }
58 :
59 : std::istream & operator >> (std::istream & is, PdfInfo * pdf)
60 : {
61 : // make sure the stream is valid
62 0 : if ( !is ) {
63 0 : std::cerr << "PdfInfo input stream setting badbit." << std::endl;
64 0 : is.clear(std::ios::badbit);
65 0 : return is;
66 : }
67 : //
68 : // get the PdfInfo line
69 0 : std::string line;
70 0 : std::getline(is,line);
71 0 : std::istringstream iline(line);
72 0 : std::string firstc;
73 0 : iline >> firstc;
74 : // test to be sure the next entry is of type "F" then ignore it
75 0 : if ( firstc != "F" ) {
76 0 : std::cerr << "PdfInfo input stream invalid line type: "
77 0 : << firstc << std::endl;
78 : // this is non-recoverable, so throw here
79 0 : throw IO_Exception("PdfInfo input stream encounterd invalid data");
80 : }
81 : // read values into temp variables, then create a new PdfInfo object
82 0 : int id1 =0, id2 =0, pdf_id1=0, pdf_id2=0;
83 0 : double x1 = 0., x2 = 0., scale = 0., pdf1 = 0., pdf2 = 0.;
84 0 : iline >> id1 ;
85 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
86 : // check now for empty PdfInfo line
87 0 : if( id1 == 0 ) return is;
88 : // continue reading
89 0 : iline >> id2 ;
90 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
91 0 : iline >> x1 ;
92 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
93 0 : iline >> x2 ;
94 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
95 0 : iline >> scale ;
96 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
97 0 : iline >> pdf1 ;
98 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
99 0 : iline >> pdf2;
100 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
101 : // check to see if we are at the end of the line
102 0 : if( !iline.eof() ) {
103 0 : iline >> pdf_id1 ;
104 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
105 0 : iline >> pdf_id2;
106 0 : if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data");
107 : }
108 0 : pdf->set_id1( id1 );
109 0 : pdf->set_id2( id2 );
110 0 : pdf->set_pdf_id1( pdf_id1 );
111 0 : pdf->set_pdf_id2( pdf_id2 );
112 0 : pdf->set_x1( x1 );
113 0 : pdf->set_x2( x2 );
114 0 : pdf->set_scalePDF( scale );
115 0 : pdf->set_pdf1( pdf1 );
116 0 : pdf->set_pdf2( pdf2 );
117 :
118 0 : return is;
119 0 : }
120 :
121 : } // HepMC
|