TableBuilderT.icc 4.29 KB
Newer Older
Lynn Garren's avatar
Lynn Garren committed
1
// $Id: TableBuilderT.icc,v 1.2.2.1 2004/05/19 22:23:34 garren Exp $
2
3
4
5
6
7
8
// ----------------------------------------------------------------------
//
// TableBuilderT.icc
// Author: Lynn Garren
//
// ----------------------------------------------------------------------

9
#include "CLHEP/HepPDT/defs.h"
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#if HAVE_SSTREAM
#include <sstream>
#else
#include "CLHEP/HepPDT/StringStream.h"
#endif

namespace HepPDT {

template< class Config >
void TableBuilderT<Config>::fillPDT()
{ ; }

template< class Config >
void  TableBuilderT<Config>::reverseEngineer()
{ ; }

template< class Config >
TempParticleData &   TableBuilderT<Config>::getParticleData( ParticleID pid )  
{
  TempMap::iterator it = tempPDT.find( pid );
Lynn Garren's avatar
Lynn Garren committed
30
31
32
33
34
35
36
37
38
  // for some reason, Solaris CC can't cope with the more compact code
  if ( it == tempPDT.end() ) {
     return tempPDT[pid] = TempParticleData(pid);
  } else {
     return it->second;   
  }
  //return ( it == tempPDT.end() )
  //     ?  tempPDT[pid] = TempParticleData(pid)  // new one
  //     :  it->second;                           // old one
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
}

template< class Config >
TempParticleData &  TableBuilderT<Config>::getParticleData( std::string const & name )  
{
    TempIDMap::iterator it = tempIDT.find( name );
    if( it == tempIDT.end() ) {
        // can neither build nor return a proper TempParticleData
	os << "HepPDT::TableBuilder.getParticleData: There is no entry for " << name << std::endl;
        exit(-3);
    }
    ParticleID pid = it->second;
    return getParticleData( pid );
}

template< class Config >
TempParticleData &  TableBuilderT<Config>::getAntiParticle( ParticleID pid, 
                                                    const std::string & aname )
{
    // is it already here?
    ParticleID apid = ParticleID( -pid.pid() );
    TempMap::iterator it = tempPDT.find( apid );
    if( it != tempPDT.end() ) {
        return it->second;
    }
    // check for original particle to copy
    it = tempPDT.find( pid );
    if( it == tempPDT.end() ) {
        // no particle to copy
	TempParticleData atpd = getParticleData( apid );
	atpd.tempParticleName = aname;
	return tempPDT[apid] = atpd;	// getParticleData already added it to the map
    } else {
        // copy original
	TempParticleData tpd = it->second;
	TempParticleData atpd = tpd.antiparticle( aname );
        return tempPDT[apid] = atpd;	// add to map and return
    }
}

template< class Config >
bool TableBuilderT<Config>::hasParticleData( std::string const & name )
{
    TempIDMap::iterator it = tempIDT.find( name );
    return ( it == tempIDT.end() ) ?  false  : true;
}

template< class Config >
bool TableBuilderT<Config>::hasAlias( std::string const & alias )
{
    TempAliasMap::iterator it = tempAliases.find( alias );
    return ( it == tempAliases.end() ) ?  false  : true;
}

template< class Config >
void  TableBuilderT<Config>::addParticle( TempParticleData const & pd )  {
  getParticleData( pd.tempID ) = pd;
  if( !hasParticleData( pd.tempParticleName ) ) {
      tempIDT[pd.tempParticleName] = pd.tempID;
  }
}


template< class Config >
void TableBuilderT<Config>::addAlias( TempAliasData const & ad )
{
    std::string alias = ad.tempAlias;
    tempAliases[alias] = ad;
}

template< class Config >
TempAliasData& TableBuilderT<Config>::aliasData( std::string const & alias )
{
    TempAliasMap::iterator it = tempAliases.find( alias );
    if( it == tempAliases.end() ) {
        // can neither build nor return a proper TempParticleData
	os << "HepPDT::TableBuilder.aliasData: There is no entry for " 
                       << alias << std::endl;
        exit(-4);
    }
    return it->second;
}

// --- free functions
//

void getPDGpid( std::vector<int> & idlist,  std::string & pdline );
void parsePDGline( TempParticleData & tpd,  std::string & pdline );

template< class Config >
bool  addPDGParticles( std::istream & pdfile, TableBuilderT<Config> & tb )
{
  // mass and width lines can be in any order
  std::vector<int> idlist;
  std::string pdline;
  // read and parse each line
  while( std::getline( pdfile, pdline) ) {
    getPDGpid( idlist, pdline );
    for( unsigned int i = 0; i < idlist.size(); ++i )
    {
        TempParticleData& tpd = tb.getParticleData( ParticleID( idlist[i] ) );
        parsePDGline( tpd, pdline );
    }
  }
  std::cout << "found " << tb.size() << " particles" << std::endl;
  return true;
}

}  // namespace HepPDT