【问题标题】:Instance of a C++ vector in python (for TTrees in pyROOT)python 中的 C++ 向量实例(用于 pyROOT 中的 TTrees)
【发布时间】:2012-07-25 06:53:42
【问题描述】:

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

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

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

这可能吗?

【问题讨论】:

    标签: python c++ boost cython root-framework


    【解决方案1】:

    CINT 为您导出了许多 STL 类,其中包括 std::vector。创建例如来自 pyROOT 的 std::vector<double>

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-30
      • 1970-01-01
      • 2010-10-17
      • 1970-01-01
      • 2018-12-29
      相关资源
      最近更新 更多