RE: [ROOT] Copying Trees and scoping issues?

From: Philippe Canal (pcanal@fnal.gov)
Date: Mon Sep 15 2003 - 22:20:50 MEST


Hi Alex,

This behavior comes from the fact that you set the address of the new tree
to
the addresses of variable created on the stack and hence being deleted at
the end of the function.

In your case just add:
	newtree->ResetBranchAddresses();
just before returning.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Alex Olivas
Sent: Monday, September 15, 2003 12:44 PM
To: roottalk
Subject: [ROOT] Copying Trees and scoping issues?


i'm trying to copy entries from one tree to another.
i eventually want to make cuts, but for testing i just copy
all of the entries.  my code looks like...

TTree* uniqueTree(TChain* treeName,char* particleType);

TTree* uniqueTree(TChain* oldTree,char* particleType){
  const int nentries = (const int)oldTree->GetEntries();

  int upper;
  int lower;
  double UID;
  double psimass;
  if(!strcmp(particleType,"Psi2s")){
    oldTree->SetBranchAddress("upper",&upper);
    oldTree->SetBranchAddress("lower",&lower);
    oldTree->SetBranchAddress("psiUID",&UID);
    oldTree->SetBranchAddress("psimass",&psimass);
  }

  oldTree->SetBranchStatus("*",0);
  oldTree->SetBranchStatus("upper",1);
  oldTree->SetBranchStatus("lower",1);
  oldTree->SetBranchStatus("psiUID",1);
  oldTree->SetBranchStatus("psimass",1);

  TTree *newtree = oldTree->CloneTree(0);

  for (Int_t i=0;i<nentries; i++) {
    oldTree->GetEntry(i);
    newtree->Fill();
  }
  newtree->Print();
  newtree->AutoSave();
  newtree->Show(0);
  oldTree->Delete();
  return newtree;
}

i do a "Show" of the zeroth entry of the returned tree and get different
results.

***Before TTree* is returned
======> EVENT:0
 upper           = 1227159
 lower           = -1940522577
 psimass         = 3.4278
 psiUID          = 10939

***After TTree* is returned
======> EVENT:0
 upper           = 142061856
 lower           = 1
 psimass         = 3.4278
 psiUID          = 0

any help would be greatly appreciated.
thanks,
alex.



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