[ROOT] Sorting any TObject

From: LEE, KERRY T. (JSC-SR) (UHCL) (kerry.t.lee1@jsc.nasa.gov)
Date: Wed Mar 10 2004 - 07:57:15 MET


Dear ROOT team,

I would like to be able to sort any TList of objects that inherit from
TObject using some common Int_t.  Say for example that I'd like to sort a
currently unsortable list of objects such as TGeoTrack, by their fId number.
If I could toggle the IsSortable flag, and then set the TObject::fUniqueID =
fId, then I could sort any List of TObjects that I choose using a default
Compare function in TObject, which sorts by fUniqueID.

More specifically, I am trying to sort a list of TGeoTrack objects.  I read
data for these tracks from a file and put the data into TGeoTrack objects,
and then place the TGeoTrack objects in a TList in the order I read them in.
This order is not always the order of Parent->daughter->granddaughter etc,
but from the sequential track id numbers and parent id numbers this
ancestral hierarchy can be determined. 

There is another way for me to do this, but it requires looking through the
list each time for the next largest track id number, and this could
potentially consume a lot of cpu time if the list contained a large number
of objects.  Sorting the list once by track id solves this problem.  I could
of course write my own sorting routine, but using the already optimized ROOT
framework is more desireable.

Would it be possible to implement this default sorting mechanism for any
list of TObjects?

Thanks
Kerry



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET