[571] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | //
|
---|
| 3 | // HeavyIon.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 "HeavyIon.h"
|
---|
| 16 | #include "StreamHelpers.h"
|
---|
| 17 | #include "IO_Exception.h"
|
---|
| 18 |
|
---|
| 19 | namespace HepMC {
|
---|
| 20 |
|
---|
| 21 | /// Write the contents of HeavyIon to an output stream.
|
---|
| 22 | /// GenEvent stores a pointer to a HeavyIon.
|
---|
| 23 | std::ostream & operator << (std::ostream & os, HeavyIon const * ion)
|
---|
| 24 | {
|
---|
| 25 | if ( !os ) {
|
---|
| 26 | std::cerr << "HeavyIon output stream !os, "
|
---|
| 27 | << " setting badbit" << std::endl;
|
---|
| 28 | os.clear(std::ios::badbit);
|
---|
| 29 | return os;
|
---|
| 30 | }
|
---|
| 31 | os << 'H';
|
---|
| 32 | // HeavyIon* is set to 0 by default
|
---|
| 33 | if ( !ion ) {
|
---|
| 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, 0 );
|
---|
| 42 | detail::output( os, 0 );
|
---|
| 43 | detail::output( os, 0. );
|
---|
| 44 | detail::output( os, 0. );
|
---|
| 45 | detail::output( os, 0. );
|
---|
| 46 | detail::output( os, 0. );
|
---|
| 47 | detail::output( os,'\n');
|
---|
| 48 | return os;
|
---|
| 49 | }
|
---|
| 50 | //
|
---|
| 51 | detail::output( os, ion->Ncoll_hard() );
|
---|
| 52 | detail::output( os, ion->Npart_proj() );
|
---|
| 53 | detail::output( os, ion->Npart_targ() );
|
---|
| 54 | detail::output( os, ion->Ncoll() );
|
---|
| 55 | detail::output( os, ion->spectator_neutrons() );
|
---|
| 56 | detail::output( os, ion->spectator_protons() );
|
---|
| 57 | detail::output( os, ion->N_Nwounded_collisions() );
|
---|
| 58 | detail::output( os, ion->Nwounded_N_collisions() );
|
---|
| 59 | detail::output( os, ion->Nwounded_Nwounded_collisions() );
|
---|
| 60 | detail::output( os, ion->impact_parameter() );
|
---|
| 61 | detail::output( os, ion->event_plane_angle() );
|
---|
| 62 | detail::output( os, ion->eccentricity() );
|
---|
| 63 | detail::output( os, ion->sigma_inel_NN() );
|
---|
| 64 | detail::output( os,'\n');
|
---|
| 65 |
|
---|
| 66 | return os;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /// Read the contents of HeavyIon from an input stream.
|
---|
| 70 | /// GenEvent stores a pointer to a HeavyIon.
|
---|
| 71 | std::istream & operator >> (std::istream & is, HeavyIon * ion)
|
---|
| 72 | {
|
---|
| 73 | // make sure the stream is valid
|
---|
| 74 | if ( !is ) {
|
---|
| 75 | std::cerr << "HeavyIon input stream setting badbit." << std::endl;
|
---|
| 76 | is.clear(std::ios::badbit);
|
---|
| 77 | return is;
|
---|
| 78 | }
|
---|
| 79 | // get the HeavyIon line
|
---|
| 80 | std::string line;
|
---|
| 81 | std::getline(is,line);
|
---|
| 82 | std::istringstream iline(line);
|
---|
| 83 | std::string firstc;
|
---|
| 84 | iline >> firstc;
|
---|
| 85 | // test to be sure the next entry is of type "H"
|
---|
| 86 | if( firstc != "H" ) {
|
---|
| 87 | std::cerr << "HeavyIon input stream invalid line type: "
|
---|
| 88 | << firstc << std::endl;
|
---|
| 89 | // The most likely problem is that we have found a HepMC block line
|
---|
| 90 | throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 91 | }
|
---|
| 92 | // read values into temp variables, then create a new HeavyIon object
|
---|
| 93 | int nh =0, np =0, nt =0, nc =0,
|
---|
| 94 | neut = 0, prot = 0, nw =0, nwn =0, nwnw =0;
|
---|
| 95 | float impact = 0., plane = 0., xcen = 0., inel = 0.;
|
---|
| 96 | iline >> nh ;
|
---|
| 97 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 98 | iline >> np ;
|
---|
| 99 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 100 | iline >> nt ;
|
---|
| 101 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 102 | iline >> nc ;
|
---|
| 103 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 104 | iline >> neut ;
|
---|
| 105 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 106 | iline >> prot;
|
---|
| 107 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 108 | iline >> nw ;
|
---|
| 109 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 110 | iline >> nwn ;
|
---|
| 111 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 112 | iline >> nwnw ;
|
---|
| 113 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 114 | iline >> impact ;
|
---|
| 115 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 116 | iline >> plane ;
|
---|
| 117 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 118 | iline >> xcen ;
|
---|
| 119 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 120 | iline >> inel;
|
---|
| 121 | if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data");
|
---|
| 122 | if( nh == 0 ) {
|
---|
| 123 | return is;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | ion->set_Ncoll_hard(nh);
|
---|
| 127 | ion->set_Npart_proj(np);
|
---|
| 128 | ion->set_Npart_targ(nt);
|
---|
| 129 | ion->set_Ncoll(nc);
|
---|
| 130 | ion->set_spectator_neutrons(neut);
|
---|
| 131 | ion->set_spectator_protons(prot);
|
---|
| 132 | ion->set_N_Nwounded_collisions(nw);
|
---|
| 133 | ion->set_Nwounded_N_collisions(nwn);
|
---|
| 134 | ion->set_Nwounded_Nwounded_collisions(nwnw);
|
---|
| 135 | ion->set_impact_parameter(impact);
|
---|
| 136 | ion->set_event_plane_angle(plane);
|
---|
| 137 | ion->set_eccentricity(xcen);
|
---|
| 138 | ion->set_sigma_inel_NN(inel);
|
---|
| 139 |
|
---|
| 140 | return is;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | } // HepMC
|
---|