Re: [ROOT] TTreeIter class proposal

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Thu Nov 22 2001 - 18:56:06 MET


Hi Philippe,
thank you for replay.
Philippe Canal wrote:
> and TTree::Draw can handle the following cases (which TIter does not
> yet address):
> 1. Can handle of most types of arrays data members (including TClonesArray,

In split mode 99 TClonesArray is converted to set of normal arrays
and TTreeIter can handle it

>         and multi-dimension arrays) 
multi-dimension arrays handles as one dimension array. User can use it as it is
or to do some cast to the real form of array. C++ does not allow to do methods for
all possible variants of arrays.

>         [notation fTracks.fPx[0], fTracks.fValues[][2], etc.. ].
It works

  const float *&fPx = iter("fTracks.fPx")
  ...
if (fPx[11] > 2001) {}

> 2. Can call Member functions of the object (if library is available);
>         including support for casting to a selected type.
>         [notation (TTube*)shape.GetTubeValue() ].

It is possible to do, but I do not know good enough internal TTree structure

    TObject *&obj = iter("MyObject");
    ...

    ((MyObject*)obj)->Method()
this is not implemented yet

> In other word, TIter currently only support using data members/leaves that
> are of a simple data type.

More precise, TTreeIter currently supports split mode 99, when everything is splited
to variables or arrays.

When I will understand or somebody will  help me,internal structure of TTree
then I will do it. 

Victor


