CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ExceptionHandler.cc
Go to the documentation of this file.
4 
6 
7 #include "G4EventManager.hh"
8 #include "G4StateManager.hh"
9 #include "G4ios.hh"
10 
11 using std::cout;
12 using std::endl;
13 using std::string;
14 
16  : fRunManager(rm),fRunManagerMT(0)
17 {}
18 
20  : fRunManager(0),fRunManagerMT(rm)
21 {}
22 
24 
25 bool ExceptionHandler::Notify(const char* exceptionOrigin,
26  const char* exceptionCode,
27  G4ExceptionSeverity severity,
28  const char* description)
29 {
30  cout << endl;
31  cout << "*** G4Exception : " << exceptionCode << " issued by " << exceptionOrigin << endl;
32  cout << " " << description << endl;
33  bool abortionForCoreDump = false;
34  G4ApplicationState aps = G4StateManager::GetStateManager()->GetCurrentState();
35  switch(severity)
36  {
37  case FatalException:
38  if ( aps==G4State_EventProc && exceptionOrigin==string("G4HadronicProcess") )
39  {
40  cout << "*** Fatal exception *** " << endl;
41  throw SimG4Exception( "SimG4CoreApplication: Bug in G4HadronicProcess" ) ;
42  }
43  else
44  {
45  cout << "*** Fatal exception *** core dump ***" << endl;
46  abortionForCoreDump = true;
47  }
48 /*
49  cout << "*** Fatal exception *** core dump ***" << endl;
50  abortionForCoreDump = true;
51 */
52  break;
53  case FatalErrorInArgument:
54  cout << "*** Fatal error in argument *** core dump ***" << endl;
55  abortionForCoreDump = true;
56  break;
57  case RunMustBeAborted:
58  if(aps==G4State_GeomClosed || aps==G4State_EventProc)
59  {
60  cout << "*** Run must be aborted " << endl;
61  if(fRunManager) { fRunManager->abortRun(false); }
62  if(fRunManagerMT) { fRunManagerMT->abortRun(false); }
63  }
64  abortionForCoreDump = false;
65  break;
66  case EventMustBeAborted:
67  if(aps==G4State_EventProc)
68  {
69  cout << "*** Event must be aborted " << endl;
70  // if (override && exceptionCode == string("StuckTrack"))
71 /*
72  if (exceptionCode == string("StuckTrack"))
73  {
74  //if (verbose > 1) cout << "*** overriden by user " << endl;
75  G4Track * t = G4EventManager::GetEventManager()->GetTrackingManager()->GetTrack();
76  //if (verbose > 1)
77  cout << " ERROR - G4Navigator::ComputeStep() " << endl
78  << " Track " << t->GetTrackID() << " stuck "
79  << " in volume " << t->GetVolume()->GetName()
80  << " at point " << t->GetPosition()/mm << " mm "<< endl
81  << " with direction: " << t->GetMomentumDirection()
82  << " and distance to out "
83  << (t->GetVolume()->GetLogicalVolume()->GetSolid())
84  ->DistanceToOut(t->GetPosition())/mm << " mm " << endl;
85  //if (verbose > 1)
86  cout << " Particle " << t->GetDynamicParticle()->GetDefinition()->GetParticleName()
87  << " from parent ID " << t->GetParentID() << endl
88  << " with " << t->GetKineticEnergy()/MeV << " MeV kinetic energy "
89  << " created in " << t->GetLogicalVolumeAtVertex()->GetName() << endl;
90  cout << " *** StuckTrack: track status set to fStopButAlive " << endl;
91  t->SetTrackStatus(fStopButAlive);
92  }
93  else
94 */
95  //fRunManager->abortEvent();
96  //RunManager::instance()->abortEvent() ;
97  throw SimG4Exception( "SimG4CoreApplication: G4Navigator:StuckTrack detected" ) ;
98  }
99  abortionForCoreDump = false;
100  break;
101  default:
102  cout << "*** This is just a warning message " << endl;
103  abortionForCoreDump = false;
104  break;
105  }
106  cout << endl;
107  return abortionForCoreDump;
108 }
109 
virtual ~ExceptionHandler()
void abortRun(bool softAbort=false)
Definition: RunManager.cc:486
void abortRun(bool softAbort=false)
Definition: RunManagerMT.h:74
virtual bool Notify(const char *exceptionOrigin, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
string rm
Definition: submit.py:76
tuple description
Definition: idDealer.py:66
RunManager * fRunManager
RunManagerMT * fRunManagerMT
tuple cout
Definition: gather_cfg.py:121