Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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// G4ParticleTable
27//
28// Class description:
29//
30// G4ParticleTable is the table of pointers to G4ParticleDefinition.
31// It is a "singleton" (only one static object).
32// Each G4ParticleDefinition pointer is stored with its name as a key
33// to itself. So, each G4ParticleDefinition object must have unique
34// name.
35
36// Authors: G.Cosmo, 2 December 1995 - Design, based on object model
37// H.Kurashige, 27 June 1996 - First implementation
38// History:
39// - 14 Nov 1997, H.Kurashige - Added messenger
40// - 24 Sep 1998, H.Kurashige - Added dictionary for encoding
41// - 28 Oct 1999, H.Kurashige - Migration to STL maps
42// - 15 Sep 2017, K.L.Genser - Added support for MuonicAtom
43// --------------------------------------------------------------------
44#ifndef G4ParticleTable_hh
45#define G4ParticleTable_hh 1
46
47#include <map>
48
49#include "G4ios.hh"
50#include "globals.hh"
51#include "G4Threading.hh"
54
55class G4UImessenger;
57class G4IonTable;
58
60{
61 public:
62
71
74 // Copy constructor and assignment operator not allowed
75
77 // This method is similar to the constructor. It is used by each worker
78 // thread to achieve the partial effect as that of the master thread
79
80 virtual ~G4ParticleTable();
82 // This method is similar to the destructor. It is used by each worker
83 // thread to achieve the partial effect as that of the master thread
84
86 // Return the pointer to the G4ParticleTable object
87 // G4ParticleTable is a "singleton" and can get its pointer by this
88 // function. At the first time of calling this function, the
89 // G4ParticleTable object is instantiated
90
91 inline G4bool contains(const G4ParticleDefinition* particle) const;
92 G4bool contains(const G4String& particle_name) const;
93 // Returns TRUE if the ParticleTable contains the particle's pointer
94
95 G4int entries() const;
96 G4int size() const;
97 // Returns the number of particles in the ParticleTable
98
100 // Returns a pointer to the i-th particle in the ParticleTable
101 // 0 <= index < entries()
102
103 const G4String& GetParticleName(G4int index) const;
104 // Returns the name of i-th particle in the ParticleTable
105
107 G4ParticleDefinition* FindParticle(const G4String& particle_name);
109 // Returns a pointer to the particle (0 if not contained)
110
114 // Returns a pointer to its anti-particle (0 if not contained)
115
117 // Returns the pointer to the Iterator
118
119 void DumpTable(const G4String& particle_name = "ALL");
120 // Dumps information of particles specified by name
121
122 G4IonTable* GetIonTable() const;
123 // Returns the pointer to the G4IonTable object
124
126 // Inserts the particle into ParticleTable.
127 // Returned value is the same as particle if successfully inserted
128 // or the pointer to another G4ParticleDefinition object
129 // which has same particle name
130 // or nullptr if failing to insert by other reason
131
133 // Removes the particle from the table (not delete)
134
135 void RemoveAllParticles();
136 // Removes all particles from G4ParticleTable
137
138 void DeleteAllParticles();
139 // Removes and deletes all particles from G4ParticleTable
140
142 // Creates messenger
143
144 void SelectParticle(const G4String& name);
145
147
148 inline void SetVerboseLevel(G4int value);
149 inline G4int GetVerboseLevel() const;
150
151 inline void SetReadiness(G4bool val = true);
152 inline G4bool GetReadiness() const;
153
156
159
160 // Public data ----------------------------------------------------
161
166 // These fields should be thread local or thread private. For a singleton
167 // class, we can change any member field as static without any problem
168 // because there is only one instance. Then we are allowed to add
169 // "G4ThreadLocal"
170
172 // Particle table is being shared
173
175 // This field should be thread private. However, we have to keep one copy
176 // of the ion table pointer. So we change all important fields of
177 // G4IonTable to be thread local
178
179 // These shadow pointers are used by each worker thread to copy the content
180 // from the master thread
181 //
185
186#ifdef G4MULTITHREADED
187 // Shared instance of a mutex
188 static G4GLOB_DLL G4Mutex& particleTableMutex();
189 static G4GLOB_DLL G4int& lockCount();
190#endif
191
192 protected:
193
194 const G4PTblDictionary* GetDictionary() const;
195
196 inline const G4String& GetKey(const G4ParticleDefinition* particle) const;
197 // Returns key value of the particle (i.e. particle name)
198
200 // Returns the pointer to EncodingDictionary
201
202 private:
203
205 // Provate default constructor
206
207 void CheckReadiness() const;
208
209 // Private data ---------------------------------------------------
210
211 G4ParticleDefinition* genericIon = nullptr;
212 G4ParticleDefinition* genericMuonicAtom = nullptr;
213 const G4ParticleDefinition* selectedParticle = nullptr;
214
215 const G4String noName = " ";
216 G4String selectedName = "undefined";
217
218 G4int verboseLevel = 1;
219 // Control flag for output message
220 // 0: Silent
221 // 1: Warning message
222 // 2: More
223
224 G4bool readyToUse = false;
225};
226
227#include "G4ParticleTable.icc"
228
229#endif
std::mutex G4Mutex
Definition: G4Threading.hh:81
#define G4GLOB_DLL
Definition: G4Types.hh:70
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
std::map< K, V, std::less< K > > Map
G4IonTable * GetIonTable() const
G4bool GetReadiness() const
static G4ThreadLocal G4PTblEncodingDictionary * fEncodingDictionary
G4ParticleDefinition * GetParticle(G4int index) const
G4int GetVerboseLevel() const
G4ParticleDefinition * GetGenericMuonicAtom() const
static G4PTblEncodingDictionary * fEncodingDictionaryShadow
G4int entries() const
void DestroyWorkerG4ParticleTable()
G4bool contains(const G4ParticleDefinition *particle) const
static G4ParticleTable * fgParticleTable
G4PTblDicIterator * GetIterator() const
G4ParticleTable(const G4ParticleTable &)=delete
G4ParticleTable & operator=(const G4ParticleTable &)=delete
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
static G4ParticleTable * GetParticleTable()
void SetVerboseLevel(G4int value)
G4ParticleDefinition * Insert(G4ParticleDefinition *particle)
void SelectParticle(const G4String &name)
G4ParticleTableIterator< G4int, G4ParticleDefinition * >::Map G4PTblEncodingDictionary
G4ParticleDefinition * Remove(G4ParticleDefinition *particle)
static G4PTblDictionary * fDictionaryShadow
static G4PTblDicIterator * fIteratorShadow
void SetGenericMuonicAtom(G4ParticleDefinition *)
G4int size() const
void SetReadiness(G4bool val=true)
void SetGenericIon(G4ParticleDefinition *)
void WorkerG4ParticleTable()
G4UImessenger * CreateMessenger()
G4IonTable * fIonTable
G4ParticleDefinition * FindAntiParticle(const G4ParticleDefinition *p)
virtual ~G4ParticleTable()
G4ParticleMessenger * fParticleMessenger
const G4ParticleDefinition * GetSelectedParticle() const
const G4String & GetKey(const G4ParticleDefinition *particle) const
G4ParticleDefinition * FindAntiParticle(const G4String &p_name)
G4ParticleDefinition * GetGenericIon() const
static G4ThreadLocal G4PTblDicIterator * fIterator
const G4PTblDictionary * GetDictionary() const
G4ParticleDefinition * FindAntiParticle(G4int PDGEncoding)
const G4PTblEncodingDictionary * GetEncodingDictionary() const
const G4String & GetParticleName(G4int index) const
G4ParticleTableIterator< G4String, G4ParticleDefinition * >::Map G4PTblDictionary
static G4ThreadLocal G4PTblDictionary * fDictionary
void DumpTable(const G4String &particle_name="ALL")
#define G4ThreadLocal
Definition: tls.hh:77