Hi HP, Each branch must have its own address. It does not make sense to share the same address between different branches. The declaration double var inside the loop cannot work. Declare the variables that you intend to declare to branches outside the loop. I strongly suggest to read the Users Guide and in particular the tutorials tree1,2,3,4.C Rene Brun On Fri, 13 Dec 2002, HP Wei wrote: > I want to create a big tree with many branches. > But I need to create one or several branches at a time. > After the following pseudo-code (for one branch at at time) > goes through i=0, then > it produces Segmentation Fault at i=1 at TBranch *br statement. > > What should I do? > > --------------------------------------------- > char sym[100]; > char symType[100]; > int N= 1000; > int M= 2000; > > Open_root_file; > TTree * tree = new TTree("S", ""); > > 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