Hi Christian, Following your description, my advice is to create one single Tree with 300 branches. Then you loop on your 50000 rows, reading the 300 columns and fill the Tree. Rene On Sat, 21 Dec 2002, cstrato wrote: > Dear Rene > > Thank you for sending me your suggestion. Now my code works. > What is not quite clear to me is, that I have to create only > one object mycl of MyClass for all trees. > > My problem is the following: > I have a large table which can contain e.g. 300 columns and > 50,000 rows. Three consecutive columns contain separate data > types so that I want to create 100 trees with three branches > each and 50,000 entries each to store the data. > > Since the input table can be larger than 100MB, so that a > table 'data[id][i]' would not fit into memory, I read first > each line and store the data of each line in a temporary tree > in three branches as three arrays data1[100], data2[100] and > data3[100]. > > Then I create 100 trees, and read the data from the temporary > tree into each of the 100 trees. For this reason the code > needs to be: > // Fill trees with data > for (Int_t id=0; id<numentries; id++) { > tmptree->GetEntry(id); > for (Int_t i=0; i<numtrees; i++) { > tree = (TTree*)fList->At(i); > // mycl->SetData(data[id][i]); > mycl1->SetData(data1[i]); > mycl2->SetData(data2[i]); > mycl3->SetData(data3[i]); > tree->Fill(); > }//for_i > }//for_id > > In the last loop I write all 100 trees to the root file > together with a header for each tree. > > Currently, I have tested this only for a table containing > data for 4 trees, so I do not know if it will work for > 100 trees. Maybe I have to reduce the buffersize for each > branch? > > If you have suggestions how to solve this problem > differently, I would appreciate it. > > Thank you and best regards > Christian > > > > > Rene Brun wrote: > > > Hi Christian, > > > > You do not give enough information to process your problem. > > In particular, you do not show where/how you create your file(s). > > I suggest a simplification of your program as shown below. > > Could you implement it and let me know > > > > Rene Brun > > > > //------------------------- > > // Create trees and store in list > > TTree *tree = 0; > > MyClass *mycl = new MyClass(); > > fList->Clear(); > > for (Int_t i=0; i<numtrees; i++) { > > tree = new TTree(name[i], ""); > > tree->Branch("MyBr", "MyClass", &mycl, 64000, 99); > > fList->Add(tree); > > }//for_i > > > > // Fill trees with data > > for (Int_t i=0; i<numtrees; i++) { > > tree = (TTree*)fList->At(i); > > for (Int_t id=0; id<numentries; id++) { > > mycl->SetData(data[id][i]); > > tree->Fill(); > > }//for_id > > }//for_i > > > > // Write trees to file > > for (Int_t i=0; i<numtrees; i++) { > > tree = (TTree*)fList->At(i); > > tree->AutoSave(); > > delete tree; > > }//for_i > > //------------------------- > > > > > > On Fri, 20 Dec 2002, cstrato wrote: > > > > > >>Dear Rooters > >> > >>I would like to fill many trees at once, i.e. a list > >>of trees, with data and tried the following code: > >> > >>//------------------------- > >>// Create trees and store in list > >> TTree *tree = 0; > >> MyClass *mycl = 0; > >> fList->Clear(); > >> for (Int_t i=0; i<numtrees; i++) { > >> tree = new TTree(name[i], ""); > >> mycl = new MyClass(); > >> tree->Branch("MyBr", "MyClass", &mycl, 64000, 99); > >> > >> fList->Add(tree); > >> SafeDelete(mycl); > >> }//for_i > >> > >>// Fill trees with data > >> for (Int_t id=0; id<numentries; id++) { > >> for (Int_t i=0; i<numtrees; i++) { > >> tree = (TTree*)fList->At(i); > >> mycl = 0; > >> TBranch *br = tree->FindBranch("MyBr"); > >> br->SetAddress(&mycl); > >>// tree->SetBranchAddress("MyBr", &mycl); > >> mycl->SetData(data[id][i]); > >> br->Fill(); > >> }//for_i > >> }//for_id > >> > >>// Write trees to file > >> for (Int_t i=0; i<numtrees; i++) { > >> tree = (TTree*)fList->At(i); > >>// mycl = 0; > >>// tree->SetBranchAddress("MyBr", &mycl); > >> > >> // write tree to file > >> tree->Write("", TObject::kOverwrite); > >> tree->Delete(""); //delete tree from memory > >> tree = 0; > >> }//for_i > >>//------------------------- > >> > >>Although I do not get any error message, the trees are > >>never written to the root file, and trying to open the > >>file with TBrowser results in a bus error. > >> > >>Can you tell me what is wrong with my code and how to > >>fill many trees at once? > >>(I am running root 3.04/01 on MacOS X 1.1.2) > >> > >>Thank you in advance for your help. > >> > >>Best regards > >>Christian > >>_._._._._._._._._._._._._._._._ > >>C.h.i.s.t.i.a.n S.t.r.a.t.o.w.a > >>V.i.e.n.n.a A.u.s.t.r.i.a > >>_._._._._._._._._._._._._._._._ > >> > >> > > > > > > > >
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:24 MET