Re: [ROOT] how to add new branches ?

From: HP Wei (hp@rentec.com)
Date: Sat Dec 14 2002 - 23:47:35 MET


I tried to move the 'double var' outside the loop.
It still does not work.

What I am doing is a little different from the examples in tree[1-4].C
In all those examples, all the branches in the tree
are declared before tree->Fill().
In my case, I want to fill up one (or several) branch first.
Write it out to disk.
And then declare another branch(es), fill in data, write it out....
Eventaully, there will be thousands of branches.
The var is used as a temporary place for getting data into the
branches.

Is the problem due to that I cannot use the same var
for different branches ?

Or do I need to save the root_file after each generation of a branch,
and then re-open the root_file with 'update' mode ???
If I have no other choice, I would do this.

HP

> > char sym[100];
> > char symType[100];
> > int N= 1000;
> > int M= 2000;
> >
> > Open_root_file;
> > TTree * tree = new TTree("S", "");
> > double var;    // outside of loop

> > for(int i=0; i<N; ++i) {
> >    // double var;
> >    sprintf(sym, "field%d", i);
> >    sprintf(symType, "%s/D", sym);
> >    TBranch *br =tree->Branch(sym,  &var, symType); // Segmentation
Fault
> >
> >    for (int k=0; k<M; ++k) {
> >        var = 1.0;
> >        br->Fill();
> >    }
> >
> >    br->Write();
> >    tree->Delete(sym);
> > }
> >
> > tree->Write();
> > Save_the_root_file;
> >
> > ------------------------------------------------
> > Thanks,
> > HP
> >
>
>



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:23 MET