Re: [5.28.00a] GetBranch/SetAddress not working for TChains w/ multiple files ?

From: Philip Rodrigues <p.rodrigues1_at_physics.ox.ac.uk>
Date: Wed, 9 Mar 2011 09:24:28 -0500


Hi Sebastien,
If you want to continue with the way you currently have, you might find TChain::LoadTree and TTree::SetNotify useful: LoadTree(i) loads the branches for entry i in the chain, setting the current tree in the chain if necessary, and returns the "local" entry number in that tree. If the tree changes, it calls Notify() on the object specified by TTree::SetNotify - so you can SetNotify to be an instance of MyClass and have MyClass::Notify reload the branches with GetBranch.

So you would end up with something like:

MyClass m;
TChain ch("sometree");
ch.Add(...);
ch.SetNotify(&m);
for(i in ch.GetEntries()){
  ch.LoadTree(i); // will call m.Notify() if tree changes   // Do stuff here
}

Disclaimer: this seems to work for me, but my description of what happens is based on reading the source, plus trial and error, so I may be wrong.

Regards,
Phil

On Wednesday, March 09, 2011 08:50:39 am Rene Brun wrote:
> Sebastien,
>
> I am surprised by this remark. A TChain is a TTree but a TTree is not a
> TChain.
> If your case it worked for the first Tree in the TChain because this
> Tree was already loaded at the time of the call.
> I strongly suggest to use a TSelector based analysis instead of
> reinventing once more the wheel ::)
> This will take care of the changes of files and Trees in the TChain and
> in addition you will be ready to run on parallel architectures too.
>
> Rene
>
> On 09/03/2011 14:40, Sebastien Binet wrote:
> > On Wed, 9 Mar 2011 14:27:54 +0100, Rene Brun<Rene.Brun_at_cern.ch> wrote:
> >> use TChain::SetBranchAddress and TChain::SetBranchStatus
> >
> > so this code just happens to work for the special case of a TChain with
> > one file (I was careful to check the methods I was calling on the TTree
> > were virtual ;))...
> >
> >>> void MyClass::init_branches(TTree *t)
> >>> {
> >>>
> >>> TBranch *b = t->GetBranch("some_br_name");
> >>> if (!b) { panic(); }
> >>> b->SetAddress(&this->m_some_var);
> >>> b->SetStatus(1);
> >>>
> >>> }
> >
> > -s
Received on Wed Mar 09 2011 - 15:24:34 CET

This archive was generated by hypermail 2.2.0 : Wed Mar 09 2011 - 23:50:01 CET