Commit 6f3f59dc authored by Lynn Garren's avatar Lynn Garren
Browse files

replace sprintf with standard ios formatting

parent 6822564f
2006-05-16 Lynn Garren <garren@fnal.gov>
* src/GenEvent.cc: get rid of sprintf
* src/GenEvent.cc,src/GenParticle.cc,src/GenVertex.cc :
replace sprintf with ios formatting
==============================
21.11.05 Release CLHEP-2.0.2.2
......
......@@ -138,7 +138,7 @@ namespace HepMC {
// print a legend to describe the particle info
ostr << " GenParticle Legend\n";
ostr << " Barcode PDG ID "
<< "( Px, Py, Pz, E )"
<< "( Px, Py, Pz, E )"
<< " Stat DecayVtx\n";
ostr << "________________________________________"
<< "________________________________________\n";
......
......@@ -7,7 +7,8 @@
#include "CLHEP/HepMC/GenEvent.h"
#include "CLHEP/HepMC/GenVertex.h"
#include "CLHEP/HepMC/GenParticle.h"
#include <stdio.h> // needed for formatted output using sprintf
#include <iomanip> // needed for formatted output
#include <ios> // needed for ios_base
namespace HepMC {
......@@ -196,33 +197,46 @@ namespace HepMC {
// Friends //
/////////////
std::ostream& operator<<( std::ostream& ostr, const GenParticle& part ) {
char outline[80];
ostr << " ";
ostr.width(9);
ostr << part.barcode();
ostr.width(9);
ostr << part.pdg_id() << " ";
ostr.width(9);
ostr.precision(2);
ostr.setf(std::ios::scientific, std::ios::floatfield);
ostr.setf(std::ios_base::showpos);
ostr << part.momentum().px() << ",";
ostr.width(9);
ostr.precision(2);
ostr << part.momentum().py() << ",";
ostr.width(9);
ostr.precision(2);
ostr << part.momentum().pz() << ",";
ostr.width(9);
ostr.precision(2);
ostr << part.momentum().e() << " ";
//ostr.unsetf(std::ios::scientific, std::ios::floatfield);
ostr.unsetf(std::ios_base::showpos);
if ( part.end_vertex() && part.end_vertex()->barcode()!=0 ) {
sprintf( outline," %9d%9d %+9.2e,%+9.2e,%+9.2e,%+9.2e %3d %9d",
part.barcode(), part.pdg_id(),
part.momentum().px(),part.momentum().py(),
part.momentum().pz(),part.momentum().e(),
part.status(),
part.end_vertex()->barcode() );
ostr.width(3);
ostr << part.status() << " ";
ostr.width(9);
ostr << part.end_vertex()->barcode();
} else if ( !part.end_vertex() ) {
// There is no valid end_vertex
// For consistency across different compilers, do not print anything
sprintf( outline," %9d%9d %+9.2e,%+9.2e,%+9.2e,%+9.2e %3d",
part.barcode(), part.pdg_id(),
part.momentum().px(),part.momentum().py(),
part.momentum().pz(),part.momentum().e(),
part.status() );
ostr.width(3);
ostr << part.status();
} else {
// In this case the end_vertex does not have a unique
// barcode assigned, so we choose instead to print its address
sprintf( outline," %9d%9d %+9.2e,%+9.2e,%+9.2e,%+9.2e %3d %9p",
part.barcode(), part.pdg_id(),
part.momentum().px(),part.momentum().py(),
part.momentum().pz(),part.momentum().e(),
part.status(),
(void*)part.end_vertex() );
ostr.width(3);
ostr << part.status() << " ";
ostr.width(9);
ostr << (void*)part.end_vertex();
}
return ostr << outline;
return ostr;
}
} // HepMC
......
......@@ -6,7 +6,8 @@
#include "CLHEP/HepMC/GenParticle.h"
#include "CLHEP/HepMC/GenVertex.h"
#include "CLHEP/HepMC/GenEvent.h"
#include <stdio.h> // needed for formatted output using sprintf
#include <iomanip> // needed for formatted output
#include <ios> // needed for ios_base
namespace HepMC {
......@@ -124,39 +125,82 @@ namespace HepMC {
}
void GenVertex::print( std::ostream& ostr ) const {
char outline[80];
if ( barcode()!=0 ) {
if ( position() != CLHEP::HepLorentzVector(0,0,0,0) ) {
sprintf( outline,
"Vertex:%9d ID:%5d (X,cT)=%+9.2e,%+9.2e,%+9.2e,%+9.2e"
,barcode(), id(),
position().x(),
position().y(),
position().z(),
position().t() );
ostr << "Vertex:";
ostr.width(9);
ostr << barcode();
ostr << " ID:";
ostr.width(5);
ostr << id();
ostr << " (X,cT)=";
ostr.width(9);
ostr.precision(2);
ostr.setf(std::ios::scientific, std::ios::floatfield);
ostr.setf(std::ios_base::showpos);
ostr << position().x() << ",";
ostr.width(9);
ostr.precision(2);
ostr << position().y() << ",";
ostr.width(9);
ostr.precision(2);
ostr << position().z() << ",";
ostr.width(9);
ostr.precision(2);
ostr << position().t();
//ostr.unsetf(std::ios::scientific, std::ios::floatfield);
ostr.unsetf(std::ios_base::showpos);
ostr << std::endl;
} else {
sprintf( outline, "GenVertex:%9d ID:%5d (X,cT):0",
barcode(), id() );
ostr << "GenVertex:";
ostr.width(9);
ostr << barcode();
ostr << " ID:";
ostr.width(5);
ostr << id();
ostr << " (X,cT):0";
ostr << std::endl;
}
} else {
// If the vertex doesn't have a unique barcode assigned, then
// we print its memory address instead... so that the
// print out gives us a unique tag for the particle.
if ( position() != CLHEP::HepLorentzVector(0,0,0,0) ) {
sprintf( outline,
"Vertex:%9p ID:%5d (X,cT)=%+9.2e,%+9.2e,%+9.2e,%+9.2e"
,(void*)this, id(),
position().x(),
position().y(),
position().z(),
position().t() );
ostr << "Vertex:";
ostr.width(9);
ostr << (void*)this;
ostr << " ID:";
ostr.width(5);
ostr << id();
ostr << " (X,cT)=";
ostr.width(9);
ostr.precision(2);
ostr.setf(std::ios::scientific, std::ios::floatfield);
ostr.setf(std::ios_base::showpos);
ostr << position().x();
ostr.width(9);
ostr.precision(2);
ostr << position().y();
ostr.width(9);
ostr.precision(2);
ostr << position().z();
ostr.width(9);
ostr.precision(2);
ostr << position().t();
ostr.unsetf(std::ios_base::showpos);
ostr << std::endl;
} else {
sprintf( outline, "GenVertex:%9p ID:%5d (X,cT):0",
(void*)this, id() );
ostr << "GenVertex:";
ostr.width(9);
ostr << (void*)this;
ostr << " ID:";
ostr.width(5);
ostr << id();
ostr << " (X,cT):0";
ostr << std::endl;
}
}
ostr << outline << std::endl;
// print the weights if there are any
if ( ! weights().empty() ) {
ostr << " Wgts(" << weights().size() << ")=";
......@@ -168,9 +212,9 @@ namespace HepMC {
for ( particles_in_const_iterator part1 = particles_in_const_begin();
part1 != particles_in_const_end(); part1++ ) {
if ( part1 == particles_in_const_begin() ) {
char label[5];
sprintf( label," I:%2d",m_particles_in.size() );
ostr << label;
ostr << " I:";
ostr.width(2);
ostr << m_particles_in.size();
} else { ostr << " "; }
//(*part1)->print( ostr ); //uncomment for long debugging printout
ostr << **part1 << std::endl;
......@@ -178,9 +222,9 @@ namespace HepMC {
for ( particles_out_const_iterator part2 = particles_out_const_begin();
part2 != particles_out_const_end(); part2++ ) {
if ( part2 == particles_out_const_begin() ) {
char label[5];
sprintf( label," O:%2d",m_particles_out.size() );
ostr << label;
ostr << " O:";
ostr.width(2);
ostr << m_particles_out.size();
} else { ostr << " "; }
//(*part2)->print( ostr ); // uncomment for long debugging printout
ostr << **part2 << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment