diff --git a/exampleB1.cc b/exampleB1.cc index 099a778..e998256 100644 --- a/exampleB1.cc +++ b/exampleB1.cc @@ -39,6 +39,7 @@ #include "G4UIExecutive.hh" #include "Randomize.hh" +#include "UserHookForAbortState.hh" using namespace B1; @@ -86,6 +87,9 @@ int main(int argc,char** argv) // Get the pointer to the User Interface manager G4UImanager* UImanager = G4UImanager::GetUIpointer(); + // User's hook for state change + UserHookForAbortState* uhfas = new UserHookForAbortState(); + // Process macro or start UI session // if ( ! ui ) { diff --git a/include/UserHookForAbortState.hh b/include/UserHookForAbortState.hh new file mode 100644 index 0000000..816bfef --- /dev/null +++ b/include/UserHookForAbortState.hh @@ -0,0 +1,16 @@ +#ifndef UserHookForAbortState_H +#define UserHookForAbortState_H 1 + +#include "G4VStateDependent.hh" + +class UserHookForAbortState : public G4VStateDependent +{ + + public: + + UserHookForAbortState(); // constructor + ~UserHookForAbortState(); // destructor + virtual G4bool Notify(G4ApplicationState requiredState); +}; + +#endif diff --git a/run.mac b/run.mac new file mode 100644 index 0000000..0bc7b4f --- /dev/null +++ b/run.mac @@ -0,0 +1,22 @@ +# Macro file for example B1 +# +# Can be run in batch, without graphic +# or interactively: Idle> /control/execute run1.mac +# +# Change the default number of workers (in multi-threading mode) +/run/numberOfThreads 1 +# +# Initialize kernel +/run/initialize +# +/control/verbose 0 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +# +# gamma 6 MeV to the direction (0.,0.,1.) +# +/gun/particle gamma +/gun/energy 6 MeV +# +/run/beamOn 5 diff --git a/src/EventAction.cc b/src/EventAction.cc index a400550..25357ca 100644 --- a/src/EventAction.cc +++ b/src/EventAction.cc @@ -32,6 +32,7 @@ #include "G4Event.hh" #include "G4RunManager.hh" +#include "G4Run.hh" namespace B1 { @@ -52,6 +53,19 @@ EventAction::~EventAction() void EventAction::BeginOfEventAction(const G4Event*) { fEdep = 0.; + const G4Run* run = G4RunManager::GetRunManager()->GetCurrentRun(); + G4cout << "@@@ GetNumberOfEvent=" << run->GetNumberOfEvent() << "\n" <GetNumberOfEvent() == 3) + { + G4cout << "@@@ in if" << "\n" << G4endl; + G4ExceptionDescription ed; + ed << "force this exception! " << G4endl; + G4Exception("G4HadronicProcess::PostStepDoIt", "had006", FatalException, + ed); + //G4Exception("G4HadronicProcess::GetElementCrossSection", "had066", + // JustWarning, ed); + + }; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/src/UserHookForAbortState.cc b/src/UserHookForAbortState.cc new file mode 100644 index 0000000..a14af24 --- /dev/null +++ b/src/UserHookForAbortState.cc @@ -0,0 +1,18 @@ +#include "G4ios.hh" +#include "UserHookForAbortState.hh" + +UserHookForAbortState::UserHookForAbortState() {;} + +UserHookForAbortState::~UserHookForAbortState() {;} + +G4bool UserHookForAbortState::Notify(G4ApplicationState requiredState) +{ + G4cout << "$$$$$$$$$$$$$$$$$$ " << requiredState << G4endl; + //if(requiredState!=Abort) return true; + if(requiredState!=G4State_Abort) return true; + // Do book keeping here + G4cout << "!!!!!!!!!! " << "inside abort state handling" << "!!!!!!!!!!" << G4endl; + + + return true; +}