void tclwrite(Int_t split) { // Generate a Tree with a TClonesArray // The array can be split or not TFile f("tcl.root","recreate"); f.SetCompressionLevel(1); //try level 2 also TTree T("T","test tcl"); TClonesArray *arr = new TClonesArray("TLine"); TClonesArray &ar = *arr; T.Branch("tcl",&arr,256000,split); //By default a TClonesArray is created with its BypassStreamer bit set. //However, because TLine has a custom Streamer, this bit was reset //by TTree::Branch above. We set again this bit because the current //version of TLine uses the automatic Streamer. //BypassingStreamer saves space and time. arr->BypassStreamer(); for (Int_t ev=0;ev<10000;ev++) { ar.Clear(); Int_t nlines = Int_t(gRandom->Gaus(50,10)); if(nlines < 0) nlines = 1; for (Int_t i=0;i<nlines;i++) { Float_t x1 = gRandom->Rndm(); Float_t y1 = gRandom->Rndm(); Float_t x2 = gRandom->Rndm(); Float_t y2 = gRandom->Rndm(); new(ar[i]) TLine(x1,y1,x2,y2); } T.Fill(); } T.Print(); T.Write(); }