Geant4  10.01.p03
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 84274 2014-10-13 07:15:37Z 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 
131  G4PTblDicIterator* GetIterator() const;
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  public: // With Description
145  // insert the particle into ParticleTable
146  // return value is same as particle if successfully inserted
147  // or pointer to another G4ParticleDefinition object
148  // which has same name of particle
149  // or 0 if fail to insert by another reason
150 
152  // Remove the particle from the table (not delete)
153 
154  void RemoveAllParticles();
155  // remove all particles from G4ParticleTable
156 
157  void DeleteAllParticles();
158  // remove and delete all particles from G4ParticleTable
159 
160  public:
162  void DeleteMessenger();
163  // create/delete messenger for the particle table
164  // these methods are supposed to be invoked by G4RunManager only
165 
166  protected:
167 
168  const G4PTblDictionary* GetDictionary() const;
169 
170  const G4String& GetKey(const G4ParticleDefinition *particle) const;
171  // return key value of the particle (i.e. particle name)
172 
173  const G4PTblEncodingDictionary* GetEncodingDictionary() const;
174  // return the pointer to EncodingDictionary
175 
176  private:
178  // controle flag for output message
179  // 0: Silent
180  // 1: Warning message
181  // 2: More
182 
183  public:
184  void SetVerboseLevel(G4int value);
185  G4int GetVerboseLevel() const;
186 
188  static G4ThreadLocal G4PTblDictionary* fDictionary;
189  static G4ThreadLocal G4PTblDicIterator* fIterator;
190  static G4ThreadLocal G4PTblEncodingDictionary* fEncodingDictionary;
191  // These fields should be thread local or thread private. For a singleton
192  // class, we can change any member field as static without any problem
193  // because there is only one instance. Then we are allowed to add
194  // "G4ThreadLocal".
195 
196  //01.25.2009 Xin Dong: Phase II change for Geant4 multi-threading.
197  //Phase I changes this member to be thread local while each thread holds
198  //its own copy of particles.
199  //Phase II changes this member back in order to share particles.
201 
203  // This field should be thread private. However, we have to keep one copy
204  // of the ion table pointer. So we change all important fields of G4IonTable
205  // to the thread local variable.
206 
207  // These shadow pointers are used by each worker thread to copy the content
208  // from the master thread.
209 
211  static G4PTblDictionary* fDictionaryShadow;
212  static G4PTblDicIterator* fIteratorShadow;
213  static G4PTblEncodingDictionary* fEncodingDictionaryShadow;
214 
215  private:
217 
220 
221  public:
222  void SetReadiness(G4bool val=true);
223  G4bool GetReadiness() const;
226  private:
227  void CheckReadiness() const;
228 
229 
230 #ifdef G4MULTITHREADED
231 public:
232  //Andrea Dotti January 16. Shared instance of a mutex
233  static G4Mutex particleTableMutex;
234  static G4int lockCount;
235 #endif
236 };
237 #include "G4ParticleTable.icc"
238 
239 #endif
void WorkerG4ParticleTable()
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
G4ParticleDefinition * FindAntiParticle(G4int PDGEncoding)
void DumpTable(const G4String &particle_name="ALL")
const G4PTblDictionary * GetDictionary() const
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:89
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
const G4String noName
bool G4bool
Definition: G4Types.hh:79
void SetGenericIon(G4ParticleDefinition *)
G4bool contains(const G4ParticleDefinition *particle) const
G4int G4Mutex
Definition: G4Threading.hh:173
static G4ParticleTable * GetParticleTable()
static G4ThreadLocal G4PTblDictionary * fDictionary
G4ParticleDefinition * genericIon
std::map< K, V, std::less< K > > Map
const G4PTblEncodingDictionary * GetEncodingDictionary() const
G4int size() const
void CheckReadiness() 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