Performance Problem with Random Access of TTree entries

Hi all,
I have a TTree reading pereformance problem:

I have an application where I need to sort the entries of a TTree and then read the TTree in sorted order.
My TTree has only one Branch where the object being written is a class with some doubles and int’s.
My method is to fill the TTree with all my entries and then use BuildIndex to make a sorted index list, sorting by 2 of the values in each entry.
I then loop through the list getting the entry index of the TTree entries in sorted order.
I have 2 proiblem with this:
1: My number of entries is very large (>5,000,000), the sixz of each entry is ~18*4=72 bytes, which requires that the TTree be owned by a TFile in order for me to load it up with the 5,000,000 + entries.

Thats not much of a problem, my real problem isn’t even the time it takes to do the sort, the big problem is
2:The time it takes to random access all the entriess in the TTree with GetEntry(Index) where Index is found from the Index list.

Does anyone have a quicker way to get the sorted entries?

I give some snippits of pertinent code below.

[code]class KSRootPeData : public TObject
{
public:
KSRootPeData();
virtual ~KSRootPeData();
void PrintPe();
void CopyInPe(KSPeData* pfPe);
void CopyOutPe(KSPeData* pfPe);

int fNx; // Grid coords (x,y)
int fNy;
double fTime; // Time of hit
double fDlRelative; // dl of photon relative to mount
double fDmRelative; // dm of photon(dn can be recreated)
int fSegmentID; // Segment identifier.
double fX; // X position of hit in grid rectangle.
double fY; // Y position of hit in grid rectangle.
int fTrackType; // Type of emitting particle.
int fLambda; // Wavelength of emmited photon(nm)
double fEmissionAltitude;// emmison altitude
ClassDef(KSRootPeData,1);
}
.
.
KSRootPeData* pfRootPe = new KSRootPeData();
TFile* pfTempTreeFile = (TFile*) new TFile(“SortTempTreeFile.root”,
“RECREATE”,“Temoprary Sort ROOT file”);
pfTempTreeFile->cd();
TTree* pfPeTree=new TTree(“PeTree”,“Pe Tree”);
pfPeTree->Branch(“Pe”,“KSRootPeData”,&pfRootPe,16000,0);
.
.
for(inti=0;i<fNumEntries;i++)
{
.
get an entry into pfRootPe
pfTempTreeFile->cd();
pfPeTree->Fill();
}
// Note that we have to make the sort values of nx and ny positive
//definate. Find offsets that will do that
int nxoffset=1-nxmin;
int nyoffset=1-nymin;
//Build the index sorting strings.
char nxStr[80];
sprintf(nxStr,“Pe->fNx + %i”,nxoffset);
char nyStr[80];
sprintf(nyStr,“Pe->fNy + %i”,nyoffset);

int fNumIndexes=pfPeTree->BuildIndex(nxStr,nyStr);
// Now get a pointer to the index array list
TTreeIndex* pfPeTreeIndex=(TTreeIndex*)pfPeTree->GetTreeIndex();
Long64_t* fIndexList=pfPeTreeIndex->GetIndex();

// Save the TTree to a file in sorted order
Long64_t fPeIndex=0;
for(int i=0;i<fNumIndexes;i++)
{
fPeIndex=fIndexList[i];
pfPeTree->GetEntry(fPeIndex);
.
.
Save sorted entry to a binary file
}
[/code]
Its this last loop that takes a very long time.

Thanks
Glenn

If you plan to have random access to entries in your Tree, you should make
your brnches with small buffer sizes. In your case, I suggest using 1000
instead of 16000.
To come with a more precise answer, I will need a concrete piece of code.

Rene