Re: [ROOT] TTree::MakeClass with added iterators.

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Jul 12 2003 - 09:16:09 MEST


Hi Clark,

Many type of iterators (eg STL-like) could be introduced to
navigate in Trees/chains. However, it would be difficult
to have the generality and simplicity of the simple do loop.
For example, your iterator is limited to a pure sequential scan
of the Tree. It does allow for direct access to any entry.
Your iterator has also another problem. It will not work if the Tree
is a TChain. You will have to provide the equivalent definition in
TChain.
We want to be cautious with iterators on Trees in view of PROOF.
When running with multiple processors in parallel like in PROOF,
the user does have the control on the event loop. We recommend
using the TSelector mechanism instead.

Rene Brun

On 12 
Jul 
2003, 
Clark McGrew wrote:

> Hello,
> 
> (I've sent this message a couple times now, and so far it hasn't shown
> up in the roottalk archives.  I assume it's getting cut by some spam
> filter, so I've removed the attached code. I apologize if it you are
> getting several copies) 
> 
> I often find myself with a TTree that I would like to use MakeClass (or
> similar) to start an analysis, but there is a problem when the TTree
> definition changes and I need to regenerate the "loop" file.  Any new
> MakeClass will stomp on my Loop code, unless I've been careful and
> copied/renamed my file.  However, it occurs to me that the
> problem can be solved very simply with an iterator.
> 
> root [0] TTree *t = GetATree();
> root [1] t->MakeClass("TTreeClass");
> root [2] .L TTreeClass.C
> root [3] TTreeClass dst;
> root [4] TTreeClass::iterator it;
> root [5] for(it=dst.Begin();it!=dst.End();++it) cout << it->nev << endl;
> 
> which is rather simpler and more intuitive (to me) than the only other
> solution I've run across (compare lines [4] and [5] below). 
> 
> root [0] TTree *t = GetATree();
> root [1] t->MakeClass("TTreeClass");
> root [2] .L TTreeClass.C
> root [3] TTreeClass dst;
> root [4] int i;
> root [5] for(i=0;;++i) {
>    if (dst.LoadTree(i)<0) break;
>    dst.GetEntry(i);
>    cout << dst.nev << endl;
> }
> 
> I've put modified code at:
> 
> <http:://ale.physics.sunysb.edu/~mcgrew/TTreePlayer.cxx.gz>
> 
> I made the patch against Version 1.126 from CVS.  I've been using the
> code generated by this patch for a while, and it seems to be working
> pretty well.  
> 
> Sincerely,
> Clark
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET