Hi Rob,
When you try to update the tree you have typed:
> TFile f("r1.root","update");
> TTree *tree = (TTree*)f->Get("T");
> Double_t run;
> TString run_ls = "run/D";
> tree->Branch("run",&run,run_ls.Data());
This has the effect of adding a 2nd branch with
the same name. Instead of the last line you
should be using:
tree->SetBranchAddress("run",&run");
Cheers,
Philippe.
-----Original Message-----
From: owner-about-root@listserv.fnal.gov
[mailto:owner-about-root@listserv.fnal.gov]On Behalf Of Rob Snihur
Sent: Thursday, March 14, 2002 3:12 PM
To: about-root@fnal.gov; roottalk@pcroot.cern.ch
Subject: problem with tree update
Hi,
I am having some trouble with adding events to an existing tree.
My session (pasted below) shows that the additional event
that I attempted to add has a zero value for the single variable in the
tree.
Can someone help please?
thanks,
-rob
fcdfsgi2 638% cat new_tree.C
{
TFile f("r1.root","update");
TTree *tree = new TTree("T","kitchensink");
Double_t run;
TString run_ls = "run/D";
tree->Branch("run",&run,run_ls.Data());
run = 140257.0;
tree->Fill();
tree->Print(); // print n-tuple
tree->Write(); // Write output root file.
}
fcdfsgi2 639% root -q -b new_tree.C
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.01/06 27 July 2001 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
Compiled with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.07, July 7 2001
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing new_tree.C...
******************************************************************************
*Tree :T :
kitchensink *
*Entries : 1 : Total = 496 bytes File Size =
496 *
* : : Tree compression factor =
1.00 *
******************************************************************************
*Br 0 :run :
run/D *
*Entries : 1 : Total Size= 0 bytes File Size
= 0 *
*Baskets : 0 : Basket Size= 32000 bytes Compression=
1.00 *
*............................................................................*
fcdfsgi2 640% root r1.root
Warning in <TGX11::OpenDisplay>: system has no X11 thread support
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.01/06 27 July 2001 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
FreeType Engine v1.x used to render TrueType fonts.
Compiled with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.07, July 7 2001
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Attaching file r1.root...
root [1] T->Scan("run");
************************
* Row * run *
************************
* 0 * 140257 *
************************
root [2] .q
fcdfsgi2 641% cat update_tree.C
{
TFile f("r1.root","update");
TTree *tree = (TTree*)f->Get("T");
Double_t run;
TString run_ls = "run/D";
tree->Branch("run",&run,run_ls.Data());
run = 140257.0;
tree->Fill();
tree->Print(); // print n-tuple
tree->Write(); // Write output root file.
}
fcdfsgi2 642% root -q -b update_tree.C
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.01/06 27 July 2001 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
Compiled with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.07, July 7 2001
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Processing update_tree.C...
******************************************************************************
*Tree :T :
kitchensink *
*Entries : 2 : Total = 367 bytes File Size =
367 *
* : : Tree compression factor =
1.00 *
******************************************************************************
*Br 0 :run :
run/D *
*Entries : 2 : Total Size= 0 bytes File Size
= 0 *
*Baskets : 0 : Basket Size= 32000 bytes Compression=
1.00 *
*............................................................................*
*Br 1 :run :
run/D *
*Entries : 1 : Total Size= 0 bytes File Size
= 0 *
*Baskets : 0 : Basket Size= 32000 bytes Compression=
1.00 *
*............................................................................*
fcdfsgi2 643% root r1.root
Warning in <TGX11::OpenDisplay>: system has no X11 thread support
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.01/06 27 July 2001 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
FreeType Engine v1.x used to render TrueType fonts.
Compiled with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.07, July 7 2001
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]
Attaching file r1.root...
root [1] T->Scan("run");
************************
* Row * run *
************************
* 0 * 140257 *
* 1 * 0 *
************************
root [2] .q
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:45 MET