I have a piece of PyROOT code (mainly for usability, but should be easy to translate into C++) where I am creating two branches of std::vector<T>
types (one 32b int, one double):
import ROOT
fp = ROOT.TFile.Open("stl_containers.root", "RECREATE")
tree = ROOT.TTree("tree", "")
ROOT.gROOT.ProcessLine("""
std::vector<int32_t> vector_int32;
std::vector<double_t> vector_double;
std::vector<int32_t>* address_int32 = &vector_int32;
std::vector<double_t>* address_double = &vector_double;
""")
tree.Branch('vector_int32', ROOT.address_int32)
tree.Branch('vector_double', ROOT.address_double)
data = [3, 6, 9]
for i in range(10):
ROOT.vector_int32.clear()
ROOT.vector_double.clear()
for d in data:
ROOT.vector_int32.push_back(int(d+i))
ROOT.vector_double.push_back(float(d*i))
tree.Fill()
tree.Print()
tree.Write()
fp.Close()
How do I get it so that vector_double
is a branch written with kStreamedMemberWise
enabled? I have tried, for example, adding these lines before the for
loop
basket = tree.CreateBasket(tree.GetBranch('vector_double'))
tree.GetBranch('vector_double').AddBasket(basket, False, 0)
basket.SetBit(ROOT.TBufferFile.kStreamedMemberWise, 1)
to set this bit on the corresponding basket (doesn’t work, and the ROOT file written out is pretty badly mangled). The goal here is to have a std::vector<double>
in a branch that’s been written out member-wise instead (and on some level, learn how to force this flag to be set, which does not seem to be obvious atm).
I have also tried the following at the top
fp.SetBit(ROOT.TBufferFile.kStreamedMemberWise, 1)
as well as the following at the bottom (before tree.Write()
):
tree.GetBranch('vector_double').GetBasket(0).SetBit(ROOT.TBufferFile.kStreamedMemberWise, 1)