![]() |
HepMC Reference DocumentationHepMC |
00001 //-------------------------------------------------------------------------- 00002 // 00003 // HeavyIon.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/HeavyIon.h" 00016 #include "HepMC/StreamHelpers.h" 00017 #include "HepMC/IO_Exception.h" 00018 00019 namespace HepMC { 00020 00023 std::ostream & operator << (std::ostream & os, HeavyIon const * ion) 00024 { 00025 if ( !os ) { 00026 std::cerr << "HeavyIon output stream !os, " 00027 << " setting badbit" << std::endl; 00028 os.clear(std::ios::badbit); 00029 return os; 00030 } 00031 os << 'H'; 00032 // HeavyIon* is set to 0 by default 00033 if ( !ion ) { 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, 0 ); 00042 detail::output( os, 0 ); 00043 detail::output( os, 0. ); 00044 detail::output( os, 0. ); 00045 detail::output( os, 0. ); 00046 detail::output( os, 0. ); 00047 detail::output( os,'\n'); 00048 return os; 00049 } 00050 // 00051 detail::output( os, ion->Ncoll_hard() ); 00052 detail::output( os, ion->Npart_proj() ); 00053 detail::output( os, ion->Npart_targ() ); 00054 detail::output( os, ion->Ncoll() ); 00055 detail::output( os, ion->spectator_neutrons() ); 00056 detail::output( os, ion->spectator_protons() ); 00057 detail::output( os, ion->N_Nwounded_collisions() ); 00058 detail::output( os, ion->Nwounded_N_collisions() ); 00059 detail::output( os, ion->Nwounded_Nwounded_collisions() ); 00060 detail::output( os, ion->impact_parameter() ); 00061 detail::output( os, ion->event_plane_angle() ); 00062 detail::output( os, ion->eccentricity() ); 00063 detail::output( os, ion->sigma_inel_NN() ); 00064 detail::output( os,'\n'); 00065 00066 return os; 00067 } 00068 00071 std::istream & operator >> (std::istream & is, HeavyIon * ion) 00072 { 00073 // make sure the stream is valid 00074 if ( !is ) { 00075 std::cerr << "HeavyIon input stream setting badbit." << std::endl; 00076 is.clear(std::ios::badbit); 00077 return is; 00078 } 00079 // get the HeavyIon line 00080 std::string line; 00081 std::getline(is,line); 00082 std::istringstream iline(line); 00083 std::string firstc; 00084 iline >> firstc; 00085 // test to be sure the next entry is of type "H" 00086 if( firstc != "H" ) { 00087 std::cerr << "HeavyIon input stream invalid line type: " 00088 << firstc << std::endl; 00089 std::cerr << "HeavyIon input stream setting badbit." << std::endl; 00090 is.clear(std::ios::badbit); 00091 return is; 00092 } 00093 // read values into temp variables, then create a new HeavyIon object 00094 int nh =0, np =0, nt =0, nc =0, 00095 neut = 0, prot = 0, nw =0, nwn =0, nwnw =0; 00096 float impact = 0., plane = 0., xcen = 0., inel = 0.; 00097 iline >> nh ; 00098 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00099 iline >> np ; 00100 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00101 iline >> nt ; 00102 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00103 iline >> nc ; 00104 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00105 iline >> neut ; 00106 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00107 iline >> prot; 00108 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00109 iline >> nw ; 00110 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00111 iline >> nwn ; 00112 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00113 iline >> nwnw ; 00114 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00115 iline >> impact ; 00116 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00117 iline >> plane ; 00118 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00119 iline >> xcen ; 00120 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00121 iline >> inel; 00122 if(!iline) throw IO_Exception("HeavyIon input stream encounterd invalid data"); 00123 if( nh == 0 ) { 00124 return is; 00125 } 00126 00127 ion->set_Ncoll_hard(nh); 00128 ion->set_Npart_proj(np); 00129 ion->set_Npart_targ(nt); 00130 ion->set_Ncoll(nc); 00131 ion->set_spectator_neutrons(neut); 00132 ion->set_spectator_protons(prot); 00133 ion->set_N_Nwounded_collisions(nw); 00134 ion->set_Nwounded_N_collisions(nwn); 00135 ion->set_Nwounded_Nwounded_collisions(nwnw); 00136 ion->set_impact_parameter(impact); 00137 ion->set_event_plane_angle(plane); 00138 ion->set_eccentricity(xcen); 00139 ion->set_sigma_inel_NN(inel); 00140 00141 return is; 00142 } 00143 00144 00145 } // HepMC