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 // 27 // ------------------------------------------------------------ 28 // GEANT 4 class implementation file 29 // ------------------------------------------------------------ 30 // 31 32 #include "G4Navigator.hh" 33 34 #include "G4Timer.hh" 35 36 #include "G4ErrorRunManagerHelper.hh" 37 38 #include "G4RunManagerKernel.hh" 39 #include "G4VUserDetectorConstruction.hh" 40 #include "G4ErrorPhysicsList.hh" 41 #include "G4TransportationManager.hh" 42 #include "G4RunManager.hh" 43 44 //----------------------------------------------------------------------- 45 46 G4ThreadLocal G4ErrorRunManagerHelper* 47 G4ErrorRunManagerHelper::fRunManagerKernel = 0; 48 49 //----------------------------------------------------------------------- 50 G4ErrorRunManagerHelper* G4ErrorRunManagerHelper::GetRunManagerKernel() 51 { 52 return fRunManagerKernel; 53 } 54 55 //----------------------------------------------------------------------- 56 G4ErrorRunManagerHelper::G4ErrorRunManagerHelper() 57 { 58 if(fRunManagerKernel) 59 { 60 G4Exception("G4ErrorRunManagerHelper::G4ErrorRunManagerHelper()", 61 "InvalidSetup", FatalException, 62 "G4eRunManageKernel constructed twice."); 63 } 64 fRunManagerKernel = this; 65 66 //----- Look if somebody has created a G4RunManagerKernel 67 theG4RunManagerKernel = G4RunManagerKernel::GetRunManagerKernel(); 68 if(theG4RunManagerKernel == 0) 69 { 70 //--- if not create it 71 theG4RunManagerKernel = new G4RunManagerKernel(); 72 G4cout << " creating G4RunManagerKernel " << theG4RunManagerKernel 73 << G4endl; 74 } 75 76 theG4RunManagerKernel->SetVerboseLevel(2); 77 theUserPhysicsList = 0; 78 theUserWorld = 0; 79 } 80 81 //----------------------------------------------------------------------- 82 G4ErrorRunManagerHelper::~G4ErrorRunManagerHelper() {} 83 84 //----------------------------------------------------------------------- 85 void G4ErrorRunManagerHelper::SetUserInitialization( 86 G4VUserDetectorConstruction* userInit) 87 { 88 theUserWorld = userInit->Construct(); 89 } 90 91 //----------------------------------------------------------------------- 92 void G4ErrorRunManagerHelper::SetUserInitialization(G4VPhysicalVolume* userInit) 93 { 94 theUserWorld = userInit; 95 } 96 97 //----------------------------------------------------------------------- 98 void G4ErrorRunManagerHelper::SetUserInitialization( 99 G4VUserPhysicsList* userInit) 100 { 101 theUserPhysicsList = userInit; 102 } 103 104 //----------------------------------------------------------------------- 105 void G4ErrorRunManagerHelper::InitializeGeometry() 106 { 107 // check if user world has been directly called or someone initialized the 108 // world volume already 109 //----- First option: geometry has been defined to GEANT4e 110 if(theUserWorld != 0) 111 { 112 theG4RunManagerKernel->DefineWorldVolume(theUserWorld); 113 114 //----- Second option: geometry has been defined to GEANT4, do nothing 115 //GEANT4 should take care 116 } 117 else 118 { 119 //--- Check that indeed geometry has been defined to GEANT4 120 if(G4TransportationManager::GetTransportationManager() 121 ->GetNavigatorForTracking() 122 ->GetWorldVolume() == 0) 123 { 124 G4Exception("G4ErrorRunManagerHelper::InitializeGeometry()", 125 "InvalisSetup", FatalException, 126 "No world defined in your geometry!"); 127 } 128 } 129 } 130 131 //----------------------------------------------------------------------- 132 void G4ErrorRunManagerHelper::InitializePhysics() 133 { 134 G4cout << " G4ErrorRunManagerHelper::InitializePhysics " << G4endl; 135 136 //----- First option: physics list has been defined to GEANT4e 137 if(theUserPhysicsList != 0) 138 { 139 theG4RunManagerKernel->SetPhysics(theUserPhysicsList); 140 theG4RunManagerKernel->InitializePhysics(); 141 } 142 else 143 { 144 //----- Second option: physics list has been defined to GEANT4, do nothing 145 //GEANT4 should take care 146 if(G4RunManager::GetRunManager() != 0 && 147 G4RunManager::GetRunManager()->GetUserPhysicsList() != 0) 148 { 149 //--- Physics should be G4ErrorPhysicsList, else send a warning 150 if(static_cast<const G4ErrorPhysicsList*>( 151 G4RunManager::GetRunManager()->GetUserPhysicsList()) == 0) 152 { 153 std::ostringstream message; 154 message << "Physics list is not G4ErrorPhysicsList. Are you sure?"; 155 G4Exception("G4ErrorRunManagerHelper::InitializePhysics()", 156 "GEANT4e-Notification", JustWarning, message); 157 } 158 } 159 else 160 { 161 //----- Third option: no physics list has been defined, define a 162 //G4ErrorPhysicsList 163 theG4RunManagerKernel->SetPhysics(new G4ErrorPhysicsList); 164 // theG4RunManagerKernel->SetPhysics(new ExN02PhysicsList); 165 theG4RunManagerKernel->InitializePhysics(); 166 } 167 } 168 } 169 170 //----------------------------------------------------------------------- 171 void G4ErrorRunManagerHelper::RunInitialization() 172 { 173 theG4RunManagerKernel->RunInitialization(); 174 } 175 176 //----------------------------------------------------------------------- 177 void G4ErrorRunManagerHelper::SetUserAction(G4UserTrackingAction* userAction) 178 { 179 G4EventManager::GetEventManager()->SetUserAction(userAction); 180 } 181 182 //----------------------------------------------------------------------- 183 void G4ErrorRunManagerHelper::SetUserAction(G4UserSteppingAction* userAction) 184 { 185 G4EventManager::GetEventManager()->SetUserAction(userAction); 186 } 187 188 //----------------------------------------------------------------------- 189 void G4ErrorRunManagerHelper::RunTermination() 190 { 191 theG4RunManagerKernel->RunTermination(); 192 } 193