The current way is the only portable way (since container independent). However, creating a TIter (on the stack) causes the allocation/deallocation of a container specific iterator on the stack (via new/delete). If the innerloop is called millions of times you can better try container specific alternatives. For example: leafList = branch->GetListOfLeaves(); int entries = leafList->GetEntriesFast(); for (int i = 0; i < entries; i++) { leaf = (TLeaf*) leafList->UncheckedAt(i); // stuff } Cheers, Fons. Sean Kelly wrote: > > Hi Rooters > > My question is with regards to the correct way to implement nested > iterators. > > In the code fragment below, it seems that inner loop iterator is > created many times, when all I really want to do is to reset it to > the new value of leafList. > > Thanks for any advice. > > Sean Kelly > > TObjArray *branchList = ntuple->TTree::GetListOfBranches(); > TObjArray *leafList; > > TIter nextBranch(branchList); > while ( branch = (TBranch*) nextBranch() ) { > leafList = branch->GetListOfLeaves(); > TIter nextLeaf(leafList); > while ( leaf = (TLeaf*) nextLeaf() ) { > > // stuff > > } > } -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7677910
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:30 MET