Geant4 11.1.1
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 <stdlib.h>
32
33#include "G4ExceptionHandler.hh"
34#include "G4RunManager.hh"
35#include "G4StateManager.hh"
36#include "G4String.hh"
37#include "G4ios.hh"
38
39#include "G4EventManager.hh"
40#include "G4Material.hh"
42#include "G4RunManagerKernel.hh"
43#include "G4Step.hh"
44#include "G4StepPoint.hh"
45#include "G4SteppingManager.hh"
46#include "G4Track.hh"
47#include "G4TrackingManager.hh"
48#include "G4UnitsTable.hh"
49#include "G4VPhysicalVolume.hh"
50#include "G4VProcess.hh"
51
52// --------------------------------------------------------------------
54
55// --------------------------------------------------------------------
57
58// --------------------------------------------------------------------
60{
61 return (this == &right);
62}
63
64// --------------------------------------------------------------------
66{
67 return (this != &right);
68}
69
70// --------------------------------------------------------------------
71G4bool G4ExceptionHandler::Notify(const char* originOfException,
72 const char* exceptionCode,
73 G4ExceptionSeverity severity,
74 const char* description)
75{
76 static const G4String es_banner =
77 "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
78 static const G4String ee_banner =
79 "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
80 static const G4String ws_banner =
81 "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
82 static const G4String we_banner =
83 "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
84 std::ostringstream message;
85 message << "*** G4Exception : " << exceptionCode << G4endl
86 << " issued by : " << originOfException << G4endl << description
87 << G4endl;
88 G4bool abortionForCoreDump = false;
90 switch(severity)
91 {
92 case FatalException:
93 G4cerr << es_banner << message.str()
94 << "*** Fatal Exception *** core dump ***" << G4endl;
95 DumpTrackInfo();
96 G4cerr << ee_banner << G4endl;
97 abortionForCoreDump = true;
98 break;
100 G4cerr << es_banner << message.str()
101 << "*** Fatal Error In Argument *** core dump ***" << G4endl;
102 DumpTrackInfo();
103 G4cerr << ee_banner << G4endl;
104 abortionForCoreDump = true;
105 break;
106 case RunMustBeAborted:
107 if(aps == G4State_GeomClosed || aps == G4State_EventProc)
108 {
109 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
110 << G4endl;
111 DumpTrackInfo();
112 G4cerr << ee_banner << G4endl;
114 }
115 abortionForCoreDump = false;
116 break;
118 if(aps == G4State_EventProc)
119 {
120 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
121 << G4endl;
122 DumpTrackInfo();
123 G4cerr << ee_banner << G4endl;
125 }
126 abortionForCoreDump = false;
127 break;
128 default:
129 G4cout << ws_banner << message.str()
130 << "*** This is just a warning message. ***" << we_banner
131 << G4endl;
132 abortionForCoreDump = false;
133 break;
134 }
135 return abortionForCoreDump;
136}
137
138// --------------------------------------------------------------------
139void G4ExceptionHandler::DumpTrackInfo()
140{
141 const G4Track *theTrack = nullptr;
142 const G4Step *theStep = nullptr;
143 if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_EventProc)
144 {
148 theTrack = steppingMgr->GetfTrack();
149 theStep = steppingMgr->GetfStep();
150 }
151
152 if (theTrack == nullptr)
153 {
154 G4cerr << " **** Track information is not available at this moment"
155 << G4endl;
156 }
157 else
158 {
159 G4cerr << "G4Track (" << theTrack
160 << ") - track ID = " << theTrack->GetTrackID()
161 << ", parent ID = " << theTrack->GetParentID() << G4endl;
162 G4cerr << " Particle type : "
163 << theTrack->GetParticleDefinition()->GetParticleName();
164 if(theTrack->GetCreatorProcess())
165 {
166 G4cerr << " - creator process : "
167 << theTrack->GetCreatorProcess()->GetProcessName()
168 << ", creator model : " << theTrack->GetCreatorModelName()
169 << G4endl;
170 }
171 else
172 {
173 G4cerr << " - creator process : not available" << G4endl;
174 }
175 G4cerr << " Kinetic energy : "
176 << G4BestUnit(theTrack->GetKineticEnergy(), "Energy")
177 << " - Momentum direction : " << theTrack->GetMomentumDirection()
178 << G4endl;
179 }
180
181 if (theStep == nullptr)
182 {
183 G4cerr << " **** Step information is not available at this moment"
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;
192 G4cerr << " Pre-step point : " << theStep->GetPreStepPoint()->GetPosition();
193 G4cerr << " - Physical volume : ";
194 if(theStep->GetPreStepPoint()->GetPhysicalVolume())
195 {
197 if(theStep->GetPreStepPoint()->GetMaterial())
198 {
199 G4cerr << " (" << theStep->GetPreStepPoint()->GetMaterial()->GetName()
200 << ")";
201 }
202 else
203 {
204 G4cerr << " (material not available)";
205 }
206 }
207 else
208 {
209 G4cerr << "not available";
210 }
211 G4cerr << G4endl;
212 if(theStep->GetPreStepPoint()->GetProcessDefinedStep())
213 {
214 G4cerr
215 << " - defined by : "
217 << " - step status : " << theStep->GetPreStepPoint()->GetStepStatus()
218 << G4endl;
219 }
220 else
221 {
222 G4cerr << " - defined by : not available" << G4endl;
223 }
224 G4cerr << " Post-step point : "
225 << theStep->GetPostStepPoint()->GetPosition();
226 G4cerr << " - Physical volume : ";
227 if(theStep->GetPostStepPoint()->GetPhysicalVolume())
228 {
230 if(theStep->GetPostStepPoint()->GetMaterial())
231 {
232 G4cerr << " (" << theStep->GetPostStepPoint()->GetMaterial()->GetName()
233 << ")";
234 }
235 else
236 {
237 G4cerr << " (material not available)";
238 }
239 }
240 else
241 {
242 G4cerr << "not available";
243 }
244 G4cerr << G4endl;
246 {
247 G4cerr << " - defined by : "
248 << theStep->GetPostStepPoint()
251 << " - step status : "
252 << theStep->GetPostStepPoint()->GetStepStatus() << G4endl;
253 }
254 else
255 {
256 G4cerr << " - defined by : not available" << G4endl;
257 }
258 G4cerr << " *** Note: Step information might not be properly updated."
259 << G4endl;
260 }
261}
G4ApplicationState
@ G4State_EventProc
@ G4State_GeomClosed
G4ExceptionSeverity
@ FatalException
@ FatalErrorInArgument
@ RunMustBeAborted
@ EventMustBeAborted
#define G4BestUnit(a, b)
bool G4bool
Definition: G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool operator==(const G4ExceptionHandler &right) const
G4bool operator!=(const G4ExceptionHandler &right) const
virtual G4bool Notify(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
const G4String & GetName() const
Definition: G4Material.hh:172
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
Definition: G4Step.hh:62
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
Definition: G4VProcess.hh:386