Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/Geant4/G4ParticleTable.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4ParticleTable
0027 //
0028 // Class description:
0029 //
0030 // G4ParticleTable is the table of pointers to G4ParticleDefinition.
0031 // It is a "singleton" (only one static object).
0032 // Each G4ParticleDefinition pointer is stored with its name as a key
0033 // to itself. So, each G4ParticleDefinition object must have unique
0034 // name.
0035 
0036 // Authors: G.Cosmo, 2 December 1995 - Design, based on object model
0037 //          H.Kurashige, 27 June 1996 - First implementation
0038 // History:
0039 // - 14 Nov 1997, H.Kurashige - Added messenger
0040 // - 24 Sep 1998, H.Kurashige - Added dictionary for encoding
0041 // - 28 Oct 1999, H.Kurashige - Migration to STL maps
0042 // - 15 Sep 2017, K.L.Genser - Added support for MuonicAtom
0043 // --------------------------------------------------------------------
0044 #ifndef G4ParticleTable_hh
0045 #define G4ParticleTable_hh 1
0046 
0047 #include "G4ParticleDefinition.hh"
0048 #include "G4ParticleTableIterator.hh"
0049 #include "G4Threading.hh"
0050 #include "G4ios.hh"
0051 #include "globals.hh"
0052 
0053 #include <map>
0054 
0055 class G4UImessenger;
0056 class G4ParticleMessenger;
0057 class G4IonTable;
0058 
0059 class G4ParticleTable
0060 {
0061   public:
0062     using G4PTblDictionary = G4ParticleTableIterator<G4String, G4ParticleDefinition*>::Map;
0063     using G4PTblDicIterator = G4ParticleTableIterator<G4String, G4ParticleDefinition*>;
0064     using G4PTblEncodingDictionary = G4ParticleTableIterator<G4int, G4ParticleDefinition*>::Map;
0065     using G4PTblEncodingDicIterator = G4ParticleTableIterator<G4int, G4ParticleDefinition*>;
0066 
0067     virtual ~G4ParticleTable();
0068 
0069     // Copy constructor and assignment operator not allowed
0070     G4ParticleTable(const G4ParticleTable&) = delete;
0071     G4ParticleTable& operator=(const G4ParticleTable&) = delete;
0072 
0073     // This method is similar to the constructor. It is used by each worker
0074     // thread to achieve the partial effect as that of the master thread
0075     void WorkerG4ParticleTable();
0076 
0077     // This method is similar to the destructor. It is used by each worker
0078     // thread to achieve the partial effect as that of the master thread
0079     void DestroyWorkerG4ParticleTable();
0080 
0081     // Return the pointer to the G4ParticleTable object
0082     // G4ParticleTable is a "singleton" and can get its pointer by this
0083     // function. At the first time of calling this function, the
0084     // G4ParticleTable object is instantiated
0085     static G4ParticleTable* GetParticleTable();
0086 
0087     // Returns TRUE if the ParticleTable contains the particle's pointer
0088     inline G4bool contains(const G4ParticleDefinition* particle) const;
0089     G4bool contains(const G4String& particle_name) const;
0090 
0091     // Returns the number of particles in the ParticleTable
0092     G4int entries() const;
0093     G4int size() const;
0094 
0095     // Returns a pointer to the i-th particle in the ParticleTable
0096     // 0 <= index < entries()
0097     G4ParticleDefinition* GetParticle(G4int index) const;
0098 
0099     // Returns the name of i-th particle in the ParticleTable
0100     const G4String& GetParticleName(G4int index) const;
0101 
0102     // Returns a pointer to the particle (0 if not contained)
0103     G4ParticleDefinition* FindParticle(G4int PDGEncoding);
0104     G4ParticleDefinition* FindParticle(const G4String& particle_name);
0105     G4ParticleDefinition* FindParticle(const G4ParticleDefinition* particle);
0106 
0107     // Returns a pointer to its anti-particle (0 if not contained)
0108     inline G4ParticleDefinition* FindAntiParticle(G4int PDGEncoding);
0109     inline G4ParticleDefinition* FindAntiParticle(const G4String& p_name);
0110     inline G4ParticleDefinition* FindAntiParticle(const G4ParticleDefinition* p);
0111 
0112     // Returns the pointer to the Iterator
0113     G4PTblDicIterator* GetIterator() const;
0114 
0115     // Dumps information of particles specified by name
0116     void DumpTable(const G4String& particle_name = "ALL");
0117 
0118     // Returns the pointer to the G4IonTable object
0119     G4IonTable* GetIonTable() const;
0120 
0121     // Inserts the particle into ParticleTable.
0122     // Returned value is the same as particle if successfully inserted
0123     //   or the pointer to another G4ParticleDefinition object
0124     //      which has same particle name
0125     //   or nullptr if failing to insert by other reason
0126     G4ParticleDefinition* Insert(G4ParticleDefinition* particle);
0127 
0128     // Removes the particle from the table (not delete)
0129     G4ParticleDefinition* Remove(G4ParticleDefinition* particle);
0130 
0131     // Removes all particles from G4ParticleTable
0132     void RemoveAllParticles();
0133 
0134     // Removes and deletes all particles from G4ParticleTable
0135     void DeleteAllParticles();
0136 
0137     // Creates messenger
0138     G4UImessenger* CreateMessenger();
0139 
0140     void SelectParticle(const G4String& name);
0141 
0142     inline const G4ParticleDefinition* GetSelectedParticle() const;
0143 
0144     inline void SetVerboseLevel(G4int value);
0145     inline G4int GetVerboseLevel() const;
0146 
0147     inline void SetReadiness(G4bool val = true);
0148     inline G4bool GetReadiness() const;
0149 
0150     inline G4ParticleDefinition* GetGenericIon() const;
0151     inline void SetGenericIon(G4ParticleDefinition*);
0152 
0153     inline G4ParticleDefinition* GetGenericMuonicAtom() const;
0154     inline void SetGenericMuonicAtom(G4ParticleDefinition*);
0155 
0156     // Public data ----------------------------------------------------
0157 
0158     // These fields should be thread local or thread private. For a singleton
0159     // class, we can change any member field as static without any problem
0160     // because there is only one instance. Then we are allowed to add
0161     // "G4ThreadLocal"
0162     G4ParticleMessenger* fParticleMessenger = nullptr;
0163     static G4ThreadLocal G4PTblDictionary* fDictionary;
0164     static G4ThreadLocal G4PTblDicIterator* fIterator;
0165     static G4ThreadLocal G4PTblEncodingDictionary* fEncodingDictionary;
0166 
0167     // Particle table is being shared
0168     static G4ParticleTable* fgParticleTable;
0169 
0170     // This field should be thread private. However, we have to keep one copy
0171     // of the ion table pointer. So we change all important fields of
0172     // G4IonTable to be thread local
0173     G4IonTable* fIonTable = nullptr;
0174 
0175     // These shadow pointers are used by each worker thread to copy the content
0176     // from the master thread
0177     //
0178     static G4PTblDictionary* fDictionaryShadow;
0179     static G4PTblDicIterator* fIteratorShadow;
0180     static G4PTblEncodingDictionary* fEncodingDictionaryShadow;
0181 
0182 #ifdef G4MULTITHREADED
0183     // Shared instance of a mutex
0184     static G4GLOB_DLL G4Mutex& particleTableMutex();
0185     static G4GLOB_DLL G4int& lockCount();
0186 #endif
0187 
0188   protected:
0189     const G4PTblDictionary* GetDictionary() const;
0190 
0191     // Returns key value of the particle (i.e. particle name)
0192     inline const G4String& GetKey(const G4ParticleDefinition* particle) const;
0193 
0194     // Returns the pointer to EncodingDictionary
0195     const G4PTblEncodingDictionary* GetEncodingDictionary() const;
0196 
0197   private:
0198     // Provate default constructor
0199     G4ParticleTable();
0200 
0201     void CheckReadiness() const;
0202 
0203     // Private data ---------------------------------------------------
0204 
0205     G4ParticleDefinition* genericIon = nullptr;
0206     G4ParticleDefinition* genericMuonicAtom = nullptr;
0207     const G4ParticleDefinition* selectedParticle = nullptr;
0208 
0209     const G4String noName = " ";
0210     G4String selectedName = "undefined";
0211 
0212     // Control flag for output message
0213     //  0: Silent
0214     //  1: Warning message
0215     //  2: More
0216     G4int verboseLevel = 1;
0217 
0218     G4bool readyToUse = false;
0219 };
0220 
0221 #include "G4ParticleTable.icc"
0222 
0223 #endif