00001
00002 #ifndef HEPMC_PARTICLE_DATA_TABLE_H
00003 #define HEPMC_PARTICLE_DATA_TABLE_H
00004
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021 #include <iostream>
00022 #include <map>
00023 #include <cstdio>
00024 #include "HepMC/ParticleData.h"
00025
00026 namespace HepMC {
00027
00029
00035 class ParticleDataTable {
00036
00037 public:
00039 ParticleDataTable( std::string description = std::string() );
00041 ParticleDataTable( const char description );
00043 ParticleDataTable( const ParticleDataTable& );
00045 virtual ~ParticleDataTable();
00047 ParticleDataTable& operator=( const ParticleDataTable& );
00048
00050 void make_antiparticles_from_particles();
00052 int merge_table( const ParticleDataTable& );
00053
00055 void print( std::ostream& ostr = std::cout ) const;
00056
00057 void delete_all();
00058 void clear();
00059
00061 ParticleData* operator[]( int id ) const;
00063 ParticleData* find( int id ) const;
00065 int size() const;
00067 bool empty() const;
00069 bool insert( ParticleData* );
00071 bool erase( ParticleData* );
00073 bool erase( int id );
00075 typedef std::map<int,HepMC::ParticleData*>::iterator iterator;
00077 typedef std::map<int,HepMC::ParticleData*>::const_iterator const_iterator;
00079 iterator begin();
00081 iterator end();
00083 const_iterator begin() const;
00085 const_iterator end() const;
00086
00088
00090
00092 std::string description() const;
00094 void set_description( std::string );
00096 void set_description( const char );
00097
00098 private:
00099 std::string m_description;
00100 std::map<int,HepMC::ParticleData*> m_data_table;
00101 };
00102
00104
00106
00107 inline ParticleDataTable::ParticleDataTable( std::string description )
00108 : m_description(description) {
00109 std::cout << "-------------------------------------------------------" << std::endl;
00110 std::cout << "Use of HepMC/ParticleDataTable is deprecated" << std::endl;
00111 std::cout << "-------------------------------------------------------" << std::endl;
00112 }
00113
00114 inline ParticleDataTable::ParticleDataTable( const char description ) {
00115 m_description = description;
00116
00117 std::cout << "-------------------------------------------------------" << std::endl;
00118 std::cout << "Use of HepMC/ParticleDataTable is deprecated" << std::endl;
00119 std::cout << "-------------------------------------------------------" << std::endl;
00120 }
00121
00122 inline ParticleDataTable::ParticleDataTable( const ParticleDataTable& pdt){
00123 *this = pdt;
00124 }
00125
00126 inline ParticleDataTable::~ParticleDataTable(){}
00127
00128 inline ParticleDataTable& ParticleDataTable::operator=( const
00129 ParticleDataTable&
00130 pdt) {
00131 m_description = pdt.m_description;
00132 m_data_table = pdt.m_data_table;
00133 return *this;
00134 }
00135
00136 inline void ParticleDataTable::make_antiparticles_from_particles() {
00138 ParticleDataTable new_data;
00139 for ( ParticleDataTable::iterator p = begin(); p != end(); ++p ) {
00140 ParticleData* pdata = p->second;
00141 if ( pdata->charge() ) {
00142 new_data.insert( new ParticleData( pdata->name()+"~",
00143 -1*pdata->pdg_id(),
00144 -1.*pdata->charge(),
00145 pdata->mass(),
00146 pdata->clifetime(),
00147 pdata->spin() ));
00148 }
00149 }
00150 merge_table( new_data );
00151 }
00152
00153 inline void ParticleDataTable::print( std::ostream& ostr ) const {
00155
00156 ostr << "________________________________________"
00157 << "________________________________________\n";
00158 ostr << "ParticleData: ***** ParticleDataTable"
00159 << " ***** ( " << size()
00160 << " entries )\n";
00161 ostr << " Description: " << m_description << "\n";
00162 ostr << " PDG ID " << " PARTICLE NAME "
00163 << "CHARGE" << " MASS "
00164 << " C*LIFETIME (CM) " << " SPIN\n";
00165 for ( std::map< int,ParticleData* >::const_iterator pd
00166 = m_data_table.begin(); pd != m_data_table.end(); pd++ ) {
00167 ostr << *(pd->second) << "\n";
00168 }
00169 ostr << "________________________________________"
00170 << "________________________________________" << std::endl;
00171 }
00172
00173 inline ParticleData* ParticleDataTable::find( int id ) const {
00176 std::map<int,ParticleData*>::const_iterator iter
00177 = m_data_table.find(id);
00178 return ( iter == m_data_table.end() ) ? 0 : iter->second;
00179 }
00180
00181 inline ParticleData* ParticleDataTable::operator[]( int id ) const {
00182 return find(id);
00183 }
00184
00185 inline int ParticleDataTable::size() const {
00186 return (int)m_data_table.size();
00187 }
00188
00189 inline bool ParticleDataTable::empty() const {
00190 return (bool)m_data_table.empty();
00191 }
00192
00193 inline bool ParticleDataTable::insert( ParticleData* pdata ) {
00197 if ( m_data_table.count(pdata->pdg_id()) ) return 0;
00198 return ( m_data_table[pdata->pdg_id()] = pdata );
00199 }
00200
00201 inline bool ParticleDataTable::erase( ParticleData* pdata ) {
00204 return (bool)m_data_table.erase( pdata->pdg_id() );
00205 }
00206
00207
00208 inline bool ParticleDataTable::erase( int id ) {
00211 return (bool)m_data_table.erase( id );
00212 }
00213
00214 inline ParticleDataTable::iterator ParticleDataTable::begin() {
00215 return m_data_table.begin();
00216 }
00217
00218 inline ParticleDataTable::iterator ParticleDataTable::end() {
00219 return m_data_table.end();
00220 }
00221
00222 inline ParticleDataTable::const_iterator ParticleDataTable::begin() const {
00223 return m_data_table.begin();
00224 }
00225
00226 inline ParticleDataTable::const_iterator ParticleDataTable::end() const {
00227 return m_data_table.end();
00228 }
00229
00230 inline std::string ParticleDataTable::description() const {
00231 return m_description;
00232 }
00233
00234 inline void ParticleDataTable::set_description( std::string description ) {
00235 m_description = description;
00236 }
00237
00238 inline void ParticleDataTable::set_description( const char description ) {
00239 m_description = description;
00240 }
00241
00242 inline void ParticleDataTable::delete_all() {
00244 for ( std::map<int,ParticleData*>::iterator pd = m_data_table.begin();
00245 pd != m_data_table.end(); pd++) delete pd->second;
00246 clear();
00247 }
00248
00249 inline void ParticleDataTable::clear() { m_data_table.clear(); }
00250
00251 inline int ParticleDataTable::merge_table( const ParticleDataTable& pdt ) {
00256 int count_number_insertions =0;
00257 for ( ParticleDataTable::const_iterator p = pdt.begin();
00258 p != pdt.end(); ++p ) {
00259 if ( insert(p->second) ) ++count_number_insertions;
00260 }
00261 return count_number_insertions;
00262 }
00263
00264 }
00265
00266 #endif // HEPMC_PARTICLE_DATA_TABLE_H
00267
00268
00269
00270