Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4ExceptionHandler implementation 26 // G4ExceptionHandler implementation 27 // 27 // 28 // Author: M.Asai - August 2002 28 // Author: M.Asai - August 2002 29 // ------------------------------------------- 29 // -------------------------------------------------------------------- 30 30 >> 31 #include <stdlib.h> >> 32 31 #include "G4ExceptionHandler.hh" 33 #include "G4ExceptionHandler.hh" >> 34 #include "G4RunManager.hh" >> 35 #include "G4StateManager.hh" >> 36 #include "G4String.hh" >> 37 #include "G4ios.hh" 32 38 33 #include "G4EventManager.hh" 39 #include "G4EventManager.hh" 34 #include "G4Material.hh" 40 #include "G4Material.hh" 35 #include "G4ParticleDefinition.hh" 41 #include "G4ParticleDefinition.hh" 36 #include "G4RunManager.hh" << 37 #include "G4RunManagerKernel.hh" 42 #include "G4RunManagerKernel.hh" 38 #include "G4StateManager.hh" << 39 #include "G4Step.hh" 43 #include "G4Step.hh" 40 #include "G4StepPoint.hh" 44 #include "G4StepPoint.hh" 41 #include "G4SteppingManager.hh" 45 #include "G4SteppingManager.hh" 42 #include "G4String.hh" << 43 #include "G4Track.hh" 46 #include "G4Track.hh" 44 #include "G4TrackingManager.hh" 47 #include "G4TrackingManager.hh" 45 #include "G4UnitsTable.hh" 48 #include "G4UnitsTable.hh" 46 #include "G4VPhysicalVolume.hh" 49 #include "G4VPhysicalVolume.hh" 47 #include "G4VProcess.hh" 50 #include "G4VProcess.hh" 48 #include "G4ios.hh" << 49 51 50 #include <cstdlib> << 52 // -------------------------------------------------------------------- >> 53 G4ExceptionHandler::G4ExceptionHandler() {} >> 54 >> 55 // -------------------------------------------------------------------- >> 56 G4ExceptionHandler::~G4ExceptionHandler() {} 51 57 52 // ------------------------------------------- 58 // -------------------------------------------------------------------- 53 G4bool G4ExceptionHandler::operator==(const G4 59 G4bool G4ExceptionHandler::operator==(const G4ExceptionHandler& right) const 54 { 60 { 55 return (this == &right); 61 return (this == &right); 56 } 62 } 57 63 58 // ------------------------------------------- 64 // -------------------------------------------------------------------- 59 G4bool G4ExceptionHandler::operator!=(const G4 65 G4bool G4ExceptionHandler::operator!=(const G4ExceptionHandler& right) const 60 { 66 { 61 return (this != &right); 67 return (this != &right); 62 } 68 } 63 69 64 // ------------------------------------------- 70 // -------------------------------------------------------------------- 65 G4bool G4ExceptionHandler::Notify(const char* << 71 G4bool G4ExceptionHandler::Notify(const char* originOfException, 66 G4ExceptionS << 72 const char* exceptionCode, >> 73 G4ExceptionSeverity severity, >> 74 const char* description) 67 { 75 { 68 static const G4String es_banner = 76 static const G4String es_banner = 69 "\n-------- EEEE ------- G4Exception-START 77 "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n"; 70 static const G4String ee_banner = 78 static const G4String ee_banner = 71 "\n-------- EEEE -------- G4Exception-END 79 "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n"; 72 static const G4String ws_banner = 80 static const G4String ws_banner = 73 "\n-------- WWWW ------- G4Exception-START 81 "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n"; 74 static const G4String we_banner = 82 static const G4String we_banner = 75 "\n-------- WWWW -------- G4Exception-END 83 "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n"; 76 std::ostringstream message; 84 std::ostringstream message; 77 message << "*** G4Exception : " << exception 85 message << "*** G4Exception : " << exceptionCode << G4endl 78 << " issued by : " << originOfE << 86 << " issued by : " << originOfException << G4endl << description >> 87 << G4endl; 79 G4bool abortionForCoreDump = false; 88 G4bool abortionForCoreDump = false; 80 G4ApplicationState aps = G4StateManager::Get 89 G4ApplicationState aps = G4StateManager::GetStateManager()->GetCurrentState(); 81 switch (severity) { << 90 switch(severity) >> 91 { 82 case FatalException: 92 case FatalException: 83 G4cerr << es_banner << message.str() << << 93 G4cerr << es_banner << message.str() >> 94 << "*** Fatal Exception *** core dump ***" << G4endl; 84 DumpTrackInfo(); 95 DumpTrackInfo(); 85 G4cerr << ee_banner << G4endl; 96 G4cerr << ee_banner << G4endl; 86 abortionForCoreDump = true; 97 abortionForCoreDump = true; 87 break; 98 break; 88 case FatalErrorInArgument: 99 case FatalErrorInArgument: 89 G4cerr << es_banner << message.str() << << 100 G4cerr << es_banner << message.str() 90 << G4endl; << 101 << "*** Fatal Error In Argument *** core dump ***" << G4endl; 91 DumpTrackInfo(); 102 DumpTrackInfo(); 92 G4cerr << ee_banner << G4endl; 103 G4cerr << ee_banner << G4endl; 93 abortionForCoreDump = true; 104 abortionForCoreDump = true; 94 break; 105 break; 95 case RunMustBeAborted: 106 case RunMustBeAborted: 96 if (aps == G4State_GeomClosed || aps == << 107 if(aps == G4State_GeomClosed || aps == G4State_EventProc) 97 G4cerr << es_banner << message.str() < << 108 { >> 109 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***" >> 110 << G4endl; 98 DumpTrackInfo(); 111 DumpTrackInfo(); 99 G4cerr << ee_banner << G4endl; 112 G4cerr << ee_banner << G4endl; 100 G4RunManager::GetRunManager()->AbortRu 113 G4RunManager::GetRunManager()->AbortRun(false); 101 } 114 } 102 abortionForCoreDump = false; 115 abortionForCoreDump = false; 103 break; 116 break; 104 case EventMustBeAborted: 117 case EventMustBeAborted: 105 if (aps == G4State_EventProc) { << 118 if(aps == G4State_EventProc) 106 G4cerr << es_banner << message.str() < << 119 { >> 120 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***" >> 121 << G4endl; 107 DumpTrackInfo(); 122 DumpTrackInfo(); 108 G4cerr << ee_banner << G4endl; 123 G4cerr << ee_banner << G4endl; 109 G4RunManager::GetRunManager()->AbortEv 124 G4RunManager::GetRunManager()->AbortEvent(); 110 } 125 } 111 abortionForCoreDump = false; 126 abortionForCoreDump = false; 112 break; 127 break; 113 case JustWarning: << 114 G4cout << ws_banner << message.str() << << 115 << G4endl; << 116 abortionForCoreDump = false; << 117 break; << 118 default: 128 default: >> 129 G4cout << ws_banner << message.str() >> 130 << "*** This is just a warning message. ***" << we_banner >> 131 << G4endl; 119 abortionForCoreDump = false; 132 abortionForCoreDump = false; 120 break; 133 break; 121 } 134 } 122 return abortionForCoreDump; 135 return abortionForCoreDump; 123 } 136 } 124 137 125 // ------------------------------------------- 138 // -------------------------------------------------------------------- 126 void G4ExceptionHandler::DumpTrackInfo() 139 void G4ExceptionHandler::DumpTrackInfo() 127 { 140 { 128 const G4Track* theTrack = nullptr; << 141 const G4Track *theTrack = nullptr; 129 const G4Step* theStep = nullptr; << 142 const G4Step *theStep = nullptr; 130 if (G4StateManager::GetStateManager()->GetCu << 143 if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_EventProc) 131 G4SteppingManager* steppingMgr = << 144 { 132 G4RunManagerKernel::GetRunManagerKernel( << 145 G4SteppingManager *steppingMgr = G4RunManagerKernel::GetRunManagerKernel() >> 146 ->GetTrackingManager() >> 147 ->GetSteppingManager(); 133 theTrack = steppingMgr->GetfTrack(); 148 theTrack = steppingMgr->GetfTrack(); 134 theStep = steppingMgr->GetfStep(); 149 theStep = steppingMgr->GetfStep(); 135 } 150 } 136 151 137 if (theTrack == nullptr) { << 152 if (theTrack == nullptr) 138 G4cerr << " **** Track information is not << 153 { >> 154 G4cerr << " **** Track information is not available at this moment" >> 155 << G4endl; 139 } 156 } 140 else { << 157 else 141 G4cerr << "G4Track (" << theTrack << ") - << 158 { >> 159 G4cerr << "G4Track (" << theTrack >> 160 << ") - track ID = " << theTrack->GetTrackID() 142 << ", parent ID = " << theTrack->Ge 161 << ", parent ID = " << theTrack->GetParentID() << G4endl; 143 G4cerr << " Particle type : " << theTrack- << 162 G4cerr << " Particle type : " 144 if (theTrack->GetCreatorProcess() != nullp << 163 << theTrack->GetParticleDefinition()->GetParticleName(); 145 G4cerr << " - creator process : " << the << 164 if(theTrack->GetCreatorProcess()) 146 << ", creator model : " << theTra << 165 { >> 166 G4cerr << " - creator process : " >> 167 << theTrack->GetCreatorProcess()->GetProcessName() >> 168 << ", creator model : " << theTrack->GetCreatorModelName() >> 169 << G4endl; 147 } 170 } 148 else { << 171 else >> 172 { 149 G4cerr << " - creator process : not avai 173 G4cerr << " - creator process : not available" << G4endl; 150 } 174 } 151 G4cerr << " Kinetic energy : " << G4BestUn << 175 G4cerr << " Kinetic energy : " 152 << " - Momentum direction : " << th << 176 << G4BestUnit(theTrack->GetKineticEnergy(), "Energy") >> 177 << " - Momentum direction : " << theTrack->GetMomentumDirection() >> 178 << G4endl; 153 } 179 } 154 180 155 if (theStep == nullptr) { << 181 if (theStep == nullptr) 156 G4cerr << " **** Step information is not a << 182 { 157 } << 183 G4cerr << " **** Step information is not available at this moment" 158 else { << 159 G4cerr << " Step length : " << G4BestUnit( << 160 << " - total energy deposit : " << << 161 << G4endl; 184 << G4endl; >> 185 } >> 186 else >> 187 { >> 188 G4cerr << " Step length : " >> 189 << G4BestUnit(theStep->GetStepLength(), "Length") >> 190 << " - total energy deposit : " >> 191 << G4BestUnit(theStep->GetTotalEnergyDeposit(), "Energy") << G4endl; 162 G4cerr << " Pre-step point : " << theStep- 192 G4cerr << " Pre-step point : " << theStep->GetPreStepPoint()->GetPosition(); 163 G4cerr << " - Physical volume : "; 193 G4cerr << " - Physical volume : "; 164 if (theStep->GetPreStepPoint()->GetPhysica << 194 if(theStep->GetPreStepPoint()->GetPhysicalVolume()) >> 195 { 165 G4cerr << theStep->GetPreStepPoint()->Ge 196 G4cerr << theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName(); 166 if (theStep->GetPreStepPoint()->GetMater << 197 if(theStep->GetPreStepPoint()->GetMaterial()) 167 G4cerr << " (" << theStep->GetPreStepP << 198 { >> 199 G4cerr << " (" << theStep->GetPreStepPoint()->GetMaterial()->GetName() >> 200 << ")"; 168 } 201 } 169 else { << 202 else >> 203 { 170 G4cerr << " (material not available)"; 204 G4cerr << " (material not available)"; 171 } 205 } 172 } 206 } 173 else { << 207 else >> 208 { 174 G4cerr << "not available"; 209 G4cerr << "not available"; 175 } 210 } 176 G4cerr << G4endl; 211 G4cerr << G4endl; 177 if (theStep->GetPreStepPoint()->GetProcess << 212 if(theStep->GetPreStepPoint()->GetProcessDefinedStep()) 178 G4cerr << " - defined by : " << 213 { 179 << theStep->GetPreStepPoint()->Ge << 214 G4cerr 180 << " - step status : " << theStep << 215 << " - defined by : " >> 216 << theStep->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName() >> 217 << " - step status : " << theStep->GetPreStepPoint()->GetStepStatus() >> 218 << G4endl; 181 } 219 } 182 else { << 220 else >> 221 { 183 G4cerr << " - defined by : not available 222 G4cerr << " - defined by : not available" << G4endl; 184 } 223 } 185 G4cerr << " Post-step point : " << theStep << 224 G4cerr << " Post-step point : " >> 225 << theStep->GetPostStepPoint()->GetPosition(); 186 G4cerr << " - Physical volume : "; 226 G4cerr << " - Physical volume : "; 187 if (theStep->GetPostStepPoint()->GetPhysic << 227 if(theStep->GetPostStepPoint()->GetPhysicalVolume()) >> 228 { 188 G4cerr << theStep->GetPostStepPoint()->G 229 G4cerr << theStep->GetPostStepPoint()->GetPhysicalVolume()->GetName(); 189 if (theStep->GetPostStepPoint()->GetMate << 230 if(theStep->GetPostStepPoint()->GetMaterial()) 190 G4cerr << " (" << theStep->GetPostStep << 231 { >> 232 G4cerr << " (" << theStep->GetPostStepPoint()->GetMaterial()->GetName() >> 233 << ")"; 191 } 234 } 192 else { << 235 else >> 236 { 193 G4cerr << " (material not available)"; 237 G4cerr << " (material not available)"; 194 } 238 } 195 } 239 } 196 else { << 240 else >> 241 { 197 G4cerr << "not available"; 242 G4cerr << "not available"; 198 } 243 } 199 G4cerr << G4endl; 244 G4cerr << G4endl; 200 if (theStep->GetPostStepPoint()->GetProces << 245 if(theStep->GetPostStepPoint()->GetProcessDefinedStep()) >> 246 { 201 G4cerr << " - defined by : " 247 G4cerr << " - defined by : " 202 << theStep->GetPostStepPoint()->G << 248 << theStep->GetPostStepPoint() 203 << " - step status : " << theStep << 249 ->GetProcessDefinedStep() >> 250 ->GetProcessName() >> 251 << " - step status : " >> 252 << theStep->GetPostStepPoint()->GetStepStatus() << G4endl; 204 } 253 } 205 else { << 254 else >> 255 { 206 G4cerr << " - defined by : not available 256 G4cerr << " - defined by : not available" << G4endl; 207 } 257 } 208 G4cerr << " *** Note: Step information mig << 258 G4cerr << " *** Note: Step information might not be properly updated." >> 259 << G4endl; 209 } 260 } 210 } 261 } 211 262