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