> 
> Hi Victor,
> 
> Nice work.  This sounds like a very interesting tool.
> 
> In the state of current functionality please note that both MakeClass
> and TTree::Draw can handle the following cases (which TIter does not
> yet address):
> 
> 1. Can handle of most types of arrays data members (including TClonesArray,
>         and multi-dimension arrays) and histograms them partial or completely
>         [notation fTracks.fPx[0], fTracks.fValues[][2], etc.. ].
> 2. Can call Member functions of the object (if library is available);
>         including support for casting to a selected type.
>         [notation (TTube*)shape.GetTubeValue() ].
> 
> In other word, TIter currently only support using data members/leaves that
> are of a simple data type.
> 
> Cheers,
> Philippe.
> 
> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Victor Perevoztchikov
> Sent: Tuesday, November 20, 2001 11:33 AM
> To: root
> Subject: [ROOT] TTreeIter class proposal
> 
>   Dear rooters,
> 
> the new class TTreeIter is developed, tested and proposed for the wide usage.
> This is a kind of iterator for TTree or TChain classes.
> 
> Functionally it is combination of TTree::Draw() and TTree::MakeClass().
> TTreeIter is almost as flexible as TTree::Draw() and allows the same
> complexity of request as TTree::MakeClass()
> 
> The user interface is very simple and user friendly. It is based on rather
> complicated C++ features but all this complexity is hidden from the user.
> 
> SPEED is same as optimised MakeClass (only needed branches are read)
> In compiled case (ACLIc) it is faster then TTree::Draw
> For several histograms (>3) it is faster then TTree::Draw even in CINT case.
> 
> TTreeIter is not supposed to replace TTree::Draw() or TTree::MakeClass().
> But there is rather wide range of applications where it is more convenient
> then these two.
> 
> A simple example.
> ================
> TTreeIter iter;
> iter.AddFile("path1/event*.root");
> iter.AddFile("path2/event*.root");
> 
> // init of user variables
> 
> const int &ntrk = iter("fTracks");
> 
> const Float_t *&pz = iter("fTracks.fPz");
> 
> // Now the user variables ntrk and pz are initialised and according branches
> // automatically activated. These variables are referenced to internal
> // hidden buffers, which will be automatically updated during iteration.
> 
> TH1F *hz = new TH1F("Z","Z distribution",50,-5.,+5.);
> 
> //         Now iterations
> while (iter.Next())
> {
>    for (int itr=0;itr<ntrk;itr++)
>    {
>      hz->Fill( pz[itr]);
>    }
> 
> }
>     iter.Reset(); //ready for next loop
> -------------------------------------------------------------------------
> 
> For those who is interested, all codes and Makefile are:
> Those users who have AFS can get it
> from /afs/rhic/star/packages/.DEV/StRoot/StarRoot/*
> or
> http://rhic.bnl.gov/~perev/StarRoot/
> 
> FILEs:
> TTreeIter.txt - this message
> TTreeIter.h TTreeIter.cxx  TTreeIterLinkDef.h
> MakeTTreeIter.mk  - make file for Linux (easily modification for others)
>                   - gmake -f MakeTTreeIter.mk
> 
> th.C  - example to measure speed TTreeIter and Draw
> mk.C  - example to measure speed MakeClass
> 
> All comments, critics and proposals are welcome.
> 
> Victor
> 
> ===================================================================
> 
>    MORE DETAILED
> 
> ===================================================================
> 
>    TTreeIter does the same job as TTree::Draw() or MakeClassb but it is different.
>    ==============================================================================
> 
> Comparison with TTree::Draw():
> -----------------------------
> 1. TTree::Draw() uses special language. TTreeIter uses standard C++ or CINT.
> 
> 2. Selection in TTree::Draw() must be in one line. It is very convenient
>    for simple case. TTreeIter does not have such limitation. Selection and
>    weight calculation could be as complex as user needs.
> 
> 3. To fill several histograms, TTree::Draw() must read the file or the chain
>    of files several times. TTreeIter does it in one pass.
> 
> Comparison with MakeClass:
> -------------------------
> 
> 1. TTreeIter internally uses the same technique as MakeClass. Complexity
>    of selection is the same
> 
> 2. For each tree MakeClass generates C++ code which user should use.
>    TTreeIter is the same for all trees. No code is generated
>    In this sense TTreeIter is more flexible.
> 
> 3. If format of tree is changed, MakeClass should be regenerated.
>    TTreeIter is the same. Only additional needed variable could be declared.
> 
> 4. Usually not all variables of tree are used. To keep MakeClass fast,
>    user must activate/deactivate according branches by hands.
>    In TTreeIter, when user defined and initialised variable
>    (const Float_t &temp = iter("fTemperature");) according branch
>    activated automatically and only activated branches are read.
> 
> Speed tests:
> ------------
> 
> 1 histogram 10000 events CINT interpreter case:
> ----------------------------------------------
> 
> TTree::Draw    :  23.49 seconds
> TTreeIter      :  41.11 seconds
> MakeClassNonOpt: 162.39 seconds
> MakeClassOpt   :  41.99 seconds
> 
> So, TTreeIter as fast as optimised MakeClass and both are slower
> than TTree::Draw
> 
> 1 histogram 10000 events ACLiC case:
> ----------------------------------------------
> 
> TTree::Draw     :  24.09 seconds
> TTreeIter       :   9.32 seconds
> MakeClassNonOpt : 132.18 seconds
> MakeClassOpt    :   9.40 seconds
> 
> Again, TTreeIter as fast as optimised MakeClass and both are much
> faster than TTree::Draw. The last is evident, Draw uses interpretor.
> 
> 3 histograms 10000 events CINT interpreter case:
> ----------------------------------------------
> TTree::Draw     :  35.40 seconds
> TTreeIter       :  46.57 seconds
> MakeClassNonOpt : 164.27 seconds
> MakeClassOpt    :  47.79 seconds
> 
> Here, TTreeIter as fast as optimised MakeClass and both are close
> to TTree::Draw. It is because Draw uses separate pass for each histogram.
> For the big amount of histograms, TTree::Draw will be slower than
> TTreeIter and MakeClassOpt
> 
> 3 histograms 10000 events ACLiC case:
> ----------------------------------------------
> TTree::Draw     :  35.77 seconds
> TTreeIter       :  16.44 seconds
> MakeClassNonOpt : 129.08 seconds
> MakeClassOpt    :  15.92 seconds
> 
> Again, TTreeIter as fast as optimised MakeClass and both are much
> faster than TTree::Draw.
> 
> Any feedback will be very welcome.
> 
>   Victor
> 
> 
> --
> Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch
> Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
> tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690--

-- 
Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch       
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET