Geant4 Cross Reference |
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 // G4VModularPhysicsList 27 // 28 // Class description: 29 // 30 // This class is a subclass of G4VUserPhysicsList. 31 // The user should register his/her physics constructors by using: 32 // G4VModularPhysicsList::RegsiterPhysics() 33 // to construt particles and processes. 34 // 35 // Only one physics constructor can be registered for each "physics_type". 36 // Physics constructors with same "physics_type" can be replaced using the 37 // G4VModularPhysicsList::ReplacePhysics() method. 38 39 // Original author: H.Kurashige (Kobe University), 12 November 2000 40 // -------------------------------------------------------------------- 41 #ifndef G4VModularPhysicsList_hh 42 #define G4VModularPhysicsList_hh 1 43 44 #include "G4VPhysicsConstructor.hh" 45 #include "G4VUPLSplitter.hh" 46 #include "G4VUserPhysicsList.hh" 47 #include "G4ios.hh" 48 #include "globals.hh" 49 50 #include "rundefs.hh" 51 52 #include <vector> 53 54 class G4VMPLData 55 { 56 // Encapsulate the fields of class G4VModularPhysicsList 57 // that are per-thread. 58 59 public: 60 void initialize(); 61 using G4PhysConstVectorData = std::vector<G4VPhysicsConstructor*>; 62 // See: https://jira-geant4.kek.jp/browse/DEV-284 63 G4PhysConstVectorData* physicsVector = nullptr; 64 }; 65 66 // The type G4VMPLManager is introduced to encapsulate the methods used by 67 // both the master thread and worker threads to allocate memory space for 68 // the fields encapsulated by the class G4VMPLData. When each thread 69 // changes the value for these fields, it refers to them using a macro 70 // definition defined below. For every G4VUserPhysicsList instance, 71 // there is a corresponding G4VMPLData instance. All G4VMPLData instances 72 // are organized by the class G4VMPLManager as an array. 73 // The field "int G4VMPLInstanceID" is added to the class G4VUserPhysicsList. 74 // The value of this field in each G4VUserPhysicsList instance is the 75 // subscript of the corresponding G44VUPLData instance. 76 // In order to use the class G44VUPLManager, we add a static member in the class 77 // G4VUserPhysicsList as follows: "static G4VMPLManager subInstanceManager". 78 // Both the master thread and worker threads change the length of the array 79 // for G44VUPLData instances mutually along with G4VUserPhysicsList 80 // instances are created. 81 // 82 using G4VMPLManager = G4VUPLSplitter<G4VMPLData>; 83 using G4VModularPhysicsListSubInstanceManager = G4VMPLManager; 84 85 class G4VModularPhysicsList : public virtual G4VUserPhysicsList 86 { 87 public: 88 G4VModularPhysicsList(); 89 ~G4VModularPhysicsList() override; 90 91 // This method will be invoked in the Construct() method. 92 // Each particle type will be instantiated. 93 void ConstructParticle() override; 94 95 // This method will be invoked in the Construct() method. 96 // Each physics process will be instantiated and 97 // registered to the process manager of each particle type. 98 void ConstructProcess() override; 99 100 // Register Physics Constructor. 101 void RegisterPhysics(G4VPhysicsConstructor*); 102 103 const G4VPhysicsConstructor* GetPhysics(G4int index) const; 104 const G4VPhysicsConstructor* GetPhysics(const G4String& name) const; 105 const G4VPhysicsConstructor* GetPhysicsWithType(G4int physics_type) const; 106 107 // Replace the Physics Constructor. 108 // The existing physics constructor with same physics_type as one of 109 // the given physics constructor is replaced (existing physics will be 110 // deleted). If a corresponding physics constructor is NOT found, 111 // the given physics constructor is just added. 112 void ReplacePhysics(G4VPhysicsConstructor*); 113 114 // Remove the Physics Constructor from the list. 115 void RemovePhysics(G4VPhysicsConstructor*); 116 void RemovePhysics(G4int type); 117 void RemovePhysics(const G4String& name); 118 119 inline G4int GetInstanceID() const; 120 static const G4VMPLManager& GetSubInstanceManager(); 121 void TerminateWorker() override; 122 123 // Set/get control flag for output message 124 // 0: Silent 125 // 1: Warning message 126 // 2: More 127 // given verbose level is set to all physics constructors. 128 void SetVerboseLevel(G4int value); 129 G4int GetVerboseLevel() const; 130 131 protected: 132 // Protected copy constructor and assignment operator. 133 G4VModularPhysicsList(const G4VModularPhysicsList&); 134 G4VModularPhysicsList& operator=(const G4VModularPhysicsList&); 135 136 using G4PhysConstVector = G4VMPLData::G4PhysConstVectorData; 137 138 G4int verboseLevel = 0; 139 G4int g4vmplInstanceID = 0; 140 G4RUN_DLL static G4VMPLManager G4VMPLsubInstanceManager; 141 }; 142 143 // Inline methods implementations 144 145 inline G4int G4VModularPhysicsList::GetVerboseLevel() const 146 { 147 return verboseLevel; 148 } 149 150 inline G4int G4VModularPhysicsList::GetInstanceID() const 151 { 152 return g4vmplInstanceID; 153 } 154 155 inline const G4VMPLManager& G4VModularPhysicsList::GetSubInstanceManager() 156 { 157 return G4VMPLsubInstanceManager; 158 } 159 160 #endif 161