gpt4 book ai didi

python - python 中 C++ vector 的实例(对于 pyROOT 中的 TTrees)

转载 作者:太空狗 更新时间:2023-10-29 20:28:56 24 4
gpt4 key购买 nike

我正在尝试使用 pyROOT 在 python 中为 TTree(一个 ROOT 对象)制作过滤器.我从具有多个分支的 TTree 获取信息,其中一些是 C++ 类型 vector<int> , vector<float>vector<string>的。

为了将信息传递到新树中,我需要从旧树访问它,我需要将 vector 等的地址传递给树,然后填充树。为此,我需要访问此类新 vector 的地址。这在 C++ 中很容易,但是在查看了 Cython 和 boost 之后,我无法解决它。最终我想要这样的东西:

cppintvectorinpython = getcppintvector()    
oldtree.setbranchaddress(branchname,cppintvectorinpython)

这可能吗?

最佳答案

CINT为您导出了多个STL类,其中std::vector .创造例如一个std::vector<double>从 pyROOT 做

import ROOT as r
vec = r.vector('double')()

设置TTree的分支地址由于 pyROOT,然后非常透明,例如你不需要使用指针

tree = r.gDirectory.Get('oldtree')
tree.SetBranchAddress("vec_branch_name", vec)

关于python - python 中 C++ vector 的实例(对于 pyROOT 中的 TTrees),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11673493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com