I want to write a code that plots several histograms but before ending asks the user if they’d like to change the histogram parameters and re-plot. Basically,
do{
…
cin >> choice;
} while(choice == ‘y’);
However, the plot axes cannot be zoomed while in the loop, which is necessary to determine how the parameters should be changed. I’ve tried gSystem->ProcessEvents() at various locations in the loop to no avail.
As far as I understand it … the original problem is that while the macro is executing one of “cin >> choice;”, “cin >> mean;”, “cin >> sigma;”, one cannot interactively zoom the canvas (because processing of events is blocked by the “operator>>” when it is waiting for the user’s input).
So, one needs a routine which in some kind of a loop “waits until user presses enter” in a non-blocking way and inside of this loop one would simply need to call “gSystem->ProcessEvents();” in regular intervals. Once the “input is ready to be extracted”, one calls an appropriate “cin >>”.
I did have something like this a long time ago but I cannot find it now, sorry.
Instead of a simple loop waiting for available input, you could probably create and run a thread which would call “gSystem->ProcessEvents();” in regular intervals.
[quote=“Pepe Le Pew”]So, one needs a routine which in some kind of a loop “waits until user presses enter” in a non-blocking way and inside of this loop one would simply need to call “gSystem->ProcessEvents();” in regular intervals. Once the “input is ready to be extracted”, one calls an appropriate “cin >>”.
I did have something like this a long time ago but I cannot find it now, sorry.
Instead of a simple loop waiting for available input, you could probably create and run a thread which would call “gSystem->ProcessEvents();” in regular intervals.[/quote]
Why do you need to do simple things in a such complex unreliable way? In your macro define a function, which accepts as parameters values you now set using std::cin. Call this function passing different arguments (values). In any case it’s not good idea to mix std::cin and ROOT’s gSystem->ProcessEvent (which is also able to read from standart input and make a blocking call).