SetBranchAddress multiple addresses?

Hello,
I would like to link multiple variables to a single tree branch.
It seems to work in interactive, but I have to use TTree::SetMakeClass(1);

{
        TTree *t1 = _file0->Get("mytree");
        double Zvtx, Zvtx2;
        t1->SetMakeClass(1);
        t1->SetBranchAddress("vertex.z", &Zvtx);
        t1->SetBranchAddress("vertex.z", &Zvtx2);
        t1->GetEntry(0);
        cout << Zvtx << " " << Zvtx2 << endl;
}

0.00 -0.244

In practive the second setbranchaddress is called within a class. So I cannot just play with pointers in order to copy Zvtx pointer into Zvtx2. Of course this would be easy to do.
Knowing that the 2 zvtx variables might not exists at the same moment. Is there a way to copy it safely?

Edit: I saw it is possible to set an alias, but it seems I cannot use it with SetBranchAddress
Edit-2: I tried to use TBranchElement::GetAddress(), it returns a char* but I don’t know how to use it to get the corresponding object

I would say it’s not possible, but maybe @Axel or @pcanal could know a way…

Hello,

I just figured out. It is not very clean but I do the following:

if( t->GetBranch("branchname")->GetAddress()  != NULL )
cout << *((double*) t->GetBranch("branchname")->GetAddress() << endl;

Oh, OK, sorry, I replied to the multiple addresses question…

1 Like

Correct. Alias are for TTree::Draw.

1 Like

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