Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ExceptionHandler.cc
Go to the documentation of this file.
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// G4ExceptionHandler implementation
27//
28// Author: M.Asai - August 2002
29// --------------------------------------------------------------------
30
31#include "G4ExceptionHandler.hh"
32
33#include "G4EventManager.hh"
34#include "G4Material.hh"
36#include "G4RunManager.hh"
37#include "G4RunManagerKernel.hh"
38#include "G4StateManager.hh"
39#include "G4Step.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"
49
50#include <cstdlib>
51
52// --------------------------------------------------------------------
54{
55 return (this == &right);
56}
57
58// --------------------------------------------------------------------
60{
61 return (this != &right);
62}
63
64// --------------------------------------------------------------------
65G4bool G4ExceptionHandler::Notify(const char* originOfException, const char* exceptionCode,
66 G4ExceptionSeverity severity, const char* description)
67{
68 static const G4String es_banner =
69 "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
70 static const G4String ee_banner =
71 "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
72 static const G4String ws_banner =
73 "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
74 static const G4String we_banner =
75 "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
76 std::ostringstream message;
77 message << "*** G4Exception : " << exceptionCode << G4endl
78 << " issued by : " << originOfException << G4endl << description << G4endl;
79 G4bool abortionForCoreDump = false;
81 switch (severity) {
82 case FatalException:
83 G4cerr << es_banner << message.str() << "*** Fatal Exception *** core dump ***" << G4endl;
84 DumpTrackInfo();
85 G4cerr << ee_banner << G4endl;
86 abortionForCoreDump = true;
87 break;
89 G4cerr << es_banner << message.str() << "*** Fatal Error In Argument *** core dump ***"
90 << G4endl;
91 DumpTrackInfo();
92 G4cerr << ee_banner << G4endl;
93 abortionForCoreDump = true;
94 break;
96 if (aps == G4State_GeomClosed || aps == G4State_EventProc) {
97 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***" << G4endl;
98 DumpTrackInfo();
99 G4cerr << ee_banner << G4endl;
101 }
102 abortionForCoreDump = false;
103 break;
105 if (aps == G4State_EventProc) {
106 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***" << G4endl;
107 DumpTrackInfo();
108 G4cerr << ee_banner << G4endl;
110 }
111 abortionForCoreDump = false;
112 break;
113 case JustWarning:
114 G4cout << ws_banner << message.str() << "*** This is just a warning message. ***" << we_banner
115 << G4endl;
116 abortionForCoreDump = false;
117 break;
118 default:
119 abortionForCoreDump = false;
120 break;
121 }
122 return abortionForCoreDump;
123}
124
125// --------------------------------------------------------------------
126void G4ExceptionHandler::DumpTrackInfo()
127{
128 const G4Track* theTrack = nullptr;
129 const G4Step* theStep = nullptr;
130 if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_EventProc) {
131 G4SteppingManager* steppingMgr =
133 theTrack = steppingMgr->GetfTrack();
134 theStep = steppingMgr->GetfStep();
135 }
136
137 if (theTrack == nullptr) {
138 G4cerr << " **** Track information is not available at this moment" << G4endl;
139 }
140 else {
141 G4cerr << "G4Track (" << theTrack << ") - track ID = " << theTrack->GetTrackID()
142 << ", parent ID = " << theTrack->GetParentID() << G4endl;
143 G4cerr << " Particle type : " << theTrack->GetParticleDefinition()->GetParticleName();
144 if (theTrack->GetCreatorProcess() != nullptr) {
145 G4cerr << " - creator process : " << theTrack->GetCreatorProcess()->GetProcessName()
146 << ", creator model : " << theTrack->GetCreatorModelName() << G4endl;
147 }
148 else {
149 G4cerr << " - creator process : not available" << G4endl;
150 }
151 G4cerr << " Kinetic energy : " << G4BestUnit(theTrack->GetKineticEnergy(), "Energy")
152 << " - Momentum direction : " << theTrack->GetMomentumDirection() << G4endl;
153 }
154
155 if (theStep == nullptr) {
156 G4cerr << " **** Step information is not available at this moment" << G4endl;
157 }
158 else {
159 G4cerr << " Step length : " << G4BestUnit(theStep->GetStepLength(), "Length")
160 << " - total energy deposit : " << G4BestUnit(theStep->GetTotalEnergyDeposit(), "Energy")
161 << G4endl;
162 G4cerr << " Pre-step point : " << theStep->GetPreStepPoint()->GetPosition();
163 G4cerr << " - Physical volume : ";
164 if (theStep->GetPreStepPoint()->GetPhysicalVolume() != nullptr) {
166 if (theStep->GetPreStepPoint()->GetMaterial() != nullptr) {
167 G4cerr << " (" << theStep->GetPreStepPoint()->GetMaterial()->GetName() << ")";
168 }
169 else {
170 G4cerr << " (material not available)";
171 }
172 }
173 else {
174 G4cerr << "not available";
175 }
176 G4cerr << G4endl;
177 if (theStep->GetPreStepPoint()->GetProcessDefinedStep() != nullptr) {
178 G4cerr << " - defined by : "
180 << " - step status : " << theStep->GetPreStepPoint()->GetStepStatus() << G4endl;
181 }
182 else {
183 G4cerr << " - defined by : not available" << G4endl;
184 }
185 G4cerr << " Post-step point : " << theStep->GetPostStepPoint()->GetPosition();
186 G4cerr << " - Physical volume : ";
187 if (theStep->GetPostStepPoint()->GetPhysicalVolume() != nullptr) {
189 if (theStep->GetPostStepPoint()->GetMaterial() != nullptr) {
190 G4cerr << " (" << theStep->GetPostStepPoint()->GetMaterial()->GetName() << ")";
191 }
192 else {
193 G4cerr << " (material not available)";
194 }
195 }
196 else {
197 G4cerr << "not available";
198 }
199 G4cerr << G4endl;
200 if (theStep->GetPostStepPoint()->GetProcessDefinedStep() != nullptr) {
201 G4cerr << " - defined by : "
203 << " - step status : " << theStep->GetPostStepPoint()->GetStepStatus() << G4endl;
204 }
205 else {
206 G4cerr << " - defined by : not available" << G4endl;
207 }
208 G4cerr << " *** Note: Step information might not be properly updated." << G4endl;
209 }
210}
G4ApplicationState
@ G4State_EventProc
@ G4State_GeomClosed
G4ExceptionSeverity
@ JustWarning
@ FatalException
@ FatalErrorInArgument
@ RunMustBeAborted
@ EventMustBeAborted
#define G4BestUnit(a, b)
bool G4bool
Definition G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4bool operator==(const G4ExceptionHandler &right) const
G4bool operator!=(const G4ExceptionHandler &right) const
G4bool Notify(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description) override
const G4String & GetName() const
const G4String & GetParticleName() const
static G4RunManagerKernel * GetRunManagerKernel()
G4TrackingManager * GetTrackingManager() const
virtual void AbortRun(G4bool softAbort=false)
static G4RunManager * GetRunManager()
virtual void AbortEvent()
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
G4StepStatus GetStepStatus() const
const G4VProcess * GetProcessDefinedStep() const
G4Material * GetMaterial() const
const G4ThreeVector & GetPosition() const
G4VPhysicalVolume * GetPhysicalVolume() const
G4StepPoint * GetPreStepPoint() const
G4double GetStepLength() const
G4double GetTotalEnergyDeposit() const
G4StepPoint * GetPostStepPoint() const
G4int GetTrackID() const
const G4ParticleDefinition * GetParticleDefinition() const
const G4VProcess * GetCreatorProcess() const
const G4String GetCreatorModelName() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetKineticEnergy() const
G4int GetParentID() const
G4SteppingManager * GetSteppingManager() const
const G4String & GetName() const
const G4String & GetProcessName() const