Modifying a branch with a TLeaf list


i want to read a TTree which contains a complicated TBranch with a structure like “Leaf1/i,Leaf2/F,Leaf3/i … LeafN/I” and then i just want to update one of the leaves. After that i want to store the modified TTree in a new root file. But i even cannot read the TBranch from the existing root file:

struct mystruct
UInt_t Leaf1;
Float_t Leaf2;
UInt_t Leaf3;

Int_t Leaf4;

mystruct ms;
tree->SetBranchAddress(“branch”, &ms);

With that approach i get the error that ms has not the right type. Root says it should have the type: UInt_t[17], which is wrong, because the branch has more than 17 leaves and they have different types. Has anyone an idea?

Post here the result of “tree->Print();”.
BTW. Instead of “struct mystruct ms;” you should have “mystruct ms;”.

yes that was just a typo. I attached the tree->Print() output to this message.
i want to modify the eventWeight of the branch (14) NTVars for each event and save the modified tree into a new file.
tree_print.txt (6.4 KB)

Well, it seems to me that the “NTVars” branch contains 52 simple leaves, some “UInt_t”, some “Int_t”, some “Float_t”.
So, the “sizeof(mystruct)” = “sizeof(ms)” should be 208 = 52 * 4.
If this is the case, there should be no problem, I believe. Try simply:
tree->SetBranchAddress(“NTVars”, ((UInt_t *)(&ms))); // the first leaf in “NTVars” is an “UInt_t”

Yes that worked! Thank you so much.