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 << 27 // 26 // 28 // Author: M.Asai - August 2002 << 27 // 29 // ------------------------------------------- << 28 // >> 29 // ------------------------------------------------------------ >> 30 // GEANT 4 class implementation file >> 31 // >> 32 // ---------------- G4ExceptionHandler ---------------- >> 33 // by Makoto Asai (August 2002) >> 34 // ------------------------------------------------------------ 30 35 31 #include "G4ExceptionHandler.hh" 36 #include "G4ExceptionHandler.hh" 32 << 33 #include "G4EventManager.hh" << 34 #include "G4Material.hh" << 35 #include "G4ParticleDefinition.hh" << 36 #include "G4RunManager.hh" << 37 #include "G4RunManagerKernel.hh" << 38 #include "G4StateManager.hh" 37 #include "G4StateManager.hh" 39 #include "G4Step.hh" << 38 #include "G4RunManager.hh" 40 #include "G4StepPoint.hh" << 41 #include "G4SteppingManager.hh" << 42 #include "G4String.hh" << 43 #include "G4Track.hh" << 44 #include "G4TrackingManager.hh" << 45 #include "G4UnitsTable.hh" << 46 #include "G4VPhysicalVolume.hh" << 47 #include "G4VProcess.hh" << 48 #include "G4ios.hh" 39 #include "G4ios.hh" >> 40 #include <stdlib.h> >> 41 #include "G4String.hh" >> 42 >> 43 G4ExceptionHandler::G4ExceptionHandler() >> 44 { >> 45 } >> 46 >> 47 G4ExceptionHandler::~G4ExceptionHandler() >> 48 { >> 49 } >> 50 >> 51 G4ExceptionHandler::G4ExceptionHandler(const G4ExceptionHandler &) >> 52 :G4VExceptionHandler() >> 53 { >> 54 } 49 55 50 #include <cstdlib> << 56 G4ExceptionHandler& G4ExceptionHandler::operator=(const G4ExceptionHandler &) >> 57 { >> 58 return *this; >> 59 } 51 60 52 // ------------------------------------------- << 61 G4bool G4ExceptionHandler::operator==(const G4ExceptionHandler &right) const 53 G4bool G4ExceptionHandler::operator==(const G4 << 54 { 62 { 55 return (this == &right); << 63 return (this == &right); 56 } 64 } 57 65 58 // ------------------------------------------- << 66 G4bool G4ExceptionHandler::operator!=(const G4ExceptionHandler &right) const 59 G4bool G4ExceptionHandler::operator!=(const G4 << 60 { 67 { 61 return (this != &right); << 68 return (this != &right); 62 } 69 } 63 70 64 // ------------------------------------------- << 71 G4bool G4ExceptionHandler::Notify(const char* originOfException, 65 G4bool G4ExceptionHandler::Notify(const char* << 72 const char* exceptionCode, 66 G4ExceptionS << 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 >> 87 << description << 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) 82 case FatalException: << 91 { 83 G4cerr << es_banner << message.str() << << 92 case FatalException: >> 93 G4cerr << es_banner << message.str() << "*** Fatal Exception *** core dump ***" << G4endl; >> 94 DumpTrackInfo(); >> 95 G4cerr << ee_banner << G4endl; >> 96 abortionForCoreDump = true; >> 97 break; >> 98 case FatalErrorInArgument: >> 99 G4cerr << es_banner << message.str() << "*** Fatal Error In Argument *** core dump ***" << G4endl; >> 100 DumpTrackInfo(); >> 101 G4cerr << ee_banner << G4endl; >> 102 abortionForCoreDump = true; >> 103 break; >> 104 case RunMustBeAborted: >> 105 if(aps==G4State_GeomClosed || aps==G4State_EventProc) >> 106 { >> 107 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***" << G4endl; 84 DumpTrackInfo(); 108 DumpTrackInfo(); 85 G4cerr << ee_banner << G4endl; 109 G4cerr << ee_banner << G4endl; 86 abortionForCoreDump = true; << 110 G4RunManager::GetRunManager()->AbortRun(false); 87 break; << 111 } 88 case FatalErrorInArgument: << 112 abortionForCoreDump = false; 89 G4cerr << es_banner << message.str() << << 113 break; 90 << G4endl; << 114 case EventMustBeAborted: >> 115 if(aps==G4State_EventProc) >> 116 { >> 117 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***" << G4endl; 91 DumpTrackInfo(); 118 DumpTrackInfo(); 92 G4cerr << ee_banner << G4endl; 119 G4cerr << ee_banner << G4endl; 93 abortionForCoreDump = true; << 120 G4RunManager::GetRunManager()->AbortEvent(); 94 break; << 121 } 95 case RunMustBeAborted: << 122 abortionForCoreDump = false; 96 if (aps == G4State_GeomClosed || aps == << 123 break; 97 G4cerr << es_banner << message.str() < << 124 default: 98 DumpTrackInfo(); << 125 G4cout << ws_banner << message.str() << "*** This is just a warning message. ***" 99 G4cerr << ee_banner << G4endl; << 126 << we_banner << G4endl; 100 G4RunManager::GetRunManager()->AbortRu << 127 abortionForCoreDump = false; 101 } << 128 break; 102 abortionForCoreDump = false; << 103 break; << 104 case EventMustBeAborted: << 105 if (aps == G4State_EventProc) { << 106 G4cerr << es_banner << message.str() < << 107 DumpTrackInfo(); << 108 G4cerr << ee_banner << G4endl; << 109 G4RunManager::GetRunManager()->AbortEv << 110 } << 111 abortionForCoreDump = false; << 112 break; << 113 case JustWarning: << 114 G4cout << ws_banner << message.str() << << 115 << G4endl; << 116 abortionForCoreDump = false; << 117 break; << 118 default: << 119 abortionForCoreDump = false; << 120 break; << 121 } 129 } 122 return abortionForCoreDump; 130 return abortionForCoreDump; 123 } 131 } 124 132 125 // ------------------------------------------- << 133 #include "G4RunManagerKernel.hh" >> 134 #include "G4EventManager.hh" >> 135 #include "G4TrackingManager.hh" >> 136 #include "G4SteppingManager.hh" >> 137 #include "G4Track.hh" >> 138 #include "G4Step.hh" >> 139 #include "G4StepPoint.hh" >> 140 #include "G4ParticleDefinition.hh" >> 141 #include "G4VProcess.hh" >> 142 #include "G4VPhysicalVolume.hh" >> 143 #include "G4Material.hh" >> 144 #include "G4UnitsTable.hh" >> 145 126 void G4ExceptionHandler::DumpTrackInfo() 146 void G4ExceptionHandler::DumpTrackInfo() 127 { 147 { 128 const G4Track* theTrack = nullptr; << 148 G4ApplicationState aps = G4StateManager::GetStateManager()->GetCurrentState(); 129 const G4Step* theStep = nullptr; << 149 G4SteppingManager* steppingMgr = G4RunManagerKernel::GetRunManagerKernel() 130 if (G4StateManager::GetStateManager()->GetCu << 150 ->GetTrackingManager()->GetSteppingManager(); 131 G4SteppingManager* steppingMgr = << 151 const G4Track* theTrack = steppingMgr->GetfTrack(); 132 G4RunManagerKernel::GetRunManagerKernel( << 152 const G4Step* theStep = steppingMgr->GetfStep(); 133 theTrack = steppingMgr->GetfTrack(); << 134 theStep = steppingMgr->GetfStep(); << 135 } << 136 153 137 if (theTrack == nullptr) { << 154 if(aps!=G4State_EventProc || !theTrack) >> 155 { 138 G4cerr << " **** Track information is not 156 G4cerr << " **** Track information is not available at this moment" << G4endl; 139 } 157 } 140 else { << 158 else >> 159 { 141 G4cerr << "G4Track (" << theTrack << ") - 160 G4cerr << "G4Track (" << theTrack << ") - track ID = " << theTrack->GetTrackID() 142 << ", parent ID = " << theTrack->Ge << 161 << ", parent ID = " << theTrack->GetParentID() << G4endl; 143 G4cerr << " Particle type : " << theTrack- 162 G4cerr << " Particle type : " << theTrack->GetParticleDefinition()->GetParticleName(); 144 if (theTrack->GetCreatorProcess() != nullp << 163 if(theTrack->GetCreatorProcess()) 145 G4cerr << " - creator process : " << the << 164 { G4cerr 146 << ", creator model : " << theTra << 165 << " - creator process : " << theTrack->GetCreatorProcess()->GetProcessName() 147 } << 166 << ", creator model : " << theTrack->GetCreatorModelName() << G4endl; 148 else { << 167 } 149 G4cerr << " - creator process : not avai << 168 else 150 } << 169 { G4cerr << " - creator process : not available" << G4endl; } 151 G4cerr << " Kinetic energy : " << G4BestUn << 170 G4cerr << " Kinetic energy : " << G4BestUnit(theTrack->GetKineticEnergy(),"Energy") 152 << " - Momentum direction : " << th << 171 << " - Momentum direction : " << theTrack->GetMomentumDirection() << G4endl; 153 } 172 } 154 173 155 if (theStep == nullptr) { << 174 if(aps!=G4State_EventProc || !theStep) >> 175 { 156 G4cerr << " **** Step information is not a 176 G4cerr << " **** Step information is not available at this moment" << G4endl; 157 } 177 } 158 else { << 178 else 159 G4cerr << " Step length : " << G4BestUnit( << 179 { 160 << " - total energy deposit : " << << 180 G4cerr << " Step length : " << G4BestUnit(theStep->GetStepLength(),"Length") 161 << G4endl; << 181 << " - total energy deposit : " << G4BestUnit(theStep->GetTotalEnergyDeposit(),"Energy") >> 182 << G4endl; 162 G4cerr << " Pre-step point : " << theStep- 183 G4cerr << " Pre-step point : " << theStep->GetPreStepPoint()->GetPosition(); 163 G4cerr << " - Physical volume : "; 184 G4cerr << " - Physical volume : "; 164 if (theStep->GetPreStepPoint()->GetPhysica << 185 if(theStep->GetPreStepPoint()->GetPhysicalVolume()) >> 186 { 165 G4cerr << theStep->GetPreStepPoint()->Ge 187 G4cerr << theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName(); 166 if (theStep->GetPreStepPoint()->GetMater << 188 if(theStep->GetPreStepPoint()->GetMaterial()) 167 G4cerr << " (" << theStep->GetPreStepP << 189 { G4cerr << " (" << theStep->GetPreStepPoint()->GetMaterial()->GetName() << ")"; } 168 } << 190 else 169 else { << 191 { G4cerr << " (material not available)"; } 170 G4cerr << " (material not available)"; << 171 } << 172 } << 173 else { << 174 G4cerr << "not available"; << 175 } 192 } >> 193 else >> 194 { G4cerr << "not available"; } 176 G4cerr << G4endl; 195 G4cerr << G4endl; 177 if (theStep->GetPreStepPoint()->GetProcess << 196 if(theStep->GetPreStepPoint()->GetProcessDefinedStep()) >> 197 { 178 G4cerr << " - defined by : " 198 G4cerr << " - defined by : " 179 << theStep->GetPreStepPoint()->Ge << 199 << theStep->GetPreStepPoint()->GetProcessDefinedStep()->GetProcessName() 180 << " - step status : " << theStep << 200 << " - step status : " << theStep->GetPreStepPoint()->GetStepStatus() << G4endl; 181 } 201 } 182 else { << 202 else >> 203 { 183 G4cerr << " - defined by : not available 204 G4cerr << " - defined by : not available" << G4endl; 184 } 205 } 185 G4cerr << " Post-step point : " << theStep 206 G4cerr << " Post-step point : " << theStep->GetPostStepPoint()->GetPosition(); 186 G4cerr << " - Physical volume : "; 207 G4cerr << " - Physical volume : "; 187 if (theStep->GetPostStepPoint()->GetPhysic << 208 if(theStep->GetPostStepPoint()->GetPhysicalVolume()) >> 209 { 188 G4cerr << theStep->GetPostStepPoint()->G 210 G4cerr << theStep->GetPostStepPoint()->GetPhysicalVolume()->GetName(); 189 if (theStep->GetPostStepPoint()->GetMate << 211 if(theStep->GetPostStepPoint()->GetMaterial()) 190 G4cerr << " (" << theStep->GetPostStep << 212 { G4cerr << " (" << theStep->GetPostStepPoint()->GetMaterial()->GetName() << ")"; } 191 } << 213 else 192 else { << 214 { G4cerr << " (material not available)"; } 193 G4cerr << " (material not available)"; << 194 } << 195 } << 196 else { << 197 G4cerr << "not available"; << 198 } 215 } >> 216 else >> 217 { G4cerr << "not available"; } 199 G4cerr << G4endl; 218 G4cerr << G4endl; 200 if (theStep->GetPostStepPoint()->GetProces << 219 if(theStep->GetPostStepPoint()->GetProcessDefinedStep()) >> 220 { 201 G4cerr << " - defined by : " 221 G4cerr << " - defined by : " 202 << theStep->GetPostStepPoint()->G << 222 << theStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() 203 << " - step status : " << theStep << 223 << " - step status : " << theStep->GetPostStepPoint()->GetStepStatus() << G4endl; 204 } 224 } 205 else { << 225 else >> 226 { 206 G4cerr << " - defined by : not available 227 G4cerr << " - defined by : not available" << G4endl; 207 } 228 } 208 G4cerr << " *** Note: Step information mig 229 G4cerr << " *** Note: Step information might not be properly updated." << G4endl; 209 } 230 } 210 } 231 } >> 232 211 233