Branch address emptied when updating a variable

Hello,

I have a problem, that it seems my TTree branch address becomes empty when I change a value of a simple int to which it points.

tdataflow->Branch("cmd_content",&CmdContent,"cmd_content/i");

Then I use it in some other function:

	cout << "br3 " << tdataflow->GetBranch("cmd_content")->GetAddress() << endl;
	cout << & CmdContent << endl;
	CmdContent = 0;
	cout << & CmdContent << endl;
	cout << "br3.1 " << tdataflow->GetBranch("cmd_content")->GetAddress() << endl;

The result is, that everywhere in the code before CmdContent=0, I get the same branch address printed. After the CmdContent=0, the branch adress value printed is empty. The &CmdContent remains the same.

This is a root 5.34.36 issue, for which I know the support is dead, but still hope that maybe someone can point an obvious mistake…

Problem fixed, although I do not understand the solution. The TTree I was writing to was in a class that I created simply as

Class obj;

When I changed it to

Class *obj = new Class();

and all the calls to methods to pointer calls, the problem disappeared…

I’m not using root 5 any more but my best guess is that the problem is elsewhere in your code. Whenever a problem is as strange as yours and when a “new” fixes your problem, you probably have some undefined behavior in your code. Maybe you are writing to some place in memory where you shouldn’t, or have something like a double delete in your code.

Can you could provide a minimal but complete example of the problem, i.e. code that one can simply run in root to reproduce the problem? Often one can find bugs by trying to reduce the code :slight_smile:

“cmd_content/i” explicitly denotes “a 32 bit unsigned integer (UInt_t)”, and so “&CmdContent” will be assumed a pointer to an ordinary UInt_t variable.

Yes, and it is a standard “unsigned int”, declared in the class definition.

I also suspect something wrong with memory in some other place. I will try to trace it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.