[ROOT] TTree Friend issues

From: Matt Palmer (palmer@hep.phy.cam.ac.uk)
Date: Fri Apr 05 2002 - 13:36:03 MEST


Hi,
I've had some problems when adding friends to TTrees when those friends are 
in the same file.  I am using ROOT v3.03/03 on rhlinux v7.1.  The script 
demonstrates the problems which are:
ROOT generates lots of warning when adding a friend tree in the same file by 
filename (but it does work)
When a friend TTree is in the same file, ROOT needlessly opens another copy 
of the file rather than using the one already there.  
If the friend is created by using a TFile* pointer, then no warning messages 
are produced but ROOT SEGVs when trying to close the file.
If two TTrees are friends of each other and this has been set up with TFile* 
then closing the file results in a hang - not even a SEGV.

These 4 issues are demonstrated in this script - uncomment the labelled lines 
to see.

Matt

{
	//Tree Friendship test:
	Float_t a,b;
	TFile* f = new TFile("TreeFriend.root", "recreate");
	TTree* t1 = new TTree("t1", "Test tree 1");
	TTree* t2 = new TTree("t2", "Test tree 2");
	t1->Branch("a", &a, "a/F");
	t2->Branch("b", &b, "b/F");

	//Critical lines:
//	t1.AddFriend("t2", "TreeFriend.root"); //1,2: Works but lots or warnings
//	t2.AddFriend("t1", "TreeFriend.root"); //2: Works, lots of warnings and 
//					ROOT opens 2 copies of the same file
//	t1.AddFriend("t2", f);	//3: Causes a segv when trying to close f
//	t2.AddFriend("t1", f);	//4: Now it won't even segv - it just hangs

	for (int i=0; i<1000; i++) {
		gRandom->Rannor(a, b);
	  	t1->Fill();
		t2->Fill();
	}

	t1->Write();
	t2->Write();
	f->Write();
//	cout << "Segv about to occur...." << endl;  //3
//	f->Close();		//3:  Segv here!
}



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