Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4ParticleTable class implementation << 27 // 26 // 28 // Authors: G.Cosmo, 2 December 1995 - Design, << 27 // $Id: G4ParticleTable.cc,v 1.27 2006/06/29 19:26:05 gunter Exp $ 29 // H.Kurashige, 27 June 1996 - First << 28 // GEANT4 tag $Name: geant4-08-02 $ 30 // History: << 31 // - 14 Nov 1997, H.Kurashige - Added messenge << 32 // - 24 Sep 1998, H.Kurashige - Added dictiona << 33 // - 28 Oct 1999, H.Kurashige - Migration to S << 34 // - 15 Sep 2017, K.L.Genser - Added support f << 35 // ------------------------------------------- << 36 << 37 #include "G4ParticleTable.hh" << 38 << 39 #include "G4IonTable.hh" << 40 #include "G4ParticleMessenger.hh" << 41 #include "G4StateManager.hh" << 42 #include "G4UImessenger.hh" << 43 #include "G4ios.hh" << 44 #include "globals.hh" << 45 << 46 // These fields should be thread local or thre << 47 // class, we can change any member field as st << 48 // because there is only one instance. Then we << 49 // "G4ThreadLocal" << 50 // 29 // 51 G4ThreadLocal G4ParticleTable::G4PTblDictionar << 30 // class G4ParticleTable 52 G4ThreadLocal G4ParticleTable::G4PTblDicIterat << 53 G4ThreadLocal G4ParticleTable::G4PTblEncodingD << 54 nullptr; << 55 << 56 // These shadow pointers are used by each work << 57 // from the master thread << 58 // 31 // 59 G4ParticleTable::G4PTblDictionary* G4ParticleT << 32 // Implementation 60 G4ParticleTable::G4PTblDicIterator* G4Particle << 61 G4ParticleTable::G4PTblEncodingDictionary* G4P << 62 << 63 // Static class variable: pointer to single in << 64 // 33 // 65 G4ParticleTable* G4ParticleTable::fgParticleTa << 34 // History: >> 35 // modified Apr., 97 H.Kurashige >> 36 // added fParticleMessenger 14 Nov., 97 H.Kurashige >> 37 // added GetParticle() 13 Dec., 97 H.Kurashige >> 38 // added IonTable and ShortLivedTable 27 June, 98 H.Kurashige >> 39 // modified FindIon 02 Aug., 98 H.Kurashige >> 40 // added dictionary for encoding 24 Sep., 98 H.Kurashige >> 41 // fixed bugs in destruction of IonTable 08 Nov.,98 H.Kurashige >> 42 // commented out G4cout/G4cout in the constructor 10 Nov.,98 H.Kurashige >> 43 // -------------------------------- >> 44 // modified destructor for STL interface 18 May 1999 >> 45 // fixed some improper codings 08 Apr., 99 H.Kurashige >> 46 // modified FindIon/GetIon methods 17 AUg., 99 H.Kurashige >> 47 // implement new version for using STL map instaed of >> 48 // RW PtrHashedDictionary 28 ct., 99 H.Kurashige 66 49 67 #ifdef G4MULTITHREADED << 68 // Lock for particle table accesses. << 69 // << 70 G4Mutex& G4ParticleTable::particleTableMutex() << 71 { << 72 static G4Mutex _instance = G4MUTEX_INITIALIZ << 73 return _instance; << 74 } << 75 G4int& G4ParticleTable::lockCount() << 76 { << 77 static G4int _instance = 0; << 78 return _instance; << 79 } << 80 #endif << 81 50 82 G4ParticleTable* G4ParticleTable::GetParticleT << 51 #include "G4ios.hh" 83 { << 52 #include "globals.hh" 84 if (fgParticleTable == nullptr) { << 53 #include "G4ParticleTable.hh" 85 static G4ParticleTable theParticleTable; << 54 #include "G4UImessenger.hh" 86 fgParticleTable = &theParticleTable; << 55 #include "G4ParticleMessenger.hh" 87 } << 56 #include "G4IonTable.hh" 88 << 57 #include "G4ShortLivedTable.hh" 89 // Here we initialize all thread private dat << 90 // << 91 if (fDictionary == nullptr) fgParticleTable- << 92 58 93 return fgParticleTable; << 94 } << 95 59 >> 60 //////////////////// 96 G4ParticleTable::G4ParticleTable() 61 G4ParticleTable::G4ParticleTable() >> 62 :verboseLevel(0),fParticleMessenger(0), >> 63 noName(" "), >> 64 readyToUse(false) 97 { 65 { 98 fDictionary = new G4PTblDictionary(); 66 fDictionary = new G4PTblDictionary(); 99 << 67 fIterator = new G4PTblDicIterator( *fDictionary ); 100 // Set up the shadow pointer used by worker << 101 // << 102 if (fDictionaryShadow == nullptr) { << 103 fDictionaryShadow = fDictionary; << 104 } << 105 << 106 fIterator = new G4PTblDicIterator(*fDictiona << 107 << 108 // Set up the shadow pointer used by worker << 109 // << 110 if (fIteratorShadow == nullptr) { << 111 fIteratorShadow = fIterator; << 112 } << 113 << 114 fEncodingDictionary = new G4PTblEncodingDict 68 fEncodingDictionary = new G4PTblEncodingDictionary(); 115 // Set up the shadow pointer used by worker << 116 // << 117 if (fEncodingDictionaryShadow == nullptr) { << 118 fEncodingDictionaryShadow = fEncodingDicti << 119 } << 120 69 121 // Ion Table << 70 // Ion Table 122 // << 123 fIonTable = new G4IonTable(); 71 fIonTable = new G4IonTable(); 124 fParticleMessenger = nullptr; << 125 } << 126 72 127 // This method is similar to the constructor. << 73 // short lived table 128 // thread to achieve the partial effect as tha << 74 fShortLivedTable = new G4ShortLivedTable(); 129 // Here we initialize all thread private data << 130 void G4ParticleTable::WorkerG4ParticleTable() << 131 { << 132 // The iterator for the shadow particle tabl << 133 // << 134 #ifdef G4MULTITHREADED << 135 G4MUTEXLOCK(&G4ParticleTable::particleTableM << 136 G4ParticleTable::lockCount()++; << 137 #endif << 138 if (fDictionary == nullptr) { << 139 fDictionary = new G4PTblDictionary(); << 140 } << 141 else { << 142 fDictionary->clear(); << 143 } << 144 << 145 if (fEncodingDictionary == nullptr) { << 146 fEncodingDictionary = new G4PTblEncodingDi << 147 } << 148 else { << 149 fEncodingDictionary->clear(); << 150 } << 151 << 152 fIteratorShadow->reset(false); << 153 while ((*fIteratorShadow)()) // Loop checki << 154 { << 155 G4ParticleDefinition* particle = fIterator << 156 fDictionary->insert(std::pair<G4String, G4 << 157 G4int code = particle->GetPDGEncoding(); << 158 if (code != 0) { << 159 fEncodingDictionary->insert(std::pair<G4 << 160 } << 161 } << 162 fIterator = new G4PTblDicIterator(*fDictiona << 163 << 164 #ifdef G4MULTITHREADED << 165 G4MUTEXUNLOCK(&G4ParticleTable::particleTabl << 166 #endif << 167 << 168 fIonTable->WorkerG4IonTable(); << 169 } 75 } 170 76 >> 77 >> 78 //////////////////// 171 G4ParticleTable::~G4ParticleTable() 79 G4ParticleTable::~G4ParticleTable() 172 { 80 { 173 readyToUse = false; << 81 >> 82 // remove all items from G4ParticleTable >> 83 RemoveAllParticles(); >> 84 >> 85 // delete Short Lived table >> 86 if (fShortLivedTable!=0) delete fShortLivedTable; >> 87 fShortLivedTable =0; 174 88 175 // remove all items from G4ParticleTable << 176 RemoveAllParticles(); << 177 89 178 // delete Ion Table << 90 //delete Ion Table 179 delete fIonTable; << 91 if (fIonTable!=0) delete fIonTable; 180 fIonTable = nullptr; << 92 fIonTable =0; 181 93 182 // delete dictionary for encoding 94 // delete dictionary for encoding 183 if (fEncodingDictionary != nullptr) { << 95 if (fEncodingDictionary!=0){ 184 fEncodingDictionary->clear(); << 96 fEncodingDictionary -> clear(); 185 delete fEncodingDictionary; 97 delete fEncodingDictionary; 186 fEncodingDictionary = nullptr; << 98 fEncodingDictionary =0; 187 } 99 } 188 100 189 if (fDictionary != nullptr) { << 101 if(fDictionary){ 190 delete fIterator; << 191 fIterator = nullptr; << 192 << 193 fDictionary->clear(); 102 fDictionary->clear(); 194 delete fDictionary; 103 delete fDictionary; 195 fDictionary = nullptr; << 104 fDictionary =0; >> 105 if (fIterator!=0 )delete fIterator; >> 106 fIterator =0; 196 } 107 } 197 108 198 delete fParticleMessenger; << 109 if (fParticleMessenger!=0) delete fParticleMessenger; 199 fParticleMessenger = nullptr; << 110 fParticleMessenger =0; 200 111 201 fgParticleTable = nullptr; << 112 fgParticleTable =0; 202 113 203 G4ParticleDefinition::Clean(); // Delete su << 204 } 114 } 205 115 206 void G4ParticleTable::DestroyWorkerG4ParticleT << 116 //////////////////// >> 117 G4ParticleTable::G4ParticleTable(const G4ParticleTable &right) 207 { 118 { 208 // delete Ion Table in worker thread << 119 G4Exception("G4ParticleTable::G4ParticleTable()", 209 if (fIonTable != nullptr) fIonTable->Destroy << 120 "illegal constructor call", JustWarning, >> 121 "you call copy constructor of G4ParticleTable"); >> 122 fDictionary = new G4PTblDictionary(*(right.fDictionary)); >> 123 fIterator = new G4PTblDicIterator(*fDictionary); >> 124 } 210 125 211 // delete dictionary for encoding << 212 if (fEncodingDictionary != nullptr) { << 213 fEncodingDictionary->clear(); << 214 delete fEncodingDictionary; << 215 fEncodingDictionary = nullptr; << 216 } << 217 126 218 if (fDictionary != nullptr) { << 219 delete fIterator; << 220 fIterator = nullptr; << 221 127 222 fDictionary->clear(); << 128 // Static class variable: ptr to single instance of class 223 delete fDictionary; << 129 G4ParticleTable* G4ParticleTable::fgParticleTable =0; 224 fDictionary = nullptr; << 130 225 } << 131 //////////////////// >> 132 G4ParticleTable* G4ParticleTable::GetParticleTable() >> 133 { >> 134 static G4ParticleTable theParticleTable; >> 135 if (!fgParticleTable){ >> 136 fgParticleTable = &theParticleTable; >> 137 } >> 138 return fgParticleTable; 226 } 139 } 227 140 >> 141 //////////////////// 228 G4UImessenger* G4ParticleTable::CreateMessenge 142 G4UImessenger* G4ParticleTable::CreateMessenger() 229 { 143 { 230 if (fParticleMessenger == nullptr) { << 144 if (fParticleMessenger== 0) { 231 // UI messenger << 145 //UI messenger 232 fParticleMessenger = new G4ParticleMesseng 146 fParticleMessenger = new G4ParticleMessenger(this); 233 } 147 } 234 return fParticleMessenger; 148 return fParticleMessenger; 235 } 149 } 236 150 237 void G4ParticleTable::DeleteAllParticles() << 151 //////////////////// >> 152 void G4ParticleTable::DeleteMessenger() 238 { 153 { 239 // set readyToUse false << 154 if (fParticleMessenger!= 0) { 240 readyToUse = false; << 155 //UI messenger 241 << 156 delete fParticleMessenger; 242 #ifdef G4VERBOSE << 157 fParticleMessenger= 0; 243 if (verboseLevel > 1) { << 158 // remove all items from G4ParticleTable 244 G4cout << "G4ParticleTable::DeleteAllParti << 159 // temporaly comment out >> 160 // RemoveAllParticles(); 245 } 161 } 246 #endif << 247 << 248 // delete all particles << 249 G4PTblDicIterator* piter = fIterator; << 250 piter->reset(false); << 251 while ((*piter)()) // Loop checking, 09.08. << 252 { << 253 #ifdef G4VERBOSE << 254 if (verboseLevel > 2) { << 255 G4cout << "Delete " << (piter->value())- << 256 << G4endl; << 257 } << 258 #endif << 259 delete (piter->value()); << 260 } << 261 RemoveAllParticles(); << 262 } 162 } 263 163 >> 164 //////////////////// 264 void G4ParticleTable::RemoveAllParticles() 165 void G4ParticleTable::RemoveAllParticles() 265 { 166 { 266 if (readyToUse) { << 267 G4Exception("G4ParticleTable::RemoveAllPar << 268 "No effects because readyToUse << 269 return; << 270 } << 271 167 272 #ifdef G4VERBOSE 168 #ifdef G4VERBOSE 273 if (verboseLevel > 1) { << 169 if (verboseLevel>1){ 274 G4cout << "G4ParticleTable::RemoveAllParti 170 G4cout << "G4ParticleTable::RemoveAllParticles() " << G4endl; 275 } 171 } 276 #endif 172 #endif >> 173 // delete all particles >> 174 G4PTblDicIterator *piter = fIterator; >> 175 piter -> reset(); >> 176 while( (*piter)() ){ >> 177 delete (piter->value()); >> 178 } 277 179 278 // remove all contents in Ion Table << 180 //delete Ion Table and contents 279 if (fIonTable != nullptr) { << 181 if (fIonTable!=0) { 280 fIonTable->clear(); << 182 delete fIonTable; >> 183 fIonTable = 0; 281 } 184 } 282 185 283 // clear dictionary << 186 // delete Short Lived table and contents 284 if (fDictionary != nullptr) { << 187 if (fShortLivedTable!=0) { 285 fDictionary->clear(); << 188 delete fShortLivedTable; >> 189 fShortLivedTable = 0; 286 } 190 } >> 191 >> 192 // delete dictionary for encoding >> 193 if (fEncodingDictionary) >> 194 { >> 195 fEncodingDictionary->clear(); >> 196 delete fEncodingDictionary; >> 197 fEncodingDictionary = 0; >> 198 } >> 199 >> 200 // delete dictionary >> 201 if (fDictionary) >> 202 { >> 203 if (fIterator!=0 )delete fIterator; >> 204 fIterator =0; >> 205 fDictionary->clear(); >> 206 delete fDictionary; >> 207 fDictionary = 0; >> 208 } 287 } 209 } 288 210 289 G4ParticleDefinition* G4ParticleTable::Insert( << 211 //////////////////// >> 212 G4ParticleDefinition* G4ParticleTable::Insert(G4ParticleDefinition *particle) 290 { 213 { >> 214 291 // check particle name 215 // check particle name 292 if ((particle == nullptr) || (GetKey(particl << 216 if ((particle == 0) || (GetKey(particle).isNull())) { 293 G4Exception("G4ParticleTable::Insert()", " << 294 "Particle witnout name can not << 295 #ifdef G4VERBOSE 217 #ifdef G4VERBOSE 296 if (verboseLevel > 1) { << 218 if (verboseLevel>0){ 297 G4cout << "The particle[Addr:" << partic << 219 G4cout << "The particle[Addr:" << particle << "] has no name "<< G4endl; 298 } 220 } 299 #endif 221 #endif 300 return nullptr; << 222 return 0; 301 } << 223 >> 224 }else { 302 225 303 if (contains(particle)) { << 226 if (contains(particle)) { 304 #ifdef G4VERBOSE 227 #ifdef G4VERBOSE 305 if (verboseLevel > 2) { << 228 if (verboseLevel>0){ 306 FindParticle(particle)->DumpTable(); << 229 G4cout << "The particle has same name "<< G4endl; 307 } << 230 } >> 231 if (verboseLevel>1){ >> 232 FindParticle(particle) -> DumpTable(); >> 233 } 308 #endif 234 #endif 309 G4String msg = "The particle "; << 235 return FindParticle(particle); 310 msg += particle->GetParticleName(); << 311 msg += " has already been registered in t << 312 G4Exception("G4ParticleTable::Insert()", " << 313 << 314 return particle; << 315 } << 316 << 317 G4PTblDictionary* pdic = fDictionaryShadow; << 318 236 319 // insert into Dictionary << 237 } else { 320 pdic->insert(std::pair<G4String, G4ParticleD << 238 G4PTblDictionary *pdic = fDictionary; 321 #ifdef G4MULTITHREADED << 239 G4PTblEncodingDictionary *pedic = fEncodingDictionary; 322 if (G4Threading::IsWorkerThread()) { << 240 323 fDictionary->insert(std::pair<G4String, G4 << 241 (*pdic)[GetKey(particle)] = particle; 324 } << 242 // insert into EncodingDictionary 325 #endif << 243 G4int code = particle->GetPDGEncoding(); >> 244 if (code !=0 ) { >> 245 (*pedic)[code] = particle; >> 246 } >> 247 >> 248 // insert it in IonTable if "nucleus" >> 249 if (fIonTable->IsIon(particle) ){ >> 250 fIonTable->Insert(particle); >> 251 } 326 252 327 G4PTblEncodingDictionary* pedic = fEncodingD << 253 // insert it in ShortLivedTable if "shortlived" >> 254 if (particle->IsShortLived() ){ >> 255 fShortLivedTable->Insert(particle); >> 256 } 328 257 329 // insert into EncodingDictionary << 258 return particle; 330 G4int code = particle->GetPDGEncoding(); << 331 if (code != 0) { << 332 pedic->insert(std::pair<G4int, G4ParticleD << 333 #ifdef G4MULTITHREADED << 334 if (G4Threading::IsWorkerThread()) { << 335 fEncodingDictionary->insert(std::pair<G4 << 336 } 259 } 337 #endif << 338 } << 339 << 340 // insert it in IonTable if "nucleus" << 341 if (fIonTable->IsIon(particle)) { << 342 fIonTable->Insert(particle); << 343 } 260 } 344 << 345 // set Verbose Level same as ParticleTable << 346 particle->SetVerboseLevel(verboseLevel); << 347 << 348 #ifdef G4VERBOSE << 349 if (verboseLevel > 3) { << 350 G4cout << "The particle " << particle->Get << 351 << G4endl; << 352 } << 353 #endif << 354 return particle; << 355 } 261 } 356 262 >> 263 >> 264 //////////////////// 357 G4ParticleDefinition* G4ParticleTable::Remove( 265 G4ParticleDefinition* G4ParticleTable::Remove(G4ParticleDefinition* particle) 358 { 266 { 359 if (particle == nullptr) return nullptr; << 267 G4PTblDictionary::iterator it = fDictionary->find(GetKey(particle)); 360 #ifdef G4MULTITHREADED << 268 if (it != fDictionary->end()) { 361 if (G4Threading::IsWorkerThread()) { << 269 fDictionary->erase(it); 362 G4ExceptionDescription ed; << 363 ed << "Request of removing " << particle-> << 364 << " is ignored as it is invoked from a << 365 G4Exception("G4ParticleTable::Remove()", " << 366 return nullptr; << 367 } << 368 #endif << 369 if (readyToUse) { << 370 G4StateManager* pStateManager = G4StateMan << 371 G4ApplicationState currentState = pStateMa << 372 if (currentState != G4State_PreInit) { << 373 G4String msg = "Request of removing "; << 374 msg += particle->GetParticleName(); << 375 msg += " has No effects other than Pre_I << 376 G4Exception("G4ParticleTable::Remove()", << 377 return nullptr; << 378 } << 379 << 380 #ifdef G4VERBOSE << 381 if (verboseLevel > 0) { << 382 G4cout << particle->GetParticleName() << << 383 } << 384 #endif << 385 } << 386 << 387 auto it = fDictionaryShadow->find(GetKey(par << 388 if (it != fDictionaryShadow->end()) { << 389 fDictionaryShadow->erase(it); << 390 // remove from EncodingDictionary 270 // remove from EncodingDictionary 391 G4int code = particle->GetPDGEncoding(); 271 G4int code = particle->GetPDGEncoding(); 392 if (code != 0) { << 272 if (code !=0 ) { 393 fEncodingDictionaryShadow->erase(fEncodi << 273 fEncodingDictionary->erase(fEncodingDictionary->find(code)); 394 } 274 } 395 } << 275 } else { 396 else { << 276 return 0; 397 return nullptr; << 398 } 277 } 399 278 400 // remove it from IonTable if "nucleus" 279 // remove it from IonTable if "nucleus" 401 if (fIonTable->IsIon(particle)) { << 280 if (fIonTable->IsIon(particle) ){ 402 fIonTable->Remove(particle); 281 fIonTable->Remove(particle); 403 } 282 } 404 << 283 405 #ifdef G4VERBOSE << 284 // Remove it from ShortLivedTable if "shortlived" 406 if (verboseLevel > 3) { << 285 if (particle->IsShortLived() ){ 407 G4cout << "The particle " << particle->Get << 286 fShortLivedTable->Remove(particle); 408 << " is removed from the ParticleTa << 409 } 287 } 410 #endif << 411 << 412 return particle; 288 return particle; 413 } 289 } 414 290 415 G4ParticleDefinition* G4ParticleTable::GetPart << 291 //////////////////// >> 292 G4ParticleDefinition* G4ParticleTable::FindIon(G4int Z, G4int A, G4int , G4int ) 416 { 293 { 417 CheckReadiness(); << 294 CheckReadiness(); 418 if ((index >= 0) && (index < entries())) { << 295 if (Z<=0) return 0; 419 G4PTblDicIterator* piter = fIterator; << 296 if (A<Z) return 0; 420 piter->reset(false); << 297 return fIonTable->GetIon(Z, A); 421 G4int counter = 0; << 422 while ((*piter)()) // Loop checking, 09.0 << 423 { << 424 if (counter == index) return piter->valu << 425 ++counter; << 426 } << 427 } << 428 #ifdef G4VERBOSE << 429 if (verboseLevel > 1) { << 430 G4cout << " G4ParticleTable::GetParticle" << 431 << " invalid index (=" << index << << 432 } << 433 #endif << 434 return nullptr; << 435 } 298 } 436 299 437 const G4String& G4ParticleTable::GetParticleNa << 300 //////////////////// >> 301 G4ParticleDefinition* G4ParticleTable::GetIon(G4int Z, G4int A, G4double E) 438 { 302 { 439 G4ParticleDefinition* aParticle = GetParticl << 303 CheckReadiness(); 440 if (aParticle != nullptr) { << 304 if (Z<=0) return 0; 441 return aParticle->GetParticleName(); << 305 if (A<Z) return 0; 442 } << 306 if (E<0.) return 0; 443 << 307 return fIonTable->GetIon(Z, A, E); 444 return noName; << 445 } 308 } 446 309 447 G4ParticleDefinition* G4ParticleTable::FindPar << 310 //////////////////// >> 311 G4ParticleDefinition* G4ParticleTable::FindIon(G4int Z, G4int A, G4double E) 448 { 312 { 449 auto it = fDictionary->find(particle_name); << 313 CheckReadiness(); 450 if (it != fDictionary->end()) { << 314 if (Z<=0) return 0; 451 return (*it).second; << 315 if (A<Z) return 0; 452 } << 316 if (E<0.) return 0; 453 << 317 return fIonTable->FindIon(Z, A, E); 454 #ifdef G4MULTITHREADED << 455 G4ParticleDefinition* ptcl = nullptr; << 456 if (G4Threading::IsWorkerThread()) { << 457 G4MUTEXLOCK(&G4ParticleTable::particleTabl << 458 auto its = fDictionaryShadow->find(particl << 459 if (its != fDictionaryShadow->end()) { << 460 fDictionary->insert(*its); << 461 ptcl = (*its).second; << 462 G4int code = ptcl->GetPDGEncoding(); << 463 if (code != 0) << 464 fEncodingDictionary->insert(std::pair< << 465 } << 466 G4MUTEXUNLOCK(&G4ParticleTable::particleTa << 467 } << 468 return ptcl; << 469 #else << 470 return nullptr; << 471 #endif << 472 } 318 } 473 319 474 void G4ParticleTable::SelectParticle(const G4S << 320 //////////////////// >> 321 G4ParticleDefinition* G4ParticleTable::GetParticle(G4int index) 475 { 322 { 476 if (name != selectedName) { << 323 CheckReadiness(); 477 const G4ParticleDefinition* part = FindPar << 324 if ( (index >=0) && (index < entries()) ) { 478 if (part != nullptr) { << 325 G4PTblDicIterator *piter = fIterator; 479 #ifdef G4MULTITHREADED << 326 piter -> reset(); 480 G4MUTEXLOCK(&G4ParticleTable::particleTa << 327 G4int counter = 0; 481 #endif << 328 while( (*piter)() ){ 482 selectedParticle = part; << 329 if ( counter == index ) return piter->value(); 483 selectedName = name; << 330 counter++; 484 #ifdef G4MULTITHREADED << 485 G4MUTEXUNLOCK(&G4ParticleTable::particle << 486 #endif << 487 } 331 } 488 } 332 } >> 333 #ifdef G4VERBOSE >> 334 if (verboseLevel>0){ >> 335 G4cout << " G4ParticleTable::GetParticle"; >> 336 G4cout << " invalid index (=" << index << ")" << G4endl; >> 337 } >> 338 #endif >> 339 return 0; 489 } 340 } 490 341 491 G4ParticleDefinition* G4ParticleTable::FindPar << 342 //////////////////// >> 343 G4ParticleDefinition* G4ParticleTable::FindParticle(const G4ParticleDefinition *particle) 492 { 344 { 493 CheckReadiness(); << 345 CheckReadiness(); 494 G4String key = GetKey(particle); 346 G4String key = GetKey(particle); 495 return FindParticle(key); 347 return FindParticle(key); 496 } 348 } 497 349 498 G4ParticleDefinition* G4ParticleTable::FindPar << 350 //////////////////// >> 351 G4ParticleDefinition* G4ParticleTable::FindParticle(G4int aPDGEncoding ) 499 { 352 { 500 CheckReadiness(); << 353 CheckReadiness(); 501 // check aPDGEncoding is valid << 354 // check aPDGEncoding is valid 502 if (aPDGEncoding == 0) { << 355 if (aPDGEncoding == 0){ 503 #ifdef G4VERBOSE 356 #ifdef G4VERBOSE 504 if (verboseLevel > 1) { << 357 if (verboseLevel>0){ 505 G4cout << "PDGEncoding [" << aPDGEncodi << 358 G4cout << "PDGEncoding [" << aPDGEncoding << "] is not valid " << G4endl; 506 } << 359 } 507 #endif 360 #endif 508 return nullptr; << 361 return 0; 509 } << 362 } 510 363 511 G4PTblEncodingDictionary* pedic = fEncodingD << 364 G4PTblEncodingDictionary *pedic = fEncodingDictionary; 512 G4ParticleDefinition* particle = nullptr; << 365 G4ParticleDefinition* particle =0; 513 366 514 if (pedic != nullptr) { << 367 G4PTblEncodingDictionary::iterator it = pedic->find(aPDGEncoding ); 515 auto it = pedic->find(aPDGEncoding); << 516 if (it != pedic->end()) { 368 if (it != pedic->end()) { 517 particle = (*it).second; 369 particle = (*it).second; 518 } 370 } 519 } << 520 << 521 #ifdef G4MULTITHREADED << 522 if (particle == nullptr && G4Threading::IsWo << 523 G4MUTEXLOCK(&G4ParticleTable::particleTabl << 524 auto its = fEncodingDictionaryShadow->find << 525 if (its != fEncodingDictionaryShadow->end( << 526 particle = (*its).second; << 527 fEncodingDictionary->insert(*its); << 528 G4String key = GetKey(particle); << 529 fDictionary->insert(std::pair<G4String, << 530 } << 531 G4MUTEXUNLOCK(&G4ParticleTable::particleTa << 532 } << 533 #endif << 534 371 535 #ifdef G4VERBOSE 372 #ifdef G4VERBOSE 536 if ((particle == nullptr) && (verboseLevel > << 373 if ((particle == 0) && (verboseLevel>0) ){ 537 G4cout << "CODE:" << aPDGEncoding << " doe << 374 G4cout << "CODE:" << aPDGEncoding << " does not exist in ParticleTable " << G4endl; 538 } << 375 } 539 #endif 376 #endif 540 return particle; << 377 return particle; 541 } 378 } 542 379 543 void G4ParticleTable::DumpTable(const G4String << 380 //////////////////// >> 381 void G4ParticleTable::DumpTable(const G4String &particle_name) 544 { 382 { 545 CheckReadiness(); << 383 CheckReadiness(); 546 if ((particle_name == "ALL") || (particle_na << 384 if (( particle_name == "ALL" ) || (particle_name == "all")){ 547 // dump all particles << 385 // dump all particles 548 G4PTblDicIterator* piter = fIterator; << 386 G4PTblDicIterator *piter = fIterator; 549 piter->reset(); << 387 piter -> reset(); 550 while ((*piter)()) // Loop checking, 09.0 << 388 while( (*piter)() ){ 551 { << 552 (piter->value())->DumpTable(); 389 (piter->value())->DumpTable(); 553 } 390 } 554 } << 391 } else { 555 else { << 392 // dump only particle with name of particle_name 556 // dump only particle with name of particl << 393 G4ParticleDefinition *ptr; 557 G4ParticleDefinition* ptr = FindParticle(p << 394 ptr = FindParticle(particle_name); 558 if (ptr != nullptr) { << 395 if ( ptr != 0) { 559 ptr->DumpTable(); 396 ptr->DumpTable(); 560 } << 397 } else { 561 else { << 562 #ifdef G4VERBOSE 398 #ifdef G4VERBOSE 563 if (verboseLevel > 1) { << 399 if (verboseLevel>0){ 564 G4cout << " G4ParticleTable::DumpTable << 400 G4cout << particle_name << " does not exist in ParticleTable " <<G4endl; 565 << " does not exist in Particle << 566 } 401 } 567 #endif 402 #endif 568 } 403 } 569 } 404 } 570 } 405 } 571 406 572 void G4ParticleTable::CheckReadiness() const << 407 void G4ParticleTable::CheckReadiness() 573 { 408 { 574 if (!readyToUse) { << 409 if(!readyToUse) 575 G4String msg; << 410 { 576 msg = "Illegal use of G4ParticleTable :\n" << 411 G4String msg; 577 msg += "Access to G4ParticleTable for find << 412 msg = " Access to G4ParticleTable for finding a particle or equivalent\n"; 578 msg += "operation occurs before G4VUserPhy << 413 msg += "operation occurs before G4VUserPhysicsList is instantiated and\n"; 579 msg += "assigned to G4RunManager. Such an << 414 msg += "assigned to G4RunManager. Such an access is prohibited by\n"; 580 msg += "Geant4 version 8.0. To fix this pr << 415 msg += "Geant4 version 8.0. To fix this problem, please make sure that\n"; 581 msg += "your main() instantiates G4VUserPh << 416 msg += "your main() instantiates G4VUserPhysicsList and set it to\n"; 582 msg += "G4RunManager before instantiating << 417 msg += "G4RunManager before instantiating other user classes such as\n"; 583 msg += "G4VUserPrimaryParticleGeneratorAct << 418 msg += "G4VUserPrimaryParticleGeneratorAction."; 584 G4Exception("G4ParticleTable::CheckReadine << 419 G4Exception("G4ParticleTable::CheckReadiness()", >> 420 "PartMan0000",FatalException,msg); 585 } 421 } 586 } 422 } 587 423 588 G4IonTable* G4ParticleTable::GetIonTable() con << 589 { << 590 return fIonTable; << 591 } << 592 << 593 const G4ParticleTable::G4PTblDictionary* G4Par << 594 { << 595 return fDictionary; << 596 } << 597 424 598 G4ParticleTable::G4PTblDicIterator* G4Particle << 599 { << 600 return fIterator; << 601 } << 602 425 603 const G4ParticleTable::G4PTblEncodingDictionar << 604 { << 605 return fEncodingDictionary; << 606 } << 607 426 608 G4bool G4ParticleTable::contains(const G4Strin << 609 { << 610 auto it = fDictionaryShadow->find(particle_n << 611 return (it != fDictionaryShadow->cend()); << 612 } << 613 427 614 G4int G4ParticleTable::entries() const << 615 { << 616 return (G4int)fDictionary->size(); << 617 } << 618 428 619 G4int G4ParticleTable::size() const << 620 { << 621 return (G4int)fDictionary->size(); << 622 } << 623 429