hepmc - Diff between revs 128 and 147
Subversion Repositories:
| Rev 128 | Rev 147 | |||
|---|---|---|---|---|
| Line 34... | Line 34... | |||
| 34 | set_flow(itsflow); | 34 | set_flow(itsflow); | |
| 35 | s_counter++; | 35 | s_counter++; | |
| 36 | } | 36 | } | |
| 37 | 37 | |||
| 38 | GenParticle::GenParticle( const GenParticle& inparticle ) : | 38 | GenParticle::GenParticle( const GenParticle& inparticle ) : | |
| 39 | m_pdg_id(0), m_status(0), m_flow(this), | - | ||
| 40 | m_production_vertex(0), m_end_vertex(0), m_barcode(0), | - | ||
| 41 | m_generated_mass(0.) | - | ||
| - | 39 | m_momentum( inparticle.momentum() ), | ||
| - | 40 | m_pdg_id( inparticle.pdg_id() ), | ||
| - | 41 | m_status( inparticle.status() ), | ||
| - | 42 | m_flow(this), | ||
| - | 43 | m_polarization( inparticle.polarization() ), | ||
| - | 44 | m_production_vertex(0), | ||
| - | 45 | m_end_vertex(0), | ||
| - | 46 | m_barcode(0), | ||
| - | 47 | m_generated_mass( inparticle.generated_mass() ), | ||
| - | 48 | m_serialnumber( inparticle.serialnumber() ) | ||
| 42 | { | 49 | { | |
| 43 | /// Shallow copy: does not copy the vertex pointers | 50 | /// Shallow copy: does not copy the vertex pointers | |
| 44 | /// (note - impossible to copy vertex pointers which having the vertex | 51 | /// (note - impossible to copy vertex pointers which having the vertex | |
| 45 | /// and particles in/out point-back to one another -- unless you | 52 | /// and particles in/out point-back to one another -- unless you | |
| 46 | /// copy the entire tree -- which we don't want to do) | 53 | /// copy the entire tree -- which we don't want to do) | |
| 47 | *this = inparticle; | - | ||
| - | 54 | set_production_vertex_( 0 ); | ||
| - | 55 | set_end_vertex_( 0 ); | ||
| - | 56 | suggest_barcode( inparticle.barcode() ); | ||
| 48 | s_counter++; | 57 | s_counter++; | |
| 49 | } | 58 | } | |
| 50 | 59 | |||
| 51 | GenParticle::~GenParticle() { | 60 | GenParticle::~GenParticle() { | |
| 52 | if ( parent_event() ) parent_event()->remove_barcode(this); | 61 | if ( parent_event() ) parent_event()->remove_barcode(this); | |
| 53 | s_counter--; | 62 | s_counter--; | |
| - | 63 | } | ||
| - | 64 | |||
| - | 65 | void GenParticle::swap( GenParticle & other) | ||
| - | 66 | { | ||
| - | 67 | // if a container has a swap method, use that for improved performance | ||
| - | 68 | m_momentum.swap( other.m_momentum ); | ||
| - | 69 | std::swap( m_pdg_id, other.m_pdg_id ); | ||
| - | 70 | std::swap( m_status, other.m_status ); | ||
| - | 71 | m_flow.swap( other.m_flow ); | ||
| - | 72 | m_polarization.swap( other.m_polarization ); | ||
| - | 73 | std::swap( m_production_vertex, other.m_production_vertex ); | ||
| - | 74 | std::swap( m_end_vertex, other.m_end_vertex ); | ||
| - | 75 | std::swap( m_barcode, other.m_barcode ); | ||
| - | 76 | std::swap( m_generated_mass, other.m_generated_mass ); | ||
| - | 77 | std::swap( m_serialnumber, other.m_serialnumber ); | ||
| 54 | } | 78 | } | |
| 55 | 79 | |||
| 56 | GenParticle& GenParticle::operator=( const GenParticle& inparticle ) { | 80 | GenParticle& GenParticle::operator=( const GenParticle& inparticle ) { | |
| 57 | /// Shallow: does not copy the vertex pointers | 81 | /// Shallow: does not copy the vertex pointers | |
| 58 | /// (note - impossible to copy vertex pointers which having the vertex | 82 | /// (note - impossible to copy vertex pointers which having the vertex | |
| 59 | /// and particles in/out point-back to one another -- unless you | 83 | /// and particles in/out point-back to one another -- unless you | |
| 60 | /// copy the entire tree -- which we don't want to do) | 84 | /// copy the entire tree -- which we don't want to do) | |
| 61 | // Protect against self assignment | - | ||
| 62 | // This works, but is not best practices | - | ||
| 63 | // Best practices involves a rewrite to use the copy constructor and swap | - | ||
| 64 | if( this != &inparticle ) { | - | ||
| 65 | set_momentum( inparticle.momentum() ); | - | ||
| 66 | set_pdg_id( inparticle.pdg_id() ); | - | ||
| 67 | set_status( inparticle.status() ); | - | ||
| 68 | set_production_vertex_( 0 ); | - | ||
| 69 | set_end_vertex_( 0 ); | - | ||
| 70 | set_flow(inparticle.m_flow); | - | ||
| 71 | set_polarization( inparticle.polarization() ); | - | ||
| 72 | suggest_barcode( inparticle.barcode() ); | - | ||
| 73 | set_generated_mass( inparticle.generated_mass() ); | - | ||
| 74 | } | - | ||
| - | 85 | |||
| - | 86 | // best practices implementation | ||
| - | 87 | GenParticle tmp( inparticle ); | ||
| - | 88 | swap( tmp ); | ||
| 75 | return *this; | 89 | return *this; | |
| 76 | } | 90 | } | |
| 77 | 91 | |||
| 78 | bool GenParticle::operator==( const GenParticle& a ) const { | 92 | bool GenParticle::operator==( const GenParticle& a ) const { | |
| 79 | /// consistent with the definition of the copy constructor as a shallow | 93 | /// consistent with the definition of the copy constructor as a shallow | |
