A problem with TRef

I have a class, Hit, with two members referencing to a
TClonesArray collection of Cluster:

class Hit : public TObject {
//! p-side cluster reference (Y).
TRef pCluster;
//! n-side cluster reference (X).
TRef nCluster;

(Clearly, when I store this class in a TTree I ask the creation of the
TBranchRef branch)

When I read the structure with an analysis program I see that the
dereference operation Hit.pCluster.GetObject() begins to be slow
when the number of events stored is big (let’s say 1000).

Now I’m using a faster operation that is pCluster.GetPID()->GetObjectWithID(pCluster.GetUniqueID())
but I’m not sure that this operation is safe.

Any suggestion?



my guess would be that you don’t call SetObjectCount. Please read the doc of TRef root.cern.ch/root/html/TRef. If you already do that: could you provide us with a working example so we can reproduce it?