Geant4 10.7.0
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//
27//
28//
29// ------------------------------------------------------------
30// GEANT 4 class implementation file
31//
32// ---------------- G4ExceptionHandler ----------------
33// by Makoto Asai (August 2002)
34// ------------------------------------------------------------
35
36#include "G4ExceptionHandler.hh"
37#include "G4RunManager.hh"
38#include "G4StateManager.hh"
39#include "G4String.hh"
40#include "G4ios.hh"
41#include <stdlib.h>
42
44
46
49{}
50
51G4ExceptionHandler& G4ExceptionHandler::operator=(const G4ExceptionHandler&)
52{
53 return *this;
54}
55
57{
58 return (this == &right);
59}
60
62{
63 return (this != &right);
64}
65
66G4bool G4ExceptionHandler::Notify(const char* originOfException,
67 const char* exceptionCode,
68 G4ExceptionSeverity severity,
69 const char* description)
70{
71 static const G4String es_banner =
72 "\n-------- EEEE ------- G4Exception-START -------- EEEE -------\n";
73 static const G4String ee_banner =
74 "\n-------- EEEE -------- G4Exception-END --------- EEEE -------\n";
75 static const G4String ws_banner =
76 "\n-------- WWWW ------- G4Exception-START -------- WWWW -------\n";
77 static const G4String we_banner =
78 "\n-------- WWWW -------- G4Exception-END --------- WWWW -------\n";
79 std::ostringstream message;
80 message << "*** G4Exception : " << exceptionCode << G4endl
81 << " issued by : " << originOfException << G4endl << description
82 << G4endl;
83 G4bool abortionForCoreDump = false;
85 switch(severity)
86 {
87 case FatalException:
88 G4cerr << es_banner << message.str()
89 << "*** Fatal Exception *** core dump ***" << G4endl;
90 DumpTrackInfo();
91 G4cerr << ee_banner << G4endl;
92 abortionForCoreDump = true;
93 break;
95 G4cerr << es_banner << message.str()
96 << "*** Fatal Error In Argument *** core dump ***" << G4endl;
97 DumpTrackInfo();
98 G4cerr << ee_banner << G4endl;
99 abortionForCoreDump = true;
100 break;
101 case RunMustBeAborted:
102 if(aps == G4State_GeomClosed || aps == G4State_EventProc)
103 {
104 G4cerr << es_banner << message.str() << "*** Run Must Be Aborted ***"
105 << G4endl;
106 DumpTrackInfo();
107 G4cerr << ee_banner << G4endl;
109 }
110 abortionForCoreDump = false;
111 break;
113 if(aps == G4State_EventProc)
114 {
115 G4cerr << es_banner << message.str() << "*** Event Must Be Aborted ***"
116 << G4endl;
117 DumpTrackInfo();
118 G4cerr << ee_banner << G4endl;
120 }
121 abortionForCoreDump = false;
122 break;
123 default:
124 G4cout << ws_banner << message.str()
125 << "*** This is just a warning message. ***" << we_banner
126 << G4endl;
127 abortionForCoreDump = false;
128 break;
129 }
130 return abortionForCoreDump;
131}
132
133#include "G4EventManager.hh"
134#include "G4Material.hh"
136#include "G4RunManagerKernel.hh"
137#include "G4Step.hh"
138#include "G4StepPoint.hh"
139#include "G4SteppingManager.hh"
140#include "G4Track.hh"
141#include "G4TrackingManager.hh"
142#include "G4UnitsTable.hh"
143#include "G4VPhysicalVolume.hh"
144#include "G4VProcess.hh"
145
146void G4ExceptionHandler::DumpTrackInfo()
147{
152 const G4Track* theTrack = steppingMgr->GetfTrack();
153 const G4Step* theStep = steppingMgr->GetfStep();
154
155 if(aps != G4State_EventProc || !theTrack)
156 {
157 G4cerr << " **** Track information is not available at this moment"
158 << G4endl;
159 }
160 else
161 {
162 G4cerr << "G4Track (" << theTrack
163 << ") - track ID = " << theTrack->GetTrackID()
164 << ", parent ID = " << theTrack->GetParentID() << G4endl;
165 G4cerr << " Particle type : "
166 << theTrack->GetParticleDefinition()->GetParticleName();
167 if(theTrack->GetCreatorProcess())
168 {
169 G4cerr << " - creator process : "
170 << theTrack->GetCreatorProcess()->GetProcessName()
171 << ", creator model : " << theTrack->GetCreatorModelName()
172 << G4endl;
173 }
174 else
175 {
176 G4cerr << " - creator process : not available" << G4endl;
177 }
178 G4cerr << " Kinetic energy : "
179 << G4BestUnit(theTrack->GetKineticEnergy(), "Energy")
180 << " - Momentum direction : " << theTrack->GetMomentumDirection()
181 << G4endl;
182 }
183
184 if(aps != G4State_EventProc || !theStep)
185 {
186 G4cerr << " **** Step information is not available at this moment"
187 << G4endl;
188 }
189 else
190 {
191 G4cerr << " Step length : "
192 << G4BestUnit(theStep->GetStepLength(), "Length")
193 << " - total energy deposit : "
194 << G4BestUnit(theStep->GetTotalEnergyDeposit(), "Energy") << G4endl;
195 G4cerr << " Pre-step point : " << theStep->GetPreStepPoint()->GetPosition();
196 G4cerr << " - Physical volume : ";
197 if(theStep->GetPreStepPoint()->GetPhysicalVolume())
198 {
200 if(theStep->GetPreStepPoint()->GetMaterial())
201 {
202 G4cerr << " (" << theStep->GetPreStepPoint()->GetMaterial()->GetName()
203 << ")";
204 }
205 else
206 {
207 G4cerr << " (material not available)";
208 }
209 }
210 else
211 {
212 G4cerr << "not available";
213 }
214 G4cerr << G4endl;
215 if(theStep->GetPreStepPoint()->GetProcessDefinedStep())
216 {
217 G4cerr
218 << " - defined by : "
220 << " - step status : " << theStep->GetPreStepPoint()->GetStepStatus()
221 << G4endl;
222 }
223 else
224 {
225 G4cerr << " - defined by : not available" << G4endl;
226 }
227 G4cerr << " Post-step point : "
228 << theStep->GetPostStepPoint()->GetPosition();
229 G4cerr << " - Physical volume : ";
230 if(theStep->GetPostStepPoint()->GetPhysicalVolume())
231 {
233 if(theStep->GetPostStepPoint()->GetMaterial())
234 {
235 G4cerr << " (" << theStep->GetPostStepPoint()->GetMaterial()->GetName()
236 << ")";
237 }
238 else
239 {
240 G4cerr << " (material not available)";
241 }
242 }
243 else
244 {
245 G4cerr << "not available";
246 }
247 G4cerr << G4endl;
249 {
250 G4cerr << " - defined by : "
251 << theStep->GetPostStepPoint()
254 << " - step status : "
255 << theStep->GetPostStepPoint()->GetStepStatus() << G4endl;
256 }
257 else
258 {
259 G4cerr << " - defined by : not available" << G4endl;
260 }
261 G4cerr << " *** Note: Step information might not be properly updated."
262 << G4endl;
263 }
264}
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:175
const G4String & GetParticleName() const
static G4RunManagerKernel * GetRunManagerKernel()
G4TrackingManager * GetTrackingManager() const
virtual void AbortRun(G4bool softAbort=false)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:84
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
const G4String & GetCreatorModelName() const
G4int GetTrackID() const
const G4ParticleDefinition * GetParticleDefinition() const
const G4VProcess * GetCreatorProcess() 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:382