Geant4  10.02.p02
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 94421 2015-11-16 08:22:56Z 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();
98  // This method is similar to the destructor. It is used by each worker
99  // thread to achieve the partial effect as that of the master thread.
100 
101  public: // With Description
103  // return the pointer to G4ParticleTable object
104  // G4ParticleTable is a "singleton" and can get its pointer by this function
105  // At the first time of calling this function, the G4ParticleTable object
106  // is instantiated
107 
108  G4bool contains(const G4ParticleDefinition *particle) const;
109  G4bool contains(const G4String &particle_name) const;
110  // returns TRUE if the ParticleTable contains
111 
112  G4int entries() const;
113  G4int size() const;
114  // returns the number of Particles in the ParticleTable
115 
116  G4ParticleDefinition* GetParticle(G4int index) const;
117  // returns a pointer to i-th particles in the ParticleTable
118  // 0<= index < entries()
119 
120  const G4String& GetParticleName(G4int index) const;
121  // returns name of i-th particles in the ParticleTable
122 
123  G4ParticleDefinition* FindParticle(G4int PDGEncoding );
124  G4ParticleDefinition* FindParticle(const G4String &particle_name);
126  // returns a pointer to the particle (0 if not contained)
127 
129  G4ParticleDefinition* FindAntiParticle(const G4String &particle_name);
131  // returns a pointer to its anti-particle (0 if not contained)
132 
133  G4PTblDicIterator* GetIterator() const;
134  // return the pointer of Iterator (RW compatible)
135 
136  void DumpTable(const G4String &particle_name = "ALL");
137  // dump information of particles specified by name
138 
139  public: //With Description
140 
141  G4IonTable* GetIonTable() const;
142  // return the pointer to G4IonTable object
143 
144 
145  public: // With Description
147  // insert the particle into ParticleTable
148  // return value is same as particle if successfully inserted
149  // or pointer to another G4ParticleDefinition object
150  // which has same name of particle
151  // or 0 if fail to insert by another reason
152 
154  // Remove the particle from the table (not delete)
155 
156  void RemoveAllParticles();
157  // remove all particles from G4ParticleTable
158 
159  void DeleteAllParticles();
160  // remove and delete all particles from G4ParticleTable
161 
162  public:
164  void DeleteMessenger();
165  // create/delete messenger for the particle table
166  // these methods are supposed to be invoked by G4RunManager only
167 
168  protected:
169 
170  const G4PTblDictionary* GetDictionary() const;
171 
172  const G4String& GetKey(const G4ParticleDefinition *particle) const;
173  // return key value of the particle (i.e. particle name)
174 
175  const G4PTblEncodingDictionary* GetEncodingDictionary() const;
176  // return the pointer to EncodingDictionary
177 
178  private:
180  // controle flag for output message
181  // 0: Silent
182  // 1: Warning message
183  // 2: More
184 
185  public:
186  void SetVerboseLevel(G4int value);
187  G4int GetVerboseLevel() const;
188 
190  static G4ThreadLocal G4PTblDictionary* fDictionary;
191  static G4ThreadLocal G4PTblDicIterator* fIterator;
192  static G4ThreadLocal G4PTblEncodingDictionary* fEncodingDictionary;
193  // These fields should be thread local or thread private. For a singleton
194  // class, we can change any member field as static without any problem
195  // because there is only one instance. Then we are allowed to add
196  // "G4ThreadLocal".
197 
198  //01.25.2009 Xin Dong: Phase II change for Geant4 multi-threading.
199  //Phase I changes this member to be thread local
200  //,while each thread holds its own copy of particles.
201  //Phase II changes this member back in order to share particles.
203 
205  // This field should be thread private. However, we have to keep one copy
206  // of the ion table pointer. So we change all important fields of G4IonTable
207  // to the thread local variable.
208 
209  // These shadow pointers are used by each worker thread to copy the content
210  // from the master thread.
211 
213  static G4PTblDictionary* fDictionaryShadow;
214  static G4PTblDicIterator* fIteratorShadow;
215  static G4PTblEncodingDictionary* fEncodingDictionaryShadow;
216 
217  private:
219 
222 
223  public:
224  void SetReadiness(G4bool val=true);
225  G4bool GetReadiness() const;
228  private:
229  void CheckReadiness() const;
230 
231 
232 #ifdef G4MULTITHREADED
233 public:
234  //Andrea Dotti January 16. Shared instance of a mutex
235  static G4Mutex particleTableMutex;
236  static G4int lockCount;
237 #endif
238 };
239 #include "G4ParticleTable.icc"
240 
241 #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 DestroyWorkerG4ParticleTable()
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