TTree in boost.python

Hello

I want to use TTree in boost.python like this

#include "TTree.h"


void printTree(TTree* t) {
   t->Print();
}

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(myroot)
{
        def("printTree", printTree, "printTree");
}

How can I fix my code?

Hi,

I am not familiar with boost python per se but it sounds like it offer similar facility as PyROOT itself (i.e. give you a way to access your C++ code from python).

To take advantage of this feature you need to generate (via rootcint or genreflex) a dictionary for your C++ entities (functions, classes), compile and link into your shared library and simply load that shared library into your python session.

The simpliest way of doing this is to use ACLiC (for example directly from python):gROOT.LoadMacro( "myroot.C+" )

Cheers,
Philippe.

Hi,

in the code above you’re expecting boost.python to know about PyROOT objects, but of course it does not. Either write your own custom converter for it, or passing it as a CObject may work already:cobj_tree = ROOT.AsCObject( tree ) myroot.printTree( cobj_tree )
HTH,
Wim