Message: Re: Clean abort of run Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: Clean abort of run 

Keywords: abort run
Forum: Run Management
Re: Question Clean abort of run (Mario Schubert)
Date: 26 Jul, 2002
From: Daniel Strul <Daniel Strul>

Hi Mario,

We had the same requirement for our project. The solution we found was
to set-up a signal handler class: when the user sends a stop signal,
this class aborts the run, then returns to the normal execution of the
simulation. I've included a typical example of code below, and some
comments at the end of this mail

namespace MySignalHandler
    G4int Install(void);

    void QuitSignalHandler(int sig);

G4int MySignalHandler::Install()
  // Install the signal handler for SIGQUIT only
  if (signal(SIGQUIT,QuitSignalHandler) == SIG_ERR) {
    G4cerr << G4endl << "Warning! Could not install handler for CTRL-\\
(SIGQUIT)!" << G4endl << G4endl;
    return -1;
  return 0;

void MySignalHandler::QuitSignalHandler(int sig)
  // Print that we received the signal to G4cerr
  G4cerr << G4endl;
  psignal(sig,"Received signal");

  // Process the signal
  G4ApplicationState state =
  switch (state)
    case GeomClosed:
    case EventProc:
      // If a beamOn/StartDAQ is running, launch abort sequence
      G4cerr << "--- Aborting run! ---" << G4endl << G4endl;
      // In other modes, ignore the signal
      G4cerr << "Signal received in state '" <<
stateManager->GetStateString(state) << "' "
             << " --> ignored!" << G4endl << G4endl;

Add at the begining of the main:

Here come a few comments about these codes:
- Firstly, we have chosen to catch the SIGQUIT signal (CTRL-\) rather
than the SIGINT one (CTRL-C). This way, the user has two ways of
stopping a simulation: CTRL-\ for a clean stop and CTRL-C for an
'emergency stop'. Still you could catch CTRL-C instaed: all you have to
do is replace SIGQUIT by SIGINT in the code above

- Secondly, this code is not perfect in the sense that it performs a
full abort of the simulation, i.e. it also aborts the current event, and
thus messes up the data output for this last event. What we would want
is something much less abrupt than that. That's in a way easy: all you
have to do is set the abortion flag G4RunManager::runAborted. The
problem is that this flag is protected, and thus can not be accessed
directly, so you need to use a customised run-manager. To do so, you
would need to do the following changes:

New run-manager class:
class MyRunManager : public G4RunManager
    GateRunManager() : G4RunManager() {}
    virtual ~GateRunManager() {}

     virtual void SetAbortFlag() 
     {  runAborted = true; }
     static MyRunManager* GetMyRunManager()
     {  return dynamic_cast<MyRunManager*>( G4RunManager::GetRunManager()
); }

Change in the signal handler:
The signal handler must no longer call the abort function but rather
should call our new function, and thus the code for the abortion
    case GeomClosed:
    case EventProc:
      // If a beamOn/StartDAQ is running, launch abort sequence
      G4cerr << "--- Aborting run! ---" << G4endl << G4endl;

Changes in the main:
There, you must install and launch the customised run-manager rather
than the standard one.

Note that the latter modificatons are strongly connected to the way
AbortRun() works in my release (4.0) of G4. Maybe in a future release
the user will have the possibility of setting the abortion flag
directly, in which case you will be able to reverting to the standard G4
run manager.

Let me know if you need any further information. And obviously, I'd be
happy to hear of any comment or suggestion about a potentially cleaner way (i.e. less
implementation-dependent) of doing this "clean-abort".

        'Hope this helps


Daniel Strul
GATE Project technical coordinator

PET Instrumentation Laboratory
Institute for High Energy Physics
University of Lausanne
CH-1015 Lausanne, Switzerland

Tel: +41 (0)21 692 37 34
Fax: +41 (0)21 692 37 05

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 Note: Re: Clean abort of run   (Daniel Strul - 01 Aug, 2002)
2 None: Re: Clean abort of run   (Mario Schubert - 01 Aug, 2002)
1 Question: Re: Clean abort of run   (Daniel Strul - 01 Aug, 2002)
(_ Agree: Re: Clean abort of run   (Makoto Asai - 07 Aug, 2002)
(_ None: Re: Clean abort of run   (Daniel Strul - 08 Aug, 2002)
 Add Message Add Message
to: "Re: Clean abort of run"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]