CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/SimG4Core/Application/src/ExceptionHandler.cc

Go to the documentation of this file.
00001 #include "SimG4Core/Application/interface/ExceptionHandler.h"
00002 #include "SimG4Core/Application/interface/RunManager.h"
00003 
00004 #include "SimG4Core/Notification/interface/SimG4Exception.h"
00005 
00006 #include "G4EventManager.hh"
00007 #include "G4StateManager.hh"
00008 #include "G4ios.hh"
00009 
00010 using std::cout;
00011 using std::endl;
00012 using std::string;
00013 
00014 ExceptionHandler::ExceptionHandler(RunManager* rm) 
00015    : fRunManager(rm)
00016 { 
00017 //    override = false; 
00018 //    verbose = 0; 
00019 }
00020 
00021 ExceptionHandler::~ExceptionHandler() {}
00022 
00023 bool ExceptionHandler::Notify(const char* exceptionOrigin,const char* exceptionCode,
00024                                  G4ExceptionSeverity severity,const char* description)
00025 {
00026     cout << endl;
00027     cout << "*** G4Exception : " << exceptionCode << " issued by " << exceptionOrigin << endl;
00028     cout << "    " << description << endl;
00029     bool abortionForCoreDump = false;
00030     G4ApplicationState aps = G4StateManager::GetStateManager()->GetCurrentState();
00031     switch(severity)
00032     {
00033     case FatalException:
00034         if ( aps==G4State_EventProc && exceptionOrigin==string("G4HadronicProcess") )
00035         {
00036         cout << "*** Fatal exception *** " << endl;
00037         throw SimG4Exception( "SimG4CoreApplication: Bug in G4HadronicProcess" ) ;
00038         }
00039         else
00040         {
00041         cout << "*** Fatal exception *** core dump ***" << endl;
00042         abortionForCoreDump = true;
00043         }
00044 /*
00045         cout << "*** Fatal exception *** core dump ***" << endl;
00046         abortionForCoreDump = true;
00047 */
00048         break;
00049     case FatalErrorInArgument:
00050         cout << "*** Fatal error in argument *** core dump ***" << endl;
00051         abortionForCoreDump = true;
00052         break;
00053     case RunMustBeAborted:
00054         if(aps==G4State_GeomClosed || aps==G4State_EventProc)
00055         {
00056             cout << "*** Run must be aborted " << endl;
00057             fRunManager->abortRun(false);
00058             //RunManager::instance()->abortRun(false) ;
00059         }
00060         abortionForCoreDump = false;
00061         break;
00062     case EventMustBeAborted:
00063         if(aps==G4State_EventProc)
00064         {
00065             cout << "*** Event must be aborted " << endl;
00066             // if (override && exceptionCode == string("StuckTrack"))
00067 /*
00068             if (exceptionCode == string("StuckTrack"))
00069             {
00070                 //if (verbose > 1) cout << "*** overriden by user " << endl;
00071                 G4Track * t = G4EventManager::GetEventManager()->GetTrackingManager()->GetTrack();
00072                 //if (verbose > 1) 
00073                     cout << " ERROR - G4Navigator::ComputeStep() " << endl 
00074                          << " Track " << t->GetTrackID() << " stuck " 
00075                          << " in volume " << t->GetVolume()->GetName()
00076                          << " at point " << t->GetPosition()/mm << " mm "<< endl
00077                          << " with direction: " << t->GetMomentumDirection()
00078                          << " and distance to out " 
00079                          << (t->GetVolume()->GetLogicalVolume()->GetSolid())
00080                         ->DistanceToOut(t->GetPosition())/mm << " mm " << endl;
00081                 //if (verbose > 1) 
00082                     cout << " Particle " << t->GetDynamicParticle()->GetDefinition()->GetParticleName()
00083                          << " from parent ID " << t->GetParentID() << endl
00084                          << " with " << t->GetKineticEnergy()/MeV << " MeV kinetic energy " 
00085                          << " created in " << t->GetLogicalVolumeAtVertex()->GetName() << endl;
00086                 cout << " *** StuckTrack: track status set to fStopButAlive " << endl;
00087                 t->SetTrackStatus(fStopButAlive);
00088             }
00089             else
00090 */
00091                 //fRunManager->abortEvent();
00092                 //RunManager::instance()->abortEvent() ;
00093                 throw SimG4Exception( "SimG4CoreApplication: G4Navigator:StuckTrack detected" ) ;
00094         }
00095         abortionForCoreDump = false;
00096         break;
00097     default:
00098         cout << "*** This is just a warning message " << endl;
00099         abortionForCoreDump = false;
00100         break;
00101     }
00102     cout << endl;
00103     return abortionForCoreDump;
00104 }
00105