Problems with TTree::SetBranchAddress()

Hello, I got following weird behavior with TTree::SetBranchAddress():

I have a class TSelected that contains some class members like this:

[code] class TSelected{

TTree* pTree;

Int_t myInt;
Double_t myDouble;

TObjArray* myBigProblem;
//[…] etc.

The Tree Pointer is associated with a TTree I get from a file in the constructor of TSelected. The problem I have occurs in a method of TSelected:

[code]void TSelected::InitializeTree()
pTree->SetBranchAddress(“myInt”, &myInt); //works fine
pTree->SetBranchAddress(“myDouble”, &myDouble); //works fine

pTree->SetBranchAddress(“myBigProblem”, &myBigProblem); //ERROR!!!

When running InitializeTree(), i get a segmentation violation calling SetBranchAddress() with a pointer to TObjArray. BUT I get it only when myBigProblem is a class member ob TSelected. When I declare it outside the class as a global variable, the code works without problems. And yes, the TTree contains a leaf with the corresponding name an correct type.
One might think I could leave myBigProblem outside the class definition, but thats no good option, not only because of aesthetical reasons (global variables are evil), but because I want to have more than just one instance of TSelected and the instances must not share myBigProblem.
So what can I do?


do you initialize myBigProblem (e.g. to 0)? If myBigProblem is !=0, ROOT assumes that you allocated memory for the TObjArray already, and writes to whatever myBigProblem points to. That’s of course fatal if it’s uninitialized. If it’s 0 ROOT will take care of the allocation itself.



it seems to work now. I added zero-initialisation to the constructor list. I didn’t know that class-members are not zero-initialized by default. #-o