]>
Commit | Line | Data |
---|---|---|
0ca57c2f | 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 | if ( !os ) { | |
24 | std::cerr << "operator << for PdfInfo: !os, " | |
25 | << " setting badbit" << std::endl; | |
26 | os.clear(std::ios::badbit); | |
27 | return os; | |
28 | } | |
29 | os << 'F'; | |
30 | // PdfInfo* is set to 0 by default | |
31 | if ( !pdf ) { | |
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'); | |
42 | return os; | |
43 | } | |
44 | // | |
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'); | |
55 | ||
56 | return os; | |
57 | } | |
58 | ||
59 | std::istream & operator >> (std::istream & is, PdfInfo * pdf) | |
60 | { | |
61 | // make sure the stream is valid | |
62 | if ( !is ) { | |
63 | std::cerr << "PdfInfo input stream setting badbit." << std::endl; | |
64 | is.clear(std::ios::badbit); | |
65 | return is; | |
66 | } | |
67 | // | |
68 | // get the PdfInfo line | |
69 | std::string line; | |
70 | std::getline(is,line); | |
71 | std::istringstream iline(line); | |
72 | std::string firstc; | |
73 | iline >> firstc; | |
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"); | |
80 | } | |
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.; | |
84 | iline >> id1 ; | |
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; | |
88 | // continue reading | |
89 | iline >> id2 ; | |
90 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
91 | iline >> x1 ; | |
92 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
93 | iline >> x2 ; | |
94 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
95 | iline >> scale ; | |
96 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
97 | iline >> pdf1 ; | |
98 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
99 | iline >> pdf2; | |
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 | |
102 | if( !iline.eof() ) { | |
103 | iline >> pdf_id1 ; | |
104 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
105 | iline >> pdf_id2; | |
106 | if(!iline) throw IO_Exception("PdfInfo input stream encounterd invalid data"); | |
107 | } | |
108 | pdf->set_id1( id1 ); | |
109 | pdf->set_id2( id2 ); | |
110 | pdf->set_pdf_id1( pdf_id1 ); | |
111 | pdf->set_pdf_id2( pdf_id2 ); | |
112 | pdf->set_x1( x1 ); | |
113 | pdf->set_x2( x2 ); | |
114 | pdf->set_scalePDF( scale ); | |
115 | pdf->set_pdf1( pdf1 ); | |
116 | pdf->set_pdf2( pdf2 ); | |
117 | ||
118 | return is; | |
119 | } | |
120 | ||
121 | } // HepMC |