Hi,
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.
Vi-Hoa
[code]{
// 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);
graph->Sort(&TGraph::CompareX,kTRUE,0,2);
graph->Sort(&TGraph::CompareX,kTRUE,3,5);
graph->Sort(&TGraph::CompareX,kTRUE,6,8);
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++)
graph1->Sort(&TGraph::CompareX,kTRUE,m*3,(m+1)*3-1);
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));
}
[/code]
[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/libc.so.6
#1 0x00000038e303bcb3 in do_system () from /lib64/libc.so.6
#2 0x00002aaaaad0afc2 in TUnixSystem::StackTrace ()
from /home/rootV5.30/lib/libCore.so
#3 0x00002aaaaad07d9a in TUnixSystem::DispatchSignals ()
from /home/rootV5.30/lib/libCore.so
#4
#5 0x0000000000000000 in ?? ()
#6 0x00002aaaad09e536 in TGraph::Sort ()
from /home/rootV5.30/lib/libHist.so
#7 0x00002aaaad1ae0bc in G__G__Hist_106_0_105 ()
from /home/rootV5.30/lib/libHist.so
#8 0x00002aaaab4c274d in Cint::G__ExceptionWrapper ()
from /home/rootV5.30/lib/libCint.so
#9 0x00002aaaab4d5ab9 in G__exec_asm ()
from /home/rootV5.30/lib/libCint.so
#10 0x00002aaaab5a919f in G__exec_loop ()
from /home/rootV5.30/lib/libCint.so
#11 0x00002aaaab5a2465 in G__exec_statement ()
from /home/rootV5.30/lib/libCint.so
#12 0x00002aaaab4fb9e5 in G__exec_tempfile_core ()
from /home/rootV5.30/lib/libCint.so
#13 0x00002aaaab4fbd0b in G__exec_tempfile ()
from /home/rootV5.30/lib/libCint.so
#14 0x00002aaaab5b41c2 in G__process_cmd ()
from /home/rootV5.30/lib/libCint.so
#15 0x00002aaaaacc649d in TCint::ProcessLine ()
from /home/rootV5.30/lib/libCore.so
#16 0x00002aaaaacc5f73 in TCint::ProcessLineSynch ()
from /home/rootV5.30/lib/libCore.so
#17 0x00002aaaaac22b03 in TApplication::ExecuteFile ()
from /home/rootV5.30/lib/libCore.so
#18 0x00002aaaaac1fe61 in TApplication::ProcessLine ()
from /home/rootV5.30/lib/libCore.so
#19 0x00002aaaac24ba62 in TRint::HandleTermInput ()
from /home/rootV5.30/lib/libRint.so
#20 0x00002aaaac24a337 in TTermInputHandler::Notify ()
from /home/rootV5.30/lib/libRint.so
#21 0x00002aaaac24cb6d in TTermInputHandler::ReadNotify ()
from /home/rootV5.30/lib/libRint.so
#22 0x00002aaaaad079d3 in TUnixSystem::CheckDescriptors ()
from /home/rootV5.30/lib/libCore.so
#23 0x00002aaaaad0844c in TUnixSystem::DispatchOneEvent ()
from /home/rootV5.30/lib/libCore.so
#24 0x00002aaaaac7ef56 in TSystem::InnerLoop ()
from /home/rootV5.30/lib/libCore.so
#25 0x00002aaaaac81f31 in TSystem::Run ()
from /home/rootV5.30/lib/libCore.so
#26 0x00002aaaaac1e6ff in TApplication::Run ()
from /home/rootV5.30/lib/libCore.so
#27 0x00002aaaac24c7ff in TRint::Run ()
from /home/rootV5.30/lib/libRint.so
#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
root.cern.ch/bugs. 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/libHist.so
[/ul]