Re: [ROOT] how to add new branches ?

From: HP Wei (hp@rentec.com)
Date: Sun Dec 15 2002 - 15:12:33 MET


The following short program has two problems.
(The program is to generate a tree with two branches.
 Each branch is constructed and filled up inside the
 for(i=...) loop.
 YES, the branches are generated one by one, not at the same time.
 But they are have the same number of entries.)
 
Two problems:
(1) As it is, the i=2 round still fails at the tree->Branch().
(2) if tree->Delete(sym) is commented out,
    the program runs fine.
    But in the generated root file 
    S.Show(100) does not show the right data.
    
Has anyone experience of generating more than one branch
one by one in one program    ???

Thanks,
--HP

----------------------------------------
#include <fstream>

#include <TROOT.h>
#include <TFile.h>
#include <TTree.h>
#include <TBranch.h>

int main()
{
  char sym[100];
  char symType[100];
  int N= 2;
  int M= 2000;
 
  TROOT root("ROOT", "Test");
  TFile *fout = new TFile("./test.root", 
		     "RECREATE", "testing");
  TTree * tree = new TTree("S", "");
 
  double var;
  TBranch *br;

  for(int i=0; i<N; ++i) {    
    sprintf(sym, "field%d", i);
    sprintf(symType, "%s/D", sym);
    cout << i << " " << sym << " " << symType << endl;

    br = tree->Branch(sym,  &var, symType); // Segmentation Fault
    
    cout << "after tree->Branch()" << endl;
    
    for (int k=0; k<M; ++k) {
        var = 1.0;
        br->Fill();
    }
    
    br->Write();
    tree->Delete(sym); // ************* ???
    cout << "end of loop"<< endl;
  }
  cout << "out of loop" << endl;
  tree->Write();
  fout->Close();
}



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