ROOT not responding

I want to “Start” the data acquisition which could be interrupted at any time the user want.
Also, if the user doesn’t want to interrupt then the system will continue acquiring the data
and will restart after user defined time interval. To test this, I wrote a small code (attached).
When I run this code, the ROOT remains unresponsive for the user defined time, 1 min,
in the example. I want to stop the execution earlier than the pre-defined time by clicking
“Stop” button. But I cannot do it. Could you please help me in this matter?
I have spent 2 days to find out the solution!
Test_Interrupt.cxx (1.85 KB)

Hi,

The best way is to create a separate thread. Just take a look at your modified macro in attachment (see also the comments in the code).

Cheers, Bertrand.
Test_Interrupt.cxx (2.92 KB)

Hello Bertrand,

Thank you very much for the prompt response, really appreciated.
With the help of your example I have now implemented "Thread"
in my code and it is working as I expected it to work.

Is there any other method which can be used instead of TThread?
I saw some people have suggested using TTimer. If that is possible,
could you please tell me how to use other method?

Thanking you once again.

Regards,

Ajay

Hi Ajay,

You’re welcome! And yes, using timers could even be a better solution. Just take a look at the attached macro.

Cheers, Bertrand.
Test_Interrupt2.cxx (2.3 KB)

Hi Bertrand,

Thanks again.

With slight modification I can use the timer example code to run continuously.
But it has to stop by the user. In principle, I want to do somethings like:

Int_t i = 0;
do{
acquire
sleep 5m
stop
sleep 30s
i++;}while (i < 5);

How this can be done using TTimer? I have done this using TThread…

Ajay

Hi Ajay,

Very simple. Here it is.

Cheers, Bertrand.
Test_Interrupt2.cxx (2.53 KB)

Hello Bertrand,

It works great. But only once!
I don’t want to quit root when I click stop instead I just want to stop execution of the loop.
Then when I click Start again, the loop should begin again.

Regards,

Ajay

[quote=“ajaydeo”]It works great. But only once!
[/quote]What do you mean? It starts the process, wait for 5minutes, then kill the process, then wait 30 seconds, and start again. It is what you asked for. Now, if you want to be able to start multiple instances, up to you to modify the code to fit exactly what you want.

[quote=“ajaydeo”]I don’t want to quit root when I click stop instead I just want to stop execution of the loop.
[/quote]Then just remove the gApplication->Terminate(0); from the code…

Cheers, Bertrand.

Dear Bertrand,

Thank you much for your help. Now I am able to do what I wanted to do earlier using TTimer.
I am attaching the file with the final version, just for your reference. May be you can suggest
further modifications, if any, would be helpful.

Regards,

Ajay
Test_Interrupt3_TT.cxx (4.38 KB)

Hi Ajay,

Maybe just improve a bit the layout (and the behavior when resizing) of your GUI:

[code]void Test_Interrupt3_TT()
{
iloop = 0;
// main frame
TGMainFrame *fMainFrame = new TGMainFrame(gClient->GetRoot(),200,100);
fMainFrame->SetName(“fMainFrame”);
fMainFrame->SetWindowName(“Test Interrupt”);

// horizontal frame
TGHorizontalFrame *fHFrame = new TGHorizontalFrame(fMainFrame);
fHFrame->SetName(“fHFrame”);

fStart = new TGTextButton(fHFrame,“Start”);
fStart->SetTextJustify(36);
fStart->SetMargins(0,0,0,0);
fStart->SetWrapLength(-1);
gClient->GetColorByName("#00ff00",ucolor);
fStart->ChangeBackground(ucolor);
fStart->Connect(“Clicked()”,0,0,“DoJob()”);
start = kFALSE;
fHFrame->AddFrame(fStart, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2));

TGTextButton *fStop = new TGTextButton(fHFrame,“Exit”);
fStop->SetTextJustify(36);
fStop->SetMargins(0,0,0,0);
fStop->SetWrapLength(-1);
fStop->Connect(“Clicked()”,0,0,“DoExit()”);
fHFrame->AddFrame(fStop, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2));

fMainFrame->AddFrame(fHFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2));

fMainFrame->MapSubwindows();
fMainFrame->Resize(fMainFrame->GetDefaultSize());
fMainFrame->MapWindow();
fMainFrame->Resize(225,103);
}[/code]
Cheers, Bertrand.