Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ParticleTable.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4ParticleTable.hh 73711 2013-09-09 09:57:29Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // History: first implementation, based on object model of
34 // 27 June 1996, H.Kurashige
35 // ------------------------------------------------------------
36 // added fParticleMessenger 14 Nov., 97 H.Kurashige
37 // added Create/DeleteMessenger 06 Jul., 98 H.Kurashige
38 // modified FindIon 02 Aug., 98 H.Kurashige
39 // added dictionary for encoding 24 Sep., 98 H.Kurashige
40 // added RemoveAllParticles() 8 Nov., 98 H.Kurashige
41 // --------------------------------
42 // fixed some improper codings 08 Apr., 99 H.Kurashige
43 // modified FindIon/GetIon methods 17 AUg., 99 H.Kurashige
44 // implement new version for using STL map instaed of RW PtrHashedDictionary
45 // 28 ct., 99 H.Kurashige
46 // modified implementation of Remove 21 Mar.,08 H.Kurashige
47 // remove G4ShortLivedTable 25 July, 13 H.Kurashige
48 //
49 
50 #ifndef G4ParticleTable_h
51 #define G4ParticleTable_h 1
52 
53 #include <map>
54 
55 #include "G4ios.hh"
56 #include "globals.hh"
57 #include "G4Threading.hh"
58 #include "G4ParticleDefinition.hh"
60 
61 class G4UImessenger;
63 class G4IonTable;
64 
66 {
67  // Class Description
68  // G4ParticleTable is the table of pointer to G4ParticleDefinition
69  // G4ParticleTable is a "singleton" (only one and staic object)
70  // In G4ParticleTable, each G4ParticleDefinition pointer is stored
71  // with its name as a key to itself. So, each G4ParticleDefinition
72  // object must have unique name for itself.
73  //
74 
75  public:
76 
81 
82  protected:
83  // default constructor
85  // Copy constructor and assignment operator
88 
89  public:
90 
91  void SlaveG4ParticleTable();
92  void WorkerG4ParticleTable();
93  // This method is similar to the constructor. It is used by each worker
94  // thread to achieve the partial effect as that of the master thread.
95 
96  virtual ~G4ParticleTable();
97  // Do we need DestroySlaveG4ParticleTable()?
98 
99  public: // With Description
101  // return the pointer to G4ParticleTable object
102  // G4ParticleTable is a "singleton" and can get its pointer by this function
103  // At the first time of calling this function, the G4ParticleTable object
104  // is instantiated
105 
106  G4bool contains(const G4ParticleDefinition *particle) const;
107  G4bool contains(const G4String &particle_name) const;
108  // returns TRUE if the ParticleTable contains
109 
110  G4int entries() const;
111  G4int size() const;
112  // returns the number of Particles in the ParticleTable
113 
114  G4ParticleDefinition* GetParticle(G4int index) const;
115  // returns a pointer to i-th particles in the ParticleTable
116  // 0<= index < entries()
117 
118  const G4String& GetParticleName(G4int index) const;
119  // returns name of i-th particles in the ParticleTable
120 
121  G4ParticleDefinition* FindParticle(G4int PDGEncoding );
122  G4ParticleDefinition* FindParticle(const G4String &particle_name);
124  // returns a pointer to the particle (0 if not contained)
125 
127  G4ParticleDefinition* FindAntiParticle(const G4String &particle_name);
129  // returns a pointer to its anti-particle (0 if not contained)
130 
132  // return the pointer of Iterator (RW compatible)
133 
134  void DumpTable(const G4String &particle_name = "ALL");
135  // dump information of particles specified by name
136 
137  public: //With Description
138 
139  G4IonTable* GetIonTable() const;
140  // return the pointer to G4IonTable object
141 
142  ///////////////////////////////////////////////////////////////////////
143  // NOTE ::
144  // Following FindIon/GetIon methods will be removed in future relases
145  // Use FindIon/GetIon methods of G4IonTable instead
146  //
147  G4ParticleDefinition* FindIon( G4int atomicNumber,
148  G4int atomicMass,
149  G4double excitationEnergy );
150  G4ParticleDefinition* FindIon( G4int atomicNumber,
151  G4int atomicMass,
152  G4int numberOfLambda,
153  G4double excitationEnergy );
154  // return the pointer to an ion (returns 0 if the ion does not exist)
155  // the ion has excitation energy nearest to given excitationEnergy (0: ground state)
156 
157  G4ParticleDefinition* GetIon( G4int atomicNumber,
158  G4int atomicMass,
159  G4double excitationEnergy);
160  G4ParticleDefinition* GetIon( G4int atomicNumber,
161  G4int atomicMass,
162  G4int numberOfLambda,
163  G4double excitationEnergy);
164 
165  G4ParticleDefinition* GetIon(G4int atomicNumber, G4int atomicMass,
166  G4int level);
167 
168  // return the pointer to an ion ( create ion if the ion does not exist)
169  // It has excitation energy nearest to given excitationEnergy (0: ground state)
170 
171  G4ParticleDefinition* FindIon( G4int atomicNumber,
172  G4int atomicMass,
173  G4int dummy1,
174  G4int dummy2 );
175  // return the pointer to an ion
176  // !! This routine behaves same as GetIon( atomicNumber, atomicMass, 0)
177  // !! The third and fourth arguments are meaningless
178  // !! This routine is provided for compatibility to old version
179  ///////////////////////////////////////////////////////////////////////////////////////
180 
181 
182 
183  public: // With Description
185  // insert the particle into ParticleTable
186  // return value is same as particle if successfully inserted
187  // or pointer to another G4ParticleDefinition object
188  // which has same name of particle
189  // or 0 if fail to insert by another reason
190 
192  // Remove the particle from the table (not delete)
193 
194  void RemoveAllParticles();
195  // remove all particles from G4ParticleTable
196 
197  void DeleteAllParticles();
198  // remove and delete all particles from G4ParticleTable
199 
200  public:
202  void DeleteMessenger();
203  // create/delete messenger for the particle table
204  // these methods are supposed to be invoked by G4RunManager only
205 
206  protected:
207 
208  const G4PTblDictionary* GetDictionary() const;
209 
210  const G4String& GetKey(const G4ParticleDefinition *particle) const;
211  // return key value of the particle (i.e. particle name)
212 
214  // return the pointer to EncodingDictionary
215 
216  private:
217  G4int verboseLevel;
218  // controle flag for output message
219  // 0: Silent
220  // 1: Warning message
221  // 2: More
222 
223  public:
225  G4int GetVerboseLevel() const;
226 
231  // These fields should be thread local or thread private. For a singleton
232  // class, we can change any member field as static without any problem
233  // because there is only one instance. Then we are allowed to add
234  // "G4ThreadLocal".
235 
236  //01.25.2009 Xin Dong: Phase II change for Geant4 multi-threading.
237  //Phase I changes this member to be thread local while each thread holds
238  //its own copy of particles.
239  //Phase II changes this member back in order to share particles.
241 
243  // This field should be thread private. However, we have to keep one copy
244  // of the ion table pointer. So we change all important fields of G4IonTable
245  // to the thread local variable.
246 
247  // These shadow pointers are used by each worker thread to copy the content
248  // from the master thread.
249 
254 
255  private:
256  const G4String noName;
257 
258  G4bool readyToUse;
259  G4ParticleDefinition* genericIon;
260 
261  public:
262  void SetReadiness(G4bool val=true);
263  G4bool GetReadiness() const;
266  private:
267  void CheckReadiness() const;
268 
269 
270 #ifdef G4MULTITHREADED
271 public:
272  //Andrea Dotti January 16. Shared instance of a mutex
273  static G4Mutex particleTableMutex;
274  static G4int lockCount;
275 #endif
276 };
277 #include "G4ParticleTable.icc"
278 
279 #endif
void WorkerG4ParticleTable()
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4ParticleDefinition * FindAntiParticle(G4int PDGEncoding)
void DumpTable(const G4String &particle_name="ALL")
const G4PTblDictionary * GetDictionary() const
G4ParticleDefinition * GetIon(G4int atomicNumber, G4int atomicMass, G4double excitationEnergy)
const G4String & GetParticleName(G4int index) const
G4UImessenger * CreateMessenger()
virtual ~G4ParticleTable()
G4ParticleDefinition * Remove(G4ParticleDefinition *particle)
const G4String & GetKey(const G4ParticleDefinition *particle) const
void SetVerboseLevel(G4int value)
G4ParticleTableIterator< G4int, G4ParticleDefinition * >::Map G4PTblEncodingDictionary
void SetReadiness(G4bool val=true)
G4ParticleDefinition * GetGenericIon() const
#define G4ThreadLocal
Definition: tls.hh:52
G4ParticleTableIterator< G4String, G4ParticleDefinition * > G4PTblDicIterator
G4bool GetReadiness() const
int G4int
Definition: G4Types.hh:78
static G4ParticleMessenger * fParticleMessengerShadow
static G4ThreadLocal G4ParticleMessenger * fParticleMessenger
static G4PTblEncodingDictionary * fEncodingDictionaryShadow
G4ParticleDefinition * GetParticle(G4int index) const
G4ParticleTable & operator=(const G4ParticleTable &)
G4ParticleDefinition * Insert(G4ParticleDefinition *particle)
G4IonTable * GetIonTable() const
bool G4bool
Definition: G4Types.hh:79
G4ParticleDefinition * FindIon(G4int atomicNumber, G4int atomicMass, G4double excitationEnergy)
void SetGenericIon(G4ParticleDefinition *)
G4bool contains(const G4ParticleDefinition *particle) const
G4int G4Mutex
Definition: G4Threading.hh:156
static G4ParticleTable * GetParticleTable()
static G4ThreadLocal G4PTblDictionary * fDictionary
std::map< K, V, std::less< K > > Map
const XML_Char int const XML_Char * value
double G4double
Definition: G4Types.hh:76
const G4PTblEncodingDictionary * GetEncodingDictionary() const
G4int size() const
G4int GetVerboseLevel() const
static G4IonTable * fIonTable
G4PTblDicIterator * GetIterator() const
G4int entries() const
static G4ThreadLocal G4PTblDicIterator * fIterator
static G4ThreadLocal G4PTblEncodingDictionary * fEncodingDictionary
static G4PTblDicIterator * fIteratorShadow
static G4ParticleTable * fgParticleTable
G4ParticleTableIterator< G4int, G4ParticleDefinition * > G4PTblEncodingDicIterator
static G4PTblDictionary * fDictionaryShadow
G4ParticleTableIterator< G4String, G4ParticleDefinition * >::Map G4PTblDictionary