TTree->GetEntry() and (multiple virtual) inheritance

Hallo all,

I have just discovered something with TTree->GetEntry and (multiple virtual) inheritance.

I have a class that inherits like this:

I sketch the code here:

class Base {
 Int_t common_variables; 
 TTree *tree;

Base::loop {
 for (int i=0; i < last; i++) {

class DeriveA: public Base {
 Double_t HT; // tree variable

class DeriveB: public Base {

class myClass public DeriveA, public DeriveB {

DeriveA::loadTree() {
 ## load some file ##
 tree = (TTree*)gDirectory->Get("EV0");
 tree->SetMakeClass(1); // copy & paste from tree->MakeClass output
 ## HT ok!
 ## tried this:
 ## tree->GetEntry(0)
 ## HT ok!

 tree->LoadTree(i); // copy&paste from tree->MakeClass output
 common_variables = some_function(HT);
 ## HT not OK if tree->SetBranchAddress("HT",&HT); is called earlier

 some_otherfunction (common_variables);

I observe now this:
I have an instance of myClass and I call myClass::loop which is Base::loop, then DerivedA::loadTree is called which loads the tree and sets the branch addresses to variables that are defined in DerivedA, e.g. Double_t HT. In the loop DerivedA::getEntries is called and the value of HT is printed out. Now the value of HT is completely wrong.

I tested it with getting the entry (only one) right after I loaded the tree with exactly the same commands (SetBranchAddress(“HT”,&HT); GetEntry(0):wink: HT has the right value. If I then follow with a debugger the value of HT it suddenly is wrong after DerivedA::getEntries (same commands!) is called.
Testing it with a fixed value of HT and never calling SetBranchAddress(“HT”,&HT), the value of HT is always the same, so no flaw in my classes (and HT is only defined in DerivedA, never overwritten by any child classes).

I also tried not to use multiple virtual inheritance like this:

I still get the same problem that after the second GetEntry call the value of HT is wrong.

So is this a ROOT problem?

Thank you

[quote]So is this a ROOT problem? [/quote]Per se, probably not (it looks more like advanced C++ coding issue :slight_smile: )
There are too many missing part in your code for me to understand what’s going on. Could you please send a complete, short example reproducing your problem so we can determine what’s really going on?



after hours of testing, I found my mistake. Setting a Branch to a variable (SetBranchAddress(“HT”,&HT) ) and then calling TTree::Scan(“HT”) changes the value of HT (to the last output value). I added these “Scan” lines for dedugging, not noticeing that it created another problem.

It has nothing to do with inheritance etc. (I suspected some pointer that was changed to the wrong address).

Mea cupla