Pyroot, reading return of a macro

Hi guys

I am trying to run a simple script with pyroot. This script execute a macro that return a std:vector of double
The problem is that I am not able to retrieve the vector when I execute the code.

A working minimal example is given below. Try to run

ROOT Version: 6.26/10
Platform: linuxx8664gcc
Compiler: 11.3.0

code.cpp (68 Bytes) (160 Bytes)

Hi Adriano,

TInterpreter::ProcessLine returns the pointer to the returned value as a 64 bit integer. You can clearly cast it to the right type and then use it, but it would be a bit sophisticated (even if very powerful).
A simpler solution would be to modify your Python code as follows:

import ROOT
import numpy as np

result = ROOT.code()
npresult = np.asarray(result)
print( type(npresult), "value: ", npresult)
# prints <class 'numpy.ndarray'> value:  [1. 2. 3.]

The line ROOT.gInterpreter.LoadMacro("code.cpp") simply loads into the ROOT type system the content of the macro code.cpp. Then you can find back all the C++ entities defined there in the ROOT Python “module”.


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.