Writing/reading TTree from TMessage

Hi,

I have a root file which contains TDirectoryFiles, one per event. Each TDirectoryFile contains TTree storing some information about the event. I need to add the title of TDirectoryFile to the tree, put it into TMessage and then read from TMessage and extract this title back. The problem is that after putting and extracting from TMessage this infomation is gone. Here is the code example:

// I open a file which contains TDirectoryFiles, each containing TTree
	TFile *inFile = TFile::Open("ITS.RecPoints.root");

 	string *name = new string(inFile->GetListOfKeys()->Last()->GetTitle());
	cout<<"last directory file is:"<<name->data()<<endl; // here I get "Event1"

	// I get TTree from last directory, create new branch and fill it with name "Event1"
 	TTree *tree = (TTree*)((TDirectoryFile*)inFile->Get(name->data()))->Get("TreeR");
	tree->Branch("event",&name);
	tree->Print();// why I need that?
	tree->Fill();

	// writing to TMessage:
	TMessage tmess(kMESS_OBJECT);
  	tmess.Reset();
  	tmess.WriteObject(tree);
  	
	// reading from TMessage:
	tmess.SetReadMode();
    	tmess.InitMap();
    	tmess.ReadClass();
    	tmess.SetBufferOffset(sizeof(UInt_t) + sizeof(kMESS_OBJECT));
    	tmess.ResetMap();

	// TTree after writing and reading from TMessage:
    	TTree *resultTree = (TTree*)(tmess.ReadObjectAny(TTree::Class()));

	//TTree *resultTree = tree; // with this line uncommented it works

	// here I extract name stored in "event" branch:
	string *resultName = new string();
	resultTree->SetBranchAddress("event",&resultName);
	resultTree->GetEntry(0);
	cout<<"Result name:"<<resultName->data()<<endl;// resultName is empty...

I attach the file which I use in this case. How should do this operation properly? One more question is - why this macro crashes when I comment out line 12?
ITS.RecPoints.root (43.4 KB)

See sft.its.cern.ch/jira/browse/ROOT-6963