Plots NOT being displayed through evolving data sets

I’m a complete novice in ROOT and I apologize if the following query
happens to be a misplaced one.

I’m trying to read/calculate data points for three plots in one canvas.
(Actually, the data points are directly read from the inout file for one plot
and the data points for the other two are calculated therefrom.)

The data points in the input file are arranged in individual sets.

The plots do show up fine for the first set. Thereafter when I ask the
code to go back reading/calculating the data points for the next set,
the old plots, expectedly, vanish but the new plots do not display.
However, I have indicators to show that the data points
are being read and calculated for the subsequent sets as well
but the display shows only a blank canvas.

This continues through the subsequent sets of data points until
I opt out of reading another set and then the last read/calculated set
of plots show up.

The snippet of the code, in a schematic way, is included herewith.

readdata:

// READING/CALCULATING ONE SET OF DATA POINTS CORRESPONDING TO THREE PLOTS.


// DONE WITH READING/CALCULATING ONE SET OF DATA POINTS

//PLOTTING IN ROOT

TCanvas* draw_trace = new TCanvas("draw_trace","TRACE OF THE PULSE",200,10,600,400);
draw_trace->Divide(1,3);

TGraph* raw_trace = new TGraph(nlines,x,y);
TGraph* ff_trace = new TGraph(nlines1,xff,yff);
TGraph* cfd_trace = new TGraph(nlines2,xcfd,ycfd);

draw_trace->cd(2);
raw_trace -> SetMarkerStyle(7);
raw_trace -> SetMarkerSize(5.0);
raw_trace -> SetMarkerColor(4);
raw_trace -> Draw("AP");


draw_trace->cd(1);
ff_trace -> SetMarkerStyle(7);
ff_trace -> SetMarkerSize(5.0);
ff_trace -> SetMarkerColor(4);
ff_trace -> Draw("AP");

draw_trace->cd(3);
cfd_trace -> SetMarkerStyle(7);
cfd_trace -> SetMarkerSize(5.0);
cfd_trace -> SetMarkerColor(4);
cfd_trace -> Draw("AP");

gPad->Modified();
gPad->Update();

//ASKING THE USER IF ANOTHER SET OF DATA POINTS ARE TO BE READ/CALCULATED

printf("Do you want to read another trace ?\n"); scanf("%d", &optread);
if(optread == 1)
           {
            goto readdata;
           }

//IF THE ANSWER IS IN AFFIRMATIVE, WE GO BACK TO READ THE NEXT SET OF DATA POINTS

I’m using ROOT Version 6.14/04.

I shall gratefully appreciate any guidance from this community.

@couet can you give a hand with this? Thanks!

On which platform ?

try to update the full canvas:

draw_trace->Modified();
draw_trace->Update();

Thank you very much for your suggestion. However, I’m afraid, the problem persists even after implementing the change.

I’m working on Linux Fedora 25.

Can you provide a small reproducer ?

I realize that I might not be providing sufficient info to facilitate a solution and do apologize for the same. The data files on which the code works are inconveniently sized for sharing.

In the absence of such options, I’m uploading the screenshots that might represent the problem. The upper panel corresponds to the display and the command window after the first set of data points are read/calculated while the lower panel corresponds to the (blank) display and the command window that I see on trying to plot the second set.

May I also mention that I’m compiling this code with,

g++ -o trace6 trace6.cpp root-config --cflags --libs

and using it thereafter.

Please let me know if I should provide additional info in order to enable a solution. Deeply appreciating your inputs.

I’m extremely sorry but I could not make this fit in the context of my problem. This is owing to my own deficiencies in this domain and I remain apologetic for the same.

Could you please elaborate on the solution ?

And I shall also remain eager to see what @couet has to say.

Gratitude !

I think the link @Wile_E_Coyote sent you might allow you to draw this histograms in a loop.
Have you tried to use your code in ROOT interpreted ?
When I asked you for a 'reproducer" it was just a small macro we could run interactively reproducing the logic of your code. The one you sent initially cannot be used as it is (there is a lot missing).

@couet It seems to me that this is a classical problem of "blocking I/O” (the same as in the thread I mentioned in my previous post).

@rraut If you do not want to solve it properly, you can try a “brutal fix” (which may or may not work) … after the last “Update” call (and / or before you start to wait for user’s input), add:

gSystem->ProcessEvents(); gSystem->Sleep(100); gSystem->ProcessEvents(); gSystem->Sleep(100); gSystem->ProcessEvents();

@Wile_E_Coyote seems to me also.

trace6_forum.cpp (9.9 KB)

Thank you very much for your kind inputs and observations. I’m grateful !

I did use the ROOT interpreter but that did not help.

I was sort of hesitant to upload the code since the same, owing to my very modest programming caliber, might look too naive in this forum.

I’m uploading the entire code (including the “brutal fix”, as suggested by @Wile_E_Coyote) herewith.
There are a lot of additional variables inside the code that are not being used. This is because the code is edited from a different (and more elaborate) one.

The “brutal fix” suggested by @Wile_E_Coyote did work to a large extent. However, it did not allow me to operate (zoom etc.) on the graphics window until I opted out of doing another data set.

Thank you very much for everything.

The “proper fix” would be to create a GUI button or a new menu entry (e.g. added to your canvas) which the user could “click” on demand (in any case, you must not use any “blocking I/O”). Maybe @bellenot has some example how to do it.

One cannot add menu buttons or menu entries in an existing canvas, but maybe using TPad::WaitPrimitive() could help? (maybe @couet knows better if it can work…)
Otherwise you could also create your own GUI with embedded canvas(es)

Well, maybe there is another solution, something like the customContextMenu.C tutorial

Sorry, I was wrong (but I tried anyway). Here is how to add a custom menu entry on a Canvas’ menu bar:

void menu_slot(Int_t id)
{
   if (id == 1001)
      new TGMsgBox(gClient->GetRoot(), gClient->GetRoot(), "menu_slot",
                   "Received a signal from the menu entry with id 1001",
                   kMBIconExclamation, kMBOk);
}

TCanvas *test_addmenu()
{
   TCanvas *c = new TCanvas("c", "c");
   TRootCanvas *rcanvas = (TRootCanvas *)c->GetCanvasImp();
   TGMenuBar *menubar = rcanvas->GetMenuBar();
   TGPopupMenu *myMenu = new TGPopupMenu(gClient->GetRoot());
   myMenu->AddEntry("My &Custom Action", 1001);
   myMenu->Connect("Activated(Int_t)", 0, 0, "menu_slot(Int_t)");
   menubar->AddPopup("&My Custom Menu", myMenu, new TGLayoutHints());
   menubar->Layout();
   return c;
}