hepmc - Diff between revs 390 and 432
Subversion Repositories:
| Rev 390 | Rev 432 | |||
|---|---|---|---|---|
| Line 107... | Line 107... | |||
| 107 | for ( std::vector<long>::iterator rs = m_random_states.begin(); | 107 | for ( std::vector<long>::iterator rs = m_random_states.begin(); | |
| 108 | rs != m_random_states.end(); ++rs ) { | 108 | rs != m_random_states.end(); ++rs ) { | |
| 109 | detail::output( os, *rs ); | 109 | detail::output( os, *rs ); | |
| 110 | } | 110 | } | |
| 111 | // weights | 111 | // weights | |
| - | 112 | // we need to iterate over the map so that the weights printed | ||
| - | 113 | // here will be in the same order as the names printed next | ||
| 112 | os << ' ' << (int)weights().size() ; | 114 | os << ' ' << (int)weights().size() ; | |
| 113 | for ( WeightContainer::const_iterator w = weights().begin(); | - | ||
| 114 | w != weights().end(); ++w ) { | - | ||
| 115 | detail::output( os, *w ); | - | ||
| - | 115 | for ( WeightContainer::const_map_iterator w = weights().map_begin(); | ||
| - | 116 | w != weights().map_end(); ++w ) { | ||
| - | 117 | detail::output( os, m_weights[w->second] ); | ||
| 116 | } | 118 | } | |
| 117 | detail::output( os,'\n'); | 119 | detail::output( os,'\n'); | |
| - | 120 | // now add names for weights | ||
| - | 121 | // note that this prints a new line if and only if the weight container | ||
| - | 122 | // is not empty | ||
| - | 123 | if ( ! weights().empty() ) { | ||
| - | 124 | os << "N " << weights().size() << " " ; | ||
| - | 125 | for ( WeightContainer::const_map_iterator w = weights().map_begin(); | ||
| - | 126 | w != weights().map_end(); ++w ) { | ||
| - | 127 | detail::output( os,'"'); | ||
| - | 128 | os << w->first; | ||
| - | 129 | detail::output( os,'"'); | ||
| - | 130 | detail::output( os,' '); | ||
| - | 131 | } | ||
| - | 132 | detail::output( os,'\n'); | ||
| - | 133 | } | ||
| 118 | // | 134 | // | |
| 119 | // Units | 135 | // Units | |
| 120 | os << "U " << name(momentum_unit()); | 136 | os << "U " << name(momentum_unit()); | |
| 121 | os << " " << name(length_unit()); | 137 | os << " " << name(length_unit()); | |
| 122 | detail::output( os,'\n'); | 138 | detail::output( os,'\n'); | |
| 123 | // | 139 | // | |
| 124 | // write GenCrossSection if it has been set | 140 | // write GenCrossSection if it has been set | |
| 125 | if( m_cross_section ) m_cross_section->write(os); | 141 | if( m_cross_section ) m_cross_section->write(os); | |
| 126 | // | 142 | // | |
| 127 | os << heavy_ion() ; | - | ||
| 128 | os << pdf_info() ; | - | ||
| - | 143 | // write HeavyIon and PdfInfo if they have been set | ||
| - | 144 | if( m_heavy_ion ) os << heavy_ion() ; | ||
| - | 145 | if( m_pdf_info ) os << pdf_info() ; | ||
| 129 | // | 146 | // | |
| 130 | // Output all of the vertices - note there is no real order. | 147 | // Output all of the vertices - note there is no real order. | |
| 131 | for ( GenEvent::vertex_const_iterator v = vertices_begin(); | 148 | for ( GenEvent::vertex_const_iterator v = vertices_begin(); | |
| 132 | v != vertices_end(); ++v ) { | 149 | v != vertices_end(); ++v ) { | |
| 133 | write_vertex(os, *v); | 150 | write_vertex(os, *v); | |
| Line 182... | Line 199... | |||
| 182 | << "setting badbit." << std::endl; | 199 | << "setting badbit." << std::endl; | |
| 183 | is.clear(std::ios::badbit); | 200 | is.clear(std::ios::badbit); | |
| 184 | return is; | 201 | return is; | |
| 185 | } | 202 | } | |
| 186 | } | 203 | } | |
| 187 | // get the event line | - | ||
| 188 | std::string line; | - | ||
| 189 | std::getline(is,line); | - | ||
| 190 | std::istringstream iline(line); | - | ||
| 191 | std::string firstc; | - | ||
| 192 | iline >> firstc; | - | ||
| 193 | // | - | ||
| 194 | // read values into temp variables, then fill GenEvent | - | ||
| 195 | int event_number = 0, signal_process_id = 0, signal_process_vertex = 0, | - | ||
| 196 | num_vertices = 0, random_states_size = 0, weights_size = 0, | - | ||
| 197 | nmpi = -1, bp1 = 0, bp2 = 0; | - | ||
| 198 | double eventScale = 0, alpha_qcd = 0, alpha_qed = 0; | - | ||
| 199 | iline >> event_number; | - | ||
| 200 | if(!iline) detail::find_event_end( is ); | - | ||
| 201 | if( info.io_type() == gen || info.io_type() == extascii ) { | - | ||
| 202 | iline >> nmpi; | - | ||
| 203 | if(!iline) detail::find_event_end( is ); | - | ||
| 204 | set_mpi( nmpi ); | - | ||
| 205 | } | - | ||
| 206 | iline >> eventScale ; | - | ||
| 207 | if(!iline) detail::find_event_end( is ); | - | ||
| 208 | iline >> alpha_qcd ; | - | ||
| 209 | if(!iline) detail::find_event_end( is ); | - | ||
| 210 | iline >> alpha_qed; | - | ||
| 211 | if(!iline) detail::find_event_end( is ); | - | ||
| 212 | iline >> signal_process_id ; | - | ||
| 213 | if(!iline) detail::find_event_end( is ); | - | ||
| 214 | iline >> signal_process_vertex; | - | ||
| 215 | if(!iline) detail::find_event_end( is ); | - | ||
| 216 | iline >> num_vertices; | - | ||
| 217 | if(!iline) detail::find_event_end( is ); | - | ||
| 218 | if( info.io_type() == gen || info.io_type() == extascii ) { | - | ||
| 219 | iline >> bp1 ; | - | ||
| 220 | if(!iline) detail::find_event_end( is ); | - | ||
| 221 | iline >> bp2; | - | ||
| 222 | if(!iline) detail::find_event_end( is ); | - | ||
| 223 | } | - | ||
| 224 | iline >> random_states_size; | - | ||
| 225 | if(!iline) detail::find_event_end( is ); | - | ||
| 226 | std::vector<long> random_states(random_states_size); | - | ||
| 227 | for ( int i = 0; i < random_states_size; ++i ) { | - | ||
| 228 | iline >> random_states[i]; | - | ||
| 229 | if(!iline) detail::find_event_end( is ); | - | ||
| 230 | } | - | ||
| 231 | iline >> weights_size; | - | ||
| 232 | if(!iline) detail::find_event_end( is ); | - | ||
| 233 | WeightContainer weights(weights_size); | - | ||
| 234 | for ( int ii = 0; ii < weights_size; ++ii ) { | - | ||
| 235 | iline >> weights[ii]; | - | ||
| 236 | if(!iline) detail::find_event_end( is ); | - | ||
| 237 | } | - | ||
| 238 | // | - | ||
| 239 | // fill signal_process_id, event_number, weights, random_states, etc. | - | ||
| 240 | set_signal_process_id( signal_process_id ); | - | ||
| 241 | set_event_number( event_number ); | - | ||
| 242 | m_weights = weights; | - | ||
| 243 | set_random_states( random_states ); | - | ||
| 244 | set_event_scale( eventScale ); | - | ||
| 245 | set_alphaQCD( alpha_qcd ); | - | ||
| 246 | set_alphaQED( alpha_qed ); | - | ||
| 247 | if( info.io_type() == gen ) { | - | ||
| 248 | // get unit information if it exists | - | ||
| 249 | read_units( is ); | - | ||
| 250 | } | - | ||
| 251 | // check to see if we have a GenCrossSection line | - | ||
| 252 | if ( is.peek()=='C' ) { | - | ||
| 253 | // create cross section | - | ||
| 254 | GenCrossSection* xs = new GenCrossSection(); | - | ||
| 255 | // check for invalid data | - | ||
| 256 | try { | - | ||
| 257 | // read the line | - | ||
| 258 | xs->read(is); | - | ||
| 259 | } | - | ||
| 260 | catch (IO_Exception& e) { | - | ||
| 261 | detail::find_event_end( is ); | - | ||
| 262 | } | - | ||
| 263 | if(xs->is_set()) { | - | ||
| 264 | set_cross_section( *xs ); | - | ||
| 265 | } else { | - | ||
| 266 | delete xs; | - | ||
| 267 | xs = 0; | - | ||
| 268 | } | - | ||
| 269 | } | - | ||
| 270 | if( info.io_type() == gen || info.io_type() == extascii ) { | - | ||
| 271 | // get HeavyIon and PdfInfo | - | ||
| 272 | HeavyIon* ion = new HeavyIon(); | - | ||
| 273 | // check for invalid data | - | ||
| 274 | try { | - | ||
| 275 | is >> ion; | - | ||
| 276 | } | - | ||
| 277 | catch (IO_Exception& e) { | - | ||
| 278 | detail::find_event_end( is ); | - | ||
| 279 | } | - | ||
| 280 | if(ion->is_valid()) { | - | ||
| 281 | set_heavy_ion( *ion ); | - | ||
| 282 | } else { | - | ||
| 283 | delete ion; | - | ||
| 284 | ion = 0; | - | ||
| 285 | } | - | ||
| 286 | PdfInfo* pdf = new PdfInfo(); | - | ||
| 287 | // check for invalid data | - | ||
| 288 | try { | - | ||
| 289 | is >> pdf; | - | ||
| 290 | } | - | ||
| 291 | catch (IO_Exception& e) { | - | ||
| 292 | detail::find_event_end( is ); | - | ||
| 293 | } | - | ||
| 294 | if(pdf->is_valid()) { | - | ||
| 295 | set_pdf_info( *pdf ); | - | ||
| 296 | } else { | - | ||
| 297 | delete pdf; | - | ||
| 298 | pdf = 0; | - | ||
| 299 | } | - | ||
| 300 | } | - | ||
| - | 204 | |||
| - | 205 | int signal_process_vertex = 0; | ||
| - | 206 | int num_vertices = 0, bp1 = 0, bp2 = 0; | ||
| - | 207 | // OK - now ready to start reading the event, so set the header flag | ||
| - | 208 | info.set_reading_event_header(true); | ||
| - | 209 | // The flag will be set to false when we reach the end of the header | ||
| - | 210 | while(info.reading_event_header()) { | ||
| - | 211 | switch(is.peek()) { | ||
| - | 212 | case 'E': | ||
| - | 213 | { // deal with the event line | ||
| - | 214 | process_event_line( is, num_vertices, bp1, bp2, signal_process_vertex ); | ||
| - | 215 | } break; | ||
| - | 216 | case 'N': | ||
| - | 217 | { // get weight names | ||
| - | 218 | read_weight_names( is ); | ||
| - | 219 | } break; | ||
| - | 220 | case 'U': | ||
| - | 221 | { // get unit information if it exists | ||
| - | 222 | if( info.io_type() == gen ) { | ||
| - | 223 | read_units( is ); | ||
| - | 224 | } | ||
| - | 225 | } break; | ||
| - | 226 | case 'C': | ||
| - | 227 | { // we have a GenCrossSection line | ||
| - | 228 | // create cross section | ||
| - | 229 | GenCrossSection* xs = new GenCrossSection(); | ||
| - | 230 | // check for invalid data | ||
| - | 231 | try { | ||
| - | 232 | // read the line | ||
| - | 233 | xs->read(is); | ||
| - | 234 | } | ||
| - | 235 | catch (IO_Exception& e) { | ||
| - | 236 | detail::find_event_end( is ); | ||
| - | 237 | } | ||
| - | 238 | if(xs->is_set()) { | ||
| - | 239 | set_cross_section( *xs ); | ||
| - | 240 | } else { | ||
| - | 241 | delete xs; | ||
| - | 242 | xs = 0; | ||
| - | 243 | } | ||
| - | 244 | } break; | ||
| - | 245 | case 'H': | ||
| - | 246 | { // we have a HeavyIon line | ||
| - | 247 | if( info.io_type() == gen || info.io_type() == extascii ) { | ||
| - | 248 | // get HeavyIon | ||
| - | 249 | HeavyIon* ion = new HeavyIon(); | ||
| - | 250 | // check for invalid data | ||
| - | 251 | try { | ||
| - | 252 | is >> ion; | ||
| - | 253 | } | ||
| - | 254 | catch (IO_Exception& e) { | ||
| - | 255 | detail::find_event_end( is ); | ||
| - | 256 | } | ||
| - | 257 | if(ion->is_valid()) { | ||
| - | 258 | set_heavy_ion( *ion ); | ||
| - | 259 | } else { | ||
| - | 260 | delete ion; | ||
| - | 261 | ion = 0; | ||
| - | 262 | } | ||
| - | 263 | } | ||
| - | 264 | } break; | ||
| - | 265 | case 'F': | ||
| - | 266 | { // we have a PdfInfo line | ||
| - | 267 | if( info.io_type() == gen || info.io_type() == extascii ) { | ||
| - | 268 | // get PdfInfo | ||
| - | 269 | PdfInfo* pdf = new PdfInfo(); | ||
| - | 270 | // check for invalid data | ||
| - | 271 | try { | ||
| - | 272 | is >> pdf; | ||
| - | 273 | } | ||
| - | 274 | catch (IO_Exception& e) { | ||
| - | 275 | detail::find_event_end( is ); | ||
| - | 276 | } | ||
| - | 277 | if(pdf->is_valid()) { | ||
| - | 278 | set_pdf_info( *pdf ); | ||
| - | 279 | } else { | ||
| - | 280 | delete pdf; | ||
| - | 281 | pdf = 0; | ||
| - | 282 | } | ||
| - | 283 | } | ||
| - | 284 | } break; | ||
| - | 285 | case 'V': | ||
| - | 286 | { | ||
| - | 287 | // this should be the first vertex line - exit this loop | ||
| - | 288 | info.set_reading_event_header(false); | ||
| - | 289 | } break; | ||
| - | 290 | case 'P': | ||
| - | 291 | { // we should not find this line | ||
| - | 292 | std::cerr << "streaming input: found unexpected line P" << std::endl; | ||
| - | 293 | info.set_reading_event_header(false); | ||
| - | 294 | } break; | ||
| - | 295 | default: | ||
| - | 296 | // ignore everything else | ||
| - | 297 | break; | ||
| - | 298 | } // switch on line type | ||
| - | 299 | } // while reading_event_header | ||
| 301 | // | 300 | // | |
| 302 | // the end vertices of the particles are not connected until | 301 | // the end vertices of the particles are not connected until | |
| 303 | // after the event is read --- we store the values in a map until then | 302 | // after the event is read --- we store the values in a map until then | |
| 304 | TempParticleMap particle_to_end_vertex; | 303 | TempParticleMap particle_to_end_vertex; | |
| 305 | // | 304 | // | |
| Line 387... | Line 386... | |||
| 387 | if( info.finished_first_event() ) { | 386 | if( info.finished_first_event() ) { | |
| 388 | os << info.IO_GenEvent_End() << "\n"; | 387 | os << info.IO_GenEvent_End() << "\n"; | |
| 389 | os << std::flush; | 388 | os << std::flush; | |
| 390 | } | 389 | } | |
| 391 | return os; | 390 | return os; | |
| - | 391 | } | ||
| - | 392 | |||
| - | 393 | std::istream & GenEvent::process_event_line( std::istream & is, | ||
| - | 394 | int & num_vertices, | ||
| - | 395 | int & bp1, int & bp2, | ||
| - | 396 | int & signal_process_vertex ) | ||
| - | 397 | { | ||
| - | 398 | // | ||
| - | 399 | if ( !is ) { | ||
| - | 400 | std::cerr << "GenEvent::process_event_line setting badbit." << std::endl; | ||
| - | 401 | is.clear(std::ios::badbit); | ||
| - | 402 | return is; | ||
| - | 403 | } | ||
| - | 404 | // | ||
| - | 405 | StreamInfo & info = get_stream_info(is); | ||
| - | 406 | std::string line; | ||
| - | 407 | std::getline(is,line); | ||
| - | 408 | std::istringstream iline(line); | ||
| - | 409 | std::string firstc; | ||
| - | 410 | iline >> firstc; | ||
| - | 411 | // | ||
| - | 412 | // read values into temp variables, then fill GenEvent | ||
| - | 413 | int event_number = 0, signal_process_id = 0, | ||
| - | 414 | random_states_size = 0, nmpi = -1; | ||
| - | 415 | double eventScale = 0, alpha_qcd = 0, alpha_qed = 0; | ||
| - | 416 | iline >> event_number; | ||
| - | 417 | if(!iline) detail::find_event_end( is ); | ||
| - | 418 | if( info.io_type() == gen || info.io_type() == extascii ) { | ||
| - | 419 | iline >> nmpi; | ||
| - | 420 | if(!iline) detail::find_event_end( is ); | ||
| - | 421 | set_mpi( nmpi ); | ||
| - | 422 | } | ||
| - | 423 | iline >> eventScale ; | ||
| - | 424 | if(!iline) detail::find_event_end( is ); | ||
| - | 425 | iline >> alpha_qcd ; | ||
| - | 426 | if(!iline) detail::find_event_end( is ); | ||
| - | 427 | iline >> alpha_qed; | ||
| - | 428 | if(!iline) detail::find_event_end( is ); | ||
| - | 429 | iline >> signal_process_id ; | ||
| - | 430 | if(!iline) detail::find_event_end( is ); | ||
| - | 431 | iline >> signal_process_vertex; | ||
| - | 432 | if(!iline) detail::find_event_end( is ); | ||
| - | 433 | iline >> num_vertices; | ||
| - | 434 | if(!iline) detail::find_event_end( is ); | ||
| - | 435 | if( info.io_type() == gen || info.io_type() == extascii ) { | ||
| - | 436 | iline >> bp1 ; | ||
| - | 437 | if(!iline) detail::find_event_end( is ); | ||
| - | 438 | iline >> bp2; | ||
| - | 439 | if(!iline) detail::find_event_end( is ); | ||
| - | 440 | } | ||
| - | 441 | iline >> random_states_size; | ||
| - | 442 | if(!iline) detail::find_event_end( is ); | ||
| - | 443 | std::vector<long> random_states(random_states_size); | ||
| - | 444 | for ( int i = 0; i < random_states_size; ++i ) { | ||
| - | 445 | iline >> random_states[i]; | ||
| - | 446 | if(!iline) detail::find_event_end( is ); | ||
| - | 447 | } | ||
| - | 448 | WeightContainer::size_type weights_size = 0; | ||
| - | 449 | iline >> weights_size; | ||
| - | 450 | if(!iline) detail::find_event_end( is ); | ||
| - | 451 | std::vector<double> wgt(weights_size); | ||
| - | 452 | for ( WeightContainer::size_type ii = 0; ii < weights_size; ++ii ) { | ||
| - | 453 | iline >> wgt[ii]; | ||
| - | 454 | if(!iline) detail::find_event_end( is ); | ||
| - | 455 | } | ||
| - | 456 | // weight names will be added later if they exist | ||
| - | 457 | if( weights_size > 0 ) m_weights = wgt; | ||
| - | 458 | // | ||
| - | 459 | // fill signal_process_id, event_number, random_states, etc. | ||
| - | 460 | set_signal_process_id( signal_process_id ); | ||
| - | 461 | set_event_number( event_number ); | ||
| - | 462 | set_random_states( random_states ); | ||
| - | 463 | set_event_scale( eventScale ); | ||
| - | 464 | set_alphaQCD( alpha_qcd ); | ||
| - | 465 | set_alphaQED( alpha_qed ); | ||
| - | 466 | // | ||
| - | 467 | return is; | ||
| - | 468 | } | ||
| - | 469 | |||
| - | 470 | std::istream & GenEvent::read_weight_names( std::istream & is ) | ||
| - | 471 | { | ||
| - | 472 | // now check for a named weight line | ||
| - | 473 | if ( !is ) { | ||
| - | 474 | std::cerr << "GenEvent::read_weight_names setting badbit." << std::endl; | ||
| - | 475 | is.clear(std::ios::badbit); | ||
| - | 476 | return is; | ||
| - | 477 | } | ||
| - | 478 | // Test to be sure the next entry is of type "N" | ||
| - | 479 | // If we have no named weight line, this is not an error | ||
| - | 480 | // releases prior to 2.06.00 do not have named weights | ||
| - | 481 | if ( is.peek() !='N') { | ||
| - | 482 | return is; | ||
| - | 483 | } | ||
| - | 484 | // now get this line and process it | ||
| - | 485 | std::string line; | ||
| - | 486 | std::getline(is,line); | ||
| - | 487 | std::istringstream wline(line); | ||
| - | 488 | std::string firstc; | ||
| - | 489 | WeightContainer::size_type name_size = 0; | ||
| - | 490 | wline >> firstc >> name_size; | ||
| - | 491 | if(!wline) detail::find_event_end( is ); | ||
| - | 492 | if( firstc != "N") { | ||
| - | 493 | std::cout << "debug: first character of named weights is " << firstc << std::endl; | ||
| - | 494 | std::cout << "debug: We should never get here" << std::endl; | ||
| - | 495 | is.clear(std::ios::badbit); | ||
| - | 496 | return is; | ||
| - | 497 | } | ||
| - | 498 | if( m_weights.size() != name_size ) { | ||
| - | 499 | std::cout << "debug: weight sizes do not match "<< std::endl; | ||
| - | 500 | std::cout << "debug: weight vector size is " << m_weights.size() << std::endl; | ||
| - | 501 | std::cout << "debug: weight name size is " << name_size << std::endl; | ||
| - | 502 | is.clear(std::ios::badbit); | ||
| - | 503 | return is; | ||
| - | 504 | } | ||
| - | 505 | std::string name; | ||
| - | 506 | std::string::size_type i1 = line.find("\""); | ||
| - | 507 | std::string::size_type i2; | ||
| - | 508 | std::string::size_type len = line.size(); | ||
| - | 509 | WeightContainer namedWeight; | ||
| - | 510 | for ( WeightContainer::size_type ii = 0; ii < name_size; ++ii ) { | ||
| - | 511 | // weight names may contain blanks | ||
| - | 512 | if(i1 >= len) { | ||
| - | 513 | std::cout << "debug: attempting to read past the end of the named weight line " << std::endl; | ||
| - | 514 | std::cout << "debug: We should never get here" << std::endl; | ||
| - | 515 | std::cout << "debug: Looking for the end of this event" << std::endl; | ||
| - | 516 | detail::find_event_end( is ); | ||
| - | 517 | } | ||
| - | 518 | i2 = line.find("\"",i1+1); | ||
| - | 519 | name = line.substr(i1+1,i2-i1-1); | ||
| - | 520 | namedWeight[name] = m_weights[ii]; | ||
| - | 521 | i1 = line.find("\"",i2+1); | ||
| - | 522 | } | ||
| - | 523 | m_weights = namedWeight; | ||
| - | 524 | return is; | ||
| 392 | } | 525 | } | |
| 393 | 526 | |||
| 394 | std::istream & GenEvent::read_units( std::istream & is ) | 527 | std::istream & GenEvent::read_units( std::istream & is ) | |
| 395 | { | 528 | { | |
| 396 | // | 529 | // | |
| 397 | if ( !is ) { | 530 | if ( !is ) { | |
| 398 | std::cerr << "StreamHelpers read_units setting badbit." << std::endl; | - | ||
| - | 531 | std::cerr << "GenEvent::read_units setting badbit." << std::endl; | ||
| 399 | is.clear(std::ios::badbit); | 532 | is.clear(std::ios::badbit); | |
| 400 | return is; | 533 | return is; | |
| 401 | } | 534 | } | |
| 402 | // | 535 | // | |
| 403 | StreamInfo & info = get_stream_info(is); | 536 | StreamInfo & info = get_stream_info(is); | |
