Hi,
The problem is your case is that TChain::ResetBranchAddresses was not properly working (this is now fixed in the CVS repository).
To work around the issue, you can simply add
chain->GetStatus()->Clear();
just before doing the cloning.
Cheers,
Philippe.
-----Original Message-----
From: owner-roottalk_at_pcroot.cern.ch [mailto:owner-roottalk_at_pcroot.cern.ch]
On Behalf Of Vassili Maroussov
Sent: Wednesday, June 07, 2006 12:04 PM
To: roottalk_at_pcroot.cern.ch
Subject: [ROOT] CopyTree & SetBranchAddress
Dear ROOTers,
I'm wondering why CopyTree(Cuts) is affected by SetBranchAddress(...). Consider a fragment like
T b_val;
TBranch *b_ref;
tree->SetBranchAddress(bname, &b_val);
//Here is a code, that doesn't reset the branch address...
int main()
{
TFile inp_file("inpfile.root", "READ"); TTree *tree = (TTree*)inp_file.Get("tree");
func(tree, "branchname", ...);
TFile out_file("outfile.root", "RECREATE"); TString Cuts = "..."; //some cuts, maybe "", then all tree should be copied
TTree *newtree = tree->CopyTree(Cuts);
newtree->SetName("newtree");
newtree->Write();
One may discover the branch "branchname" in "newtree" will be filled with 0's. Is it a bug or a feature?
More unexpected things appear if to try a similar program structure (SetBranchAddress to a local variable in a function) with TChain. In that case even ResetBranchAddresses() doesn't help. Please consider the sample program (test_CopyTree.cxx) attached. It is expected to do the following:
What I observed in reality (test_out.txt) is the following:
What is wrong with the sample code? I used ROOT 5.06 and gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-54), SLC3. The code was compiled with:
g++ -o test_CopyTree test_CopyTree.cxx `root-config --cflags --libs`
With the best regards,
Vassili. Received on Thu Jun 08 2006 - 19:02:21 MEST
This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:58 MET