Re: Performance Problem with TIterator

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Dec 17 1999 - 17:40:39 MET


Hi Christian,
If the number of hits is small, you spend a huge amount of time
in creating/deleting the iterator inside the loop. To speed up
the process, you have two solutions

 1- Create the iterator outside the loop and Reset it inside
    TIter next(fHits)
    for (i=0;i<nb_events;i++) {
       next.Reset();

 2- Use the following form:
    for (i=0;i<nb_events;i++) {
       Int_t nhits = fHits->GetEntriesfast();
       for (j=0;j<nhits;j++) {
          hit = (Hit*)fHits->At(j);


Let me know the results

Rene Brun



Christian Hilbes wrote:
> 
> Hi,
> 
> I am using a TIterator to loop over a TClonesArray I read from a tree
> (structure similar to ATLFast code). I do something like the following
> 
> hit is an Object of type Hit* and
> fHits is a TClonesArray of Hit's
> 
> for (i = 0; i < nb_events; i++) {
> 
>   tree->GetEvent(i);
> 
>   TIter next(fHits)
> 
>   while ((hit = (Hit*)next())) {
> 
>     // do stuff
> 
>   }
> 
>   // do a clear of the Arrays here
> 
> }
> 
> The problem is, that if the TClonesArray is empty (which happens quite
> often for one of my branches), a loop over the tree is really slow :350
> events per second. If I add the following however
> 
> for (i = 0; i < nb_events; i++) {
> 
>   tree->GetEvent(i);
> 
>   TIter next(fHits)
> 
>   if (fHits->GetEntriesFast()) {
>     while ((hit = (Hit*)next())) {
> 
>       // do stuff
>     }
>   }
> 
>   // do a clear of the arrays here
> 
> }
> 
> the loop is speeded up by quite a big factor : 2900 events per second.
> 
> In case of a brach without empty arrays, the performace is about 2500
> evts. per second.
> 
> The while loop is in fact not entered for empty arrays in the first case
> -> why does the call to next() take so much time if the TClonesArray is
> empty?
> 
> Cheers,
> 
> Christian Hilbes
> 
> IPP - ETH Zuerich



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:44 MET