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

From: Philippe Canal (pcanal@fnal.gov)
Date: Thu Jul 17 2003 - 19:28:39 MEST


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



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