00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "G4ios.hh"
00051 #include "globals.hh"
00052 #include "G4ParticleTable.hh"
00053 #include "G4UImessenger.hh"
00054 #include "G4ParticleMessenger.hh"
00055 #include "G4IonTable.hh"
00056 #include "G4ShortLivedTable.hh"
00057 #include "G4StateManager.hh"
00058
00059
00060 G4ParticleTable* G4ParticleTable::fgParticleTable =0;
00061
00063 G4ParticleTable* G4ParticleTable::GetParticleTable()
00064 {
00065 static G4ParticleTable theParticleTable;
00066 if (!fgParticleTable){
00067 fgParticleTable = &theParticleTable;
00068 }
00069 return fgParticleTable;
00070 }
00071
00073 G4ParticleTable::G4ParticleTable()
00074 :verboseLevel(1),fParticleMessenger(0),
00075 noName(" "),
00076 readyToUse(false)
00077 {
00078 fDictionary = new G4PTblDictionary();
00079 fIterator = new G4PTblDicIterator( *fDictionary );
00080 fEncodingDictionary = new G4PTblEncodingDictionary();
00081
00082
00083 fIonTable = new G4IonTable();
00084
00085
00086 fShortLivedTable = new G4ShortLivedTable();
00087 }
00088
00090 G4ParticleTable::~G4ParticleTable()
00091 {
00092 readyToUse = false;
00093
00094
00095 RemoveAllParticles();
00096
00097
00098 if (fShortLivedTable!=0) delete fShortLivedTable;
00099 fShortLivedTable =0;
00100
00101
00102
00103 if (fIonTable!=0) delete fIonTable;
00104 fIonTable =0;
00105
00106
00107 if (fEncodingDictionary!=0){
00108 fEncodingDictionary -> clear();
00109 delete fEncodingDictionary;
00110 fEncodingDictionary =0;
00111 }
00112
00113 if(fDictionary){
00114 if (fIterator!=0 )delete fIterator;
00115 fIterator =0;
00116
00117 fDictionary->clear();
00118 delete fDictionary;
00119 fDictionary =0;
00120 }
00121
00122 if (fParticleMessenger!=0) delete fParticleMessenger;
00123 fParticleMessenger =0;
00124
00125 fgParticleTable =0;
00126
00127 }
00128
00130 G4ParticleTable::G4ParticleTable(const G4ParticleTable &right)
00131 :verboseLevel(1),fParticleMessenger(0),
00132 noName(" "),
00133 readyToUse(false)
00134 {
00135 G4Exception("G4ParticleTable::G4ParticleTable()",
00136 "PART001", FatalException,
00137 "Illegal call of copy constructor for G4ParticleTable");
00138 fDictionary = new G4PTblDictionary(*(right.fDictionary));
00139 fIterator = new G4PTblDicIterator(*fDictionary);
00140 }
00141
00143 G4ParticleTable & G4ParticleTable::operator=(const G4ParticleTable & right)
00144 {
00145 if (this != &right) {
00146 G4Exception("G4ParticleTable::G4ParticleTable()",
00147 "PART001", FatalException,
00148 "Illegal call of assignment operator for G4ParticleTable");
00149 fDictionary = new G4PTblDictionary(*(right.fDictionary));
00150 fIterator = new G4PTblDicIterator(*fDictionary);
00151 }
00152 return *this;
00153 }
00154
00156 G4UImessenger* G4ParticleTable::CreateMessenger()
00157 {
00158 if (fParticleMessenger== 0) {
00159
00160 fParticleMessenger = new G4ParticleMessenger(this);
00161 }
00162 return fParticleMessenger;
00163 }
00164
00166 void G4ParticleTable::DeleteMessenger()
00167 {
00168 if (fParticleMessenger!= 0) {
00169
00170 delete fParticleMessenger;
00171 fParticleMessenger= 0;
00172 }
00173
00174 }
00175
00177 void G4ParticleTable::DeleteAllParticles()
00178 {
00179
00180 readyToUse = false;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 #ifdef G4VERBOSE
00191 if (verboseLevel>1){
00192 G4cout << "G4ParticleTable::DeleteAllParticles() " << G4endl;
00193 }
00194 #endif
00195
00196
00197 G4PTblDicIterator *piter = fIterator;
00198 piter -> reset();
00199 while( (*piter)() ){
00200 #ifdef G4VERBOSE
00201 if (verboseLevel>2){
00202 G4cout << "Delete " << (piter->value())->GetParticleName()
00203 << " " << (piter->value()) << G4endl;
00204 }
00205 #endif
00206 delete (piter->value());
00207 }
00208 RemoveAllParticles();
00209 }
00210
00212 void G4ParticleTable::RemoveAllParticles()
00213 {
00214 if (readyToUse) {
00215 G4Exception("G4ParticleTable::RemoveAllParticle()",
00216 "PART115", JustWarning,
00217 "No effects because readyToUse is true.");
00218 return;
00219 }
00220
00221 #ifdef G4VERBOSE
00222 if (verboseLevel>1){
00223 G4cout << "G4ParticleTable::RemoveAllParticles() " << G4endl;
00224 }
00225 #endif
00226
00227
00228 if (fIonTable!=0) {
00229 fIonTable->clear();
00230 }
00231
00232
00233 if (fShortLivedTable!=0) {
00234 fShortLivedTable->clear();
00235 }
00236
00237
00238 if (fEncodingDictionary) {
00239 fEncodingDictionary->clear();
00240 }
00241
00242
00243 if (fDictionary) {
00244 fDictionary->clear();
00245 }
00246 }
00247
00249 G4ParticleDefinition* G4ParticleTable::Insert(G4ParticleDefinition *particle)
00250 {
00251
00252
00253 if ((particle == 0) || (GetKey(particle).isNull())) {
00254 #ifdef G4VERBOSE
00255 if (verboseLevel>0){
00256 G4cerr << "The particle[Addr:" << particle << "] has no name "<< G4endl;
00257 }
00258 #endif
00259 return 0;
00260
00261 }else {
00262
00263 if (contains(particle)) {
00264 #ifdef G4VERBOSE
00265 if (verboseLevel>0){
00266 G4cerr << "The particle " << particle->GetParticleName()
00267 << "has been already registered in the Particle Table "<< G4endl;
00268 }
00269 if (verboseLevel>1){
00270 FindParticle(particle) -> DumpTable();
00271 }
00272 #endif
00273 return FindParticle(particle);
00274
00275 } else {
00276 G4PTblDictionary *pdic = fDictionary;
00277 G4PTblEncodingDictionary *pedic = fEncodingDictionary;
00278
00279
00280 pdic->insert( std::pair<G4String, G4ParticleDefinition*>(GetKey(particle), particle) );
00281
00282
00283 G4int code = particle->GetPDGEncoding();
00284 if (code !=0 ) {
00285 pedic->insert( std::pair<G4int, G4ParticleDefinition*>(code ,particle) );
00286 }
00287
00288
00289 if (fIonTable->IsIon(particle) ){
00290 fIonTable->Insert(particle);
00291 }
00292
00293
00294 if (particle->IsShortLived() ){
00295 fShortLivedTable->Insert(particle);
00296 }
00297
00298
00299 particle->SetVerboseLevel(verboseLevel);
00300
00301 #ifdef G4VERBOSE
00302 if (verboseLevel>3){
00303 G4cout << "The particle "<< particle->GetParticleName()
00304 << " is inserted in the ParticleTable " << G4endl;
00305 }
00306 #endif
00307
00308 return particle;
00309 }
00310 }
00311 }
00312
00314 G4ParticleDefinition* G4ParticleTable::Remove(G4ParticleDefinition* particle)
00315 {
00316 if (readyToUse) {
00317 G4StateManager* pStateManager = G4StateManager::GetStateManager();
00318 G4ApplicationState currentState = pStateManager->GetCurrentState();
00319 if (currentState != G4State_PreInit) {
00320 G4String msg = "Request of removing ";
00321 msg += particle->GetParticleName();
00322 msg += " has No effects other than Pre_Init";
00323 G4Exception("G4ParticleTable::Remove()",
00324 "PART117", JustWarning, msg);
00325 return 0;
00326 } else {
00327 #ifdef G4VERBOSE
00328 if (verboseLevel>0){
00329 G4cout << particle->GetParticleName()
00330 << " will be removed from the ParticleTable " << G4endl;
00331 }
00332 #endif
00333 }
00334 }
00335
00336 G4PTblDictionary::iterator it = fDictionary->find(GetKey(particle));
00337 if (it != fDictionary->end()) {
00338 fDictionary->erase(it);
00339
00340 G4int code = particle->GetPDGEncoding();
00341 if (code !=0 ) {
00342 fEncodingDictionary->erase(fEncodingDictionary->find(code));
00343 }
00344 } else {
00345 return 0;
00346 }
00347
00348
00349 if (fIonTable->IsIon(particle) ){
00350 fIonTable->Remove(particle);
00351 }
00352
00353
00354 if (particle->IsShortLived() ){
00355 fShortLivedTable->Remove(particle);
00356 }
00357
00358 #ifdef G4VERBOSE
00359 if (verboseLevel>3){
00360 G4cout << "The particle "<< particle->GetParticleName()
00361 << " is removed from the ParticleTable " << G4endl;
00362 }
00363 #endif
00364
00365 return particle;
00366 }
00367
00369 G4ParticleDefinition* G4ParticleTable::FindIon(G4int Z, G4int A, G4int , G4int )
00370 {
00371 CheckReadiness();
00372 if (Z<=0) return 0;
00373 if (A<Z) return 0;
00374 return fIonTable->GetIon(Z, A);
00375 }
00376
00378 G4ParticleDefinition* G4ParticleTable::GetIon(G4int Z, G4int A, G4double E)
00379 {
00380 CheckReadiness();
00381 if (Z<=0) return 0;
00382 if (A<Z) return 0;
00383 if (E<0.) return 0;
00384 return fIonTable->GetIon(Z, A, E);
00385 }
00386
00388 G4ParticleDefinition* G4ParticleTable::GetIon(G4int Z, G4int A, G4int L, G4double E)
00389 {
00390 CheckReadiness();
00391 if (Z<=0) return 0;
00392 if (A-L<Z) return 0;
00393 if (L<0) return 0;
00394 if (E<0.) return 0;
00395 return fIonTable->GetIon(Z, A, L, E);
00396 }
00397
00399 G4ParticleDefinition* G4ParticleTable::FindIon(G4int Z, G4int A, G4double E)
00400 {
00401 CheckReadiness();
00402 if (Z<=0) return 0;
00403 if (A<Z) return 0;
00404 if (E<0.) return 0;
00405 return fIonTable->FindIon(Z, A, E);
00406 }
00407
00409 G4ParticleDefinition* G4ParticleTable::FindIon(G4int Z, G4int A, G4int L, G4double E)
00410 {
00411 CheckReadiness();
00412 if (Z<=0) return 0;
00413 if (A-L<Z) return 0;
00414 if (L<0) return 0;
00415 if (E<0.) return 0;
00416 return fIonTable->FindIon(Z, A, L, E);
00417 }
00418
00420 G4ParticleDefinition* G4ParticleTable::GetParticle(G4int index)
00421 {
00422 CheckReadiness();
00423 if ( (index >=0) && (index < entries()) ) {
00424 G4PTblDicIterator *piter = fIterator;
00425 piter -> reset();
00426 G4int counter = 0;
00427 while( (*piter)() ){
00428 if ( counter == index ) return piter->value();
00429 counter++;
00430 }
00431 }
00432 #ifdef G4VERBOSE
00433 if (verboseLevel>1){
00434 G4cerr << " G4ParticleTable::GetParticle"
00435 << " invalid index (=" << index << ")" << G4endl;
00436 }
00437 #endif
00438 return 0;
00439 }
00440
00442 const G4String& G4ParticleTable::GetParticleName(G4int index)
00443 {
00444 G4ParticleDefinition* aParticle =GetParticle(index);
00445 if (aParticle != 0) {
00446 return aParticle->GetParticleName();
00447 } else {
00448 return noName;
00449 }
00450 }
00451
00453 G4ParticleDefinition* G4ParticleTable::FindParticle(const G4String &particle_name)
00454 {
00455 G4PTblDictionary::iterator it = fDictionary->find(particle_name);
00456 if (it != fDictionary->end()) {
00457 return (*it).second;
00458 } else {
00459 return 0;
00460 }
00461 }
00462
00464 G4ParticleDefinition* G4ParticleTable::FindParticle(const G4ParticleDefinition *particle)
00465 {
00466 CheckReadiness();
00467 G4String key = GetKey(particle);
00468 return FindParticle(key);
00469 }
00470
00472 G4ParticleDefinition* G4ParticleTable::FindParticle(G4int aPDGEncoding )
00473 {
00474 CheckReadiness();
00475
00476 if (aPDGEncoding == 0){
00477 #ifdef G4VERBOSE
00478 if (verboseLevel>1){
00479 G4cerr << "PDGEncoding [" << aPDGEncoding << "] is not valid " << G4endl;
00480 }
00481 #endif
00482 return 0;
00483 }
00484
00485 G4PTblEncodingDictionary *pedic = fEncodingDictionary;
00486 G4ParticleDefinition* particle =0;
00487
00488 G4PTblEncodingDictionary::iterator it = pedic->find(aPDGEncoding );
00489 if (it != pedic->end()) {
00490 particle = (*it).second;
00491 }
00492
00493 #ifdef G4VERBOSE
00494 if ((particle == 0) && (verboseLevel>1) ){
00495 G4cerr << "CODE:" << aPDGEncoding << " does not exist in ParticleTable " << G4endl;
00496 }
00497 #endif
00498 return particle;
00499 }
00500
00502 void G4ParticleTable::DumpTable(const G4String &particle_name)
00503 {
00504 CheckReadiness();
00505 if (( particle_name == "ALL" ) || (particle_name == "all")){
00506
00507 G4PTblDicIterator *piter = fIterator;
00508 piter -> reset();
00509 while( (*piter)() ){
00510 (piter->value())->DumpTable();
00511 }
00512 } else {
00513
00514 G4ParticleDefinition *ptr;
00515 ptr = FindParticle(particle_name);
00516 if ( ptr != 0) {
00517 ptr->DumpTable();
00518 } else {
00519 G4cerr << " G4ParticleTable::DumpTable : "
00520 << particle_name << " does not exist in ParticleTable " <<G4endl;
00521 }
00522 }
00523 }
00524
00525 void G4ParticleTable::CheckReadiness()
00526 {
00527 if(!readyToUse) {
00528 G4String msg;
00529 msg = "Illegal use of G4ParticleTable : ";
00530 msg += " Access to G4ParticleTable for finding a particle or equivalent\n";
00531 msg += "operation occurs before G4VUserPhysicsList is instantiated and\n";
00532 msg += "assigned to G4RunManager. Such an access is prohibited by\n";
00533 msg += "Geant4 version 8.0. To fix this problem, please make sure that\n";
00534 msg += "your main() instantiates G4VUserPhysicsList and set it to\n";
00535 msg += "G4RunManager before instantiating other user classes such as\n";
00536 msg += "G4VUserPrimaryParticleGeneratorAction.";
00537 G4Exception("G4ParticleTable::CheckReadiness()",
00538 "PART002",FatalException,msg);
00539 }
00540 }
00541
00542
00543