Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/particles/management/src/G4ParticleTable.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /particles/management/src/G4ParticleTable.cc (Version 11.3.0) and /particles/management/src/G4ParticleTable.cc (Version 9.5)


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