Re: TChain vs TTree

Rene Brun (Rene.Brun@cern.ch)
Mon, 20 Apr 1998 16:15:35 +0200


Laurent Aphecetche wrote:
>
> Hi,
>
> I would like to transform a program using TTree to a program using
> TChain. Basically,
> to read my TTree, I do :
>
> TBranch* small = T.GetBranch("small_branch");
> TBranch* big = T.GetBranch("the_whole_event") ;
>
> for (Int_t i=0;i<nevent;i++) {
> small->GetEvent(i);
> if (big->IsNoGood()) continue;
> T.GetEvent(i); //read complete accepted event in memory
> }
>
> I do not see cleary how this could be done with chains. Should I disable
> all branches but the small one, read the event, and then, if ok, enable
> the other branches, and read again the same event ?
> Or is another way ?

Hi Laurent,
Both TChain::GetEvent and TTree::GetEvent are functions with
two arguments. You can set the second argument to 1 to specify
that you want to read all the branches. In this case, you can use
the same code for Trees and Chains.
T.SetBranchStatus("*",0);
T.SetBranchStatus("small_branch",1);

in the loop
T.GetEvent(i); // will read only small branch
if (ok to read all)
T.GetEvent(i,1); // read all branches

In case of a chain, tou simply replace T by Chain.

Rene Brun