[ROOT] Handeling Interrupts?

From: Maurik Holtrop (maurik@improv.unh.edu)
Date: Fri Apr 27 2001 - 00:04:04 MEST


Hello ROOTers.

I tried to make a very simple class that catches a user interrupt. The code
works in a standalone code, and *almost* works within CINT. The problem with
CINT is that it seems ROOT grabs the interrupts first before handing it off
to my interrupt class. I would like that the other way around.
Is there any body who know how to do that?
There seems to be remarkably little information on how to deal with this,
perhaps I missed some documentation?

Thanks,

    Maurik

++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
Output of the code as standalone:

..............................You pressed crtl-C for the 1 time !
.............................................................................................................You
pressed crtl-C for the 2 time !
................................................................................................................................You
pressed crtl-C for the 3 time !
.........................................................................................................You
pressed crtl-C for the 4 time !
............................................You pressed crtl-C for the 5
time !
.........................................................................................................You
pressed crtl-C for the 6 time !

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
But from CINT:

root [0] .L libTest.so
root [1] TRun run;
root [2] run.Run()
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

 *** Break *** keyboard interrupt FILE:/tmp/fileiqVXDf_cint LINE:1
You pressed crtl-C for the 1 time !
..............................................................................................................................................................................................................................................................................................................................

 *** Break *** keyboard interrupt
Root >
 *** Break *** keyboard interrupt
Root > q
Error: No symbol q in current scope  FILE:/tmp/fileJVeyyl_cint LINE:1
*** Interpreter error recovered ***
root [4] .q

 *** Break *** segmentation violation
Root >
 *** Break *** segmentation violation
Root >
 *** Break *** segmentation violation
Root >
 *** Break *** segmentation violation

==============================================================
Code:

improv|testcode>cat TInterrupt.h
#include <iostream>
#include "TSystem.h"
#include "TSysEvtHandler.h"

class TInterrupt: public TSignalHandler {

 public:
  Int_t NumSig;

 public:
  TInterrupt():
    TSignalHandler(kSigInterrupt, kFALSE){NumSig=0;};
  ~TInterrupt(){};
  Bool_t Notify();  //   Override.

  ClassDef(TInterrupt,1) // TInterrupt
};

improv|testcode>cat TInterrupt.h
#include <iostream>
#include "TSystem.h"
#include "TSysEvtHandler.h"

class TInterrupt: public TSignalHandler {

 public:
  Int_t NumSig;

 public:
  TInterrupt():
    TSignalHandler(kSigInterrupt, kFALSE){NumSig=0;};
  ~TInterrupt(){};
  Bool_t Notify();  //   Override.

  ClassDef(TInterrupt,1) // TInterrupt
};

improv|testcode>cat TInterrupt.cc
#include "TInterrupt.h"

ClassImp(TInterrupt)

Bool_t  TInterrupt::Notify(){
  cerr << "You pressed crtl-C for the " << ++NumSig << " time !\n";
  if(NumSig > 5){
    gSystem->Exit(2);
  }

  return(1);
}

improv|testcode>cat TRun.h
#include <iostream>
#include "TSystem.h"
#include "TROOT.h"
#include "TInterrupt.h"

class TRun: public TObject {

 public:
  TRun();
  ~TRun(){};
  void Run();

  ClassDef(TRun,1) // TRun
};

improv|testcode>cat TRun.cc
#include "TRun.h"

ClassImp(TRun)

TRun::TRun(){
  TInterrupt *IntHandle=new TInterrupt();
  IntHandle->Add();
  //  gSystem->AddSignalHandler(IntHandle);
}

void TRun::Run(){

  Double_t z;

  for(Int_t i=0;;i++){
    if(i>100000){
      cerr <<".";
      i=0;
    }
    Double_t x=i/934;
    Double_t y=x*x*x;
    z=z+y-x;

  }

}

-------------------------------------------------------
Compile & run:
Compiling File TInterrupt.cc
g++ -O2 -Wall -fPIC -D_REENTRANT -I/usr/local/root/include -c TInterrupt.cc
-D_REENTRANT -I/usr/local/root/include  -I.
Compiling File TRun.cc
g++ -O2 -Wall -fPIC -D_REENTRANT -I/usr/local/root/include -c TRun.cc
-D_REENTRANT -I/usr/local/root/include  -I.
/usr/local/root/bin/rootcint -f TInterruptDict.cc -c  TInterrupt.h
TInterruptLinkDef.h
Compiling File TInterruptDict.cc
g++ -O2 -Wall -fPIC -D_REENTRANT -I/usr/local/root/include -c
TInterruptDict.cc -D_REENTRANT -I/usr/local/root/include  -I.
/usr/local/root/bin/rootcint -f TRunDict.cc -c  TRun.h TRunLinkDef.h
Compiling File TRunDict.cc
g++ -O2 -Wall -fPIC -D_REENTRANT -I/usr/local/root/include -c TRunDict.cc
-D_REENTRANT -I/usr/local/root/include  -I.
g++ -shared   TInterrupt.o TRun.o TInterruptDict.o TRunDict.o  -o
./libTest.so

root
.L libTest.so
root [0] .L libTest.so
root [1] TRun run;
root [2] run.Run()
.................



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:43 MET