TGraph::Sort() not happy when used in a loop


Root Version 5.26 and 5.30, compiled on RedHat 4.1.1-30

The program below uses the method TGraph::Sort(&TGraph::CompareX,kTRUE,low,high) to sort 9 numbers in groups of 3.

The sort method works fine, as long as it is NOT called within a for-loop or within a while-loop, as demonstrated in the first portion of the included codes.

When the method is called within a for-loop or in a while loop, segmentation occurs. Stack Trace is enclosed after the codes.

It is not clear to me if this is a limiation of CINT or is a bug, or a C++ reference can not be used in a loop.

I would like to be able to use the TGraph::Sort method either in a for-loop or a while loop for my task, since I have long list of numbers to sort in sort in groups.

Thanks you for any suggestions to make use of the TGraph::sort method.



// This program sorts the following 9 numbers, in groups of 3.

//output result: numbers in increasing order

Float_t x[9]={3.0, 2.0, 1.0, 6.0, 5.0, 4.0, 9.0, 8.0, 7.0};
Float_t y[9]={30.0,20.0,10.0,60.0,50.0,40.0,90.0,80.0,70.0};

// Tgraph::Sort() works ok in the following individual calls.

TGraph *graph=new TGraph(9,x,y);

Double_t *px=graph->GetX();
Double_t *py=graph->GetY();

for (Int_t i=0; i<9;i++) printf("x=%2.1f x=%2.1f \n ",(px+i),(py+i));

//Howwver, if TGraph::Sort() is called in an if-loop or in a while-loop (as shown below), segmentation occurs.

TGraph *graph1=new TGraph(9,x,y);

for(Int_t m=0;m<3;m++)

Double_t *px=graph1->GetX();
Double_t *py=graph1->GetY();

for (Int_t i=0; i<9;i++) printf("x=%2.1f x=%2.1f \n ",(px+i),(py+i));


[ul]root [0] .x TestGraphSort.c
x=1.0 x=10.0
x=2.0 x=20.0
x=3.0 x=30.0
x=4.0 x=40.0
x=5.0 x=50.0
x=6.0 x=60.0
x=7.0 x=70.0
x=8.0 x=80.0
x=9.0 x=90.0

*** Break *** segmentation violation

There was a crash.
This is the entire stack trace of all threads:

#0 0x00000038e30941b5 in waitpid () from /lib64/
#1 0x00000038e303bcb3 in do_system () from /lib64/
#2 0x00002aaaaad0afc2 in TUnixSystem::StackTrace ()
from /home/rootV5.30/lib/
#3 0x00002aaaaad07d9a in TUnixSystem::DispatchSignals ()
from /home/rootV5.30/lib/
#5 0x0000000000000000 in ?? ()
#6 0x00002aaaad09e536 in TGraph::Sort ()
from /home/rootV5.30/lib/
#7 0x00002aaaad1ae0bc in G__G__Hist_106_0_105 ()
from /home/rootV5.30/lib/
#8 0x00002aaaab4c274d in Cint::G__ExceptionWrapper ()
from /home/rootV5.30/lib/
#9 0x00002aaaab4d5ab9 in G__exec_asm ()
from /home/rootV5.30/lib/
#10 0x00002aaaab5a919f in G__exec_loop ()
from /home/rootV5.30/lib/
#11 0x00002aaaab5a2465 in G__exec_statement ()
from /home/rootV5.30/lib/
#12 0x00002aaaab4fb9e5 in G__exec_tempfile_core ()
from /home/rootV5.30/lib/
#13 0x00002aaaab4fbd0b in G__exec_tempfile ()
from /home/rootV5.30/lib/
#14 0x00002aaaab5b41c2 in G__process_cmd ()
from /home/rootV5.30/lib/
#15 0x00002aaaaacc649d in TCint::ProcessLine ()
from /home/rootV5.30/lib/
#16 0x00002aaaaacc5f73 in TCint::ProcessLineSynch ()
from /home/rootV5.30/lib/
#17 0x00002aaaaac22b03 in TApplication::ExecuteFile ()
from /home/rootV5.30/lib/
#18 0x00002aaaaac1fe61 in TApplication::ProcessLine ()
from /home/rootV5.30/lib/
#19 0x00002aaaac24ba62 in TRint::HandleTermInput ()
from /home/rootV5.30/lib/
#20 0x00002aaaac24a337 in TTermInputHandler::Notify ()
from /home/rootV5.30/lib/
#21 0x00002aaaac24cb6d in TTermInputHandler::ReadNotify ()
from /home/rootV5.30/lib/
#22 0x00002aaaaad079d3 in TUnixSystem::CheckDescriptors ()
from /home/rootV5.30/lib/
#23 0x00002aaaaad0844c in TUnixSystem::DispatchOneEvent ()
from /home/rootV5.30/lib/
#24 0x00002aaaaac7ef56 in TSystem::InnerLoop ()
from /home/rootV5.30/lib/
#25 0x00002aaaaac81f31 in TSystem::Run ()
from /home/rootV5.30/lib/
#26 0x00002aaaaac1e6ff in TApplication::Run ()
from /home/rootV5.30/lib/
#27 0x00002aaaac24c7ff in TRint::Run ()
from /home/rootV5.30/lib/
#28 0x0000000000400fed in main ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x0000000000000000 in ?? ()
#6 0x00002aaaad09e536 in TGraph::Sort ()
from /home/rootV5.30/lib/


I investigated the issue a bit more. If the program is run in compiled mode (.x TestGraphSort.c+), it seems to run ok, but the reliability might be questionable, since the x-terminal did hang once (but this crash has not been repeated). The file TestGraphSort.c is included as an attachment.

TestGraphSort.c (1.05 KB)


Do you see the same problem when compiling your script with ACLiC? (i.e. it is likely to be a CINT problem).


Hi Philippe,

When compiled using ACLiC, the TGraph::Sort() method works fine. I have been using the compiled library without any issue. The hang-up reported earlier is a non-issue.

Hope that the TGraph::Sort() would work in CINT in future release.