[ROOT] RE: Why does GetEntries stop split branches working with TChains?

From: koblitz@poly.in2p3.fr
Date: Fri Jul 18 2003 - 14:22:39 MEST


Dear Philippe,

thank you for your help, everything works now nicely. However, I would 
still insist this "feature" to be a bug. If TChain returns a TBranch, this 
should also work as a TBranch returned from a TTree, since TChain _is_ a 
TTree (at least it inherits from the tree). In this respect I am also not 
by-passing the TChain interface, I am using a valid interface which is 
offered by a tree and which works for a tree, and again since TChain 
inherits from a Tree, it _is_ a tree.
I think a lot of the problems I have encountered in the past days using 
chains seem to come from the fact that the design is - well - strange. I 
guess what it should have been is, that TChain _has_ a tree (as a data 
member) or even that a TTree inherits from the TChain, being the special 
case where there is only one file.

What makes the special feature of TChains as you said 
even more arcane is, that it works for branches which are not split but 
not for those which are split.

I would hope that a future documentation contains a lot more warnings 
concerning the intricacies of working with trees, chains, branches and 
split branches.

Cheers,
  Birger


On Thu, 17 Jul 2003, Philippe Canal wrote:

> Hi Birger,
> 
> Your difficulty comes from using:
> 
>      root [9] b_header->SetAddress(&header);
> 
> Since you by-passed the TChain interface and directly set the address in
> the branch object, this address is 'forgotten' each time the chain moves
> from one file to the other.
> 
> Remember that a TChain object is a 'facade' for a list of trees which
> manages for you all the work of opening and closing the file, loading
> and unloading the tree and making sure that the new tree are in a
> consistent state.  However, chain->GetBranch does not returns a
> TChainBranch (there is NO such things) but a TBranch that only knows
> that its belongs to the current TTree object.  After being told set its
> own address (b_header->SetAddress), the branch object has no way to
> inform the TChain objects or even the next tree object of this address.  
> In the general case, TBranch::SetAddress should not be called directly.
> 
> You should use:
> 
>      inputChain->SetBranchAddress("BRawHeader",&header);
> 
> Cheers,
> Philippe.
> 
> 
> -----Original Message-----
> From: koblitz@poly.in2p3.fr [mailto:koblitz@poly.in2p3.fr]
> Sent: Thursday, July 17, 2003 11:57 AM
> To: Philippe Canal
> Cc: Rene Brun; roottalk@pcroot.cern.ch
> Subject: Why does GetEntries stop split branches working with TChains?
> 
> 
> Hi Philippe,
> 
> Sorry to bother you again but I have another funny behaviour. I do the 
> following:
> 1. Open a chain
> 2. Attach _2_ files
> 3. Attach a split branch
> 4. Get event 3 -> works
> 5. Get event 4 -> works
> 6. chain->GetEntries()
> 7. Get event 3 -> Event is not read
> 
> The same works if only _one_ file is attached to the branch, or the 
> branch is _not_split_. 
> Certainly I expect GetEntries() to not disrupt reading of branches, event 
> if they are written in split mode. At least there are no warnings in the 
> documentation of TTree.
> 
> Cheers,
>   Birger
> 
> It follows the transcript of the session:
> 
> 
>   *******************************************
>   *                                         *
>   *        W E L C O M E  to  R O O T       *
>   *                                         *
>   *   Version   3.05/05        8 May 2003   *
>   *                                         *
>   *  You are welcome to visit our Web site  *
>   *          http://root.cern.ch            *
>   *                                         *
>   *******************************************
> 
> FreeType Engine v2.1.3 used to render TrueType fonts.
> Compiled for linux with thread support.
> 
> CINT/ROOT C/C++ Interpreter version 5.15.86, Apr 29 2003
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] 
> gSystem.Load("/afs/cern.ch/user/k/koblitz/public/h4/rawroot/Linux/libRawEvent.so");
> root [1] TChain *inputChain = new TChain("T13","H4 Analyis Input Chain");
> root [2] inputChain->Add("/coda/data/ecs63137");
> root [3] inputChain->Add("/coda/data/ecs63138");
> root [4] inputChain->SetBranchStatus("*",0);
> root [5] inputChain->SetBranchStatus("BRawHeader",1);
> root [6] inputChain->SetBranchStatus("fEvtNum",1);
> root [7] b_header=inputChain->GetBranch("BRawHeader");
> root [8] TRawHeader *header=0;
> root [9] b_header->SetAddress(&header);
> root [10] inputChain->GetEntry(3)                            <---- Event 3
> end TRawTdcInfo::Init()
> end TRawTdcInfo::Init()
> end TRawTdcInfo::Init()
> TRawTower constructor
> TRawTower constructor
> (Int_t)4
> root [11] header->Print()
> 
> fBurstNum     =            0    fEvtNum       =            3  <---- OK
> root [12] inputChain->GetEntry(4)                             <----Event 4
> (Int_t)4
> root [13] header->Print()          
> 
> fBurstNum     =            0    fEvtNum       =            4
> root [14] inputChain->GetEntries()                       <---- GetEntries()
> (const Double_t)2.00000000000000000e+03
> root [15] inputChain->GetEntry(3)                             <---- Event 3
> end TRawTdcInfo::Init()
> TRawTower constructor
> (Int_t)4
> root [16] header->Print()          
> 
> fBurstNum     =            0    fEvtNum       =            4 <----- OOOPS
> 
> 
> 

-- 
 Birger Koblitz                Tel: +33/1 69 33 31 73
 Ecole Polytechnique - LLR
 Route de Saclay
 F-91128 Palaiseau



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