Hi @eguiraud,
Thank you for your kind reply. Unfortunately, I do not have much experience dealing with libraries, so I may need some help to proceed further. I have included what I have made so far.
First, I create a file named “functions.cpp
”:
#include "ROOT/RVec.hxx"
auto myfunc(ROOT::VecOps::RVec<double> &x) {
return x * x;
}
To compile it, I enter a python session and do the following:
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.gSystem.CompileMacro('functions.cpp', 'O')
Info in <TUnixSystem::ACLiC>: creating shared library /home/fanurs/learn/functions_cpp.so
1
>>>
I believe so far everything is alright because I don’t see errors. Also, two files have been created at the current directory, namely,
- “
functions_cpp_ACLiC_dict_rdict.pcm
” and
- “
functions_cpp.d
”.
After this is where I got stuck. How can I invoke the myfunc()
in another python script? I tried the following in a new python file, “test.py
”:
import ROOT
ROOT.gSystem.Load('functions_cpp.d')
rdf = ROOT.RDataFrame('tree', 'data.root') # just some test file
rdf = rdf.Define('x_new', 'myfunc(x)')
And this is when I got an error that I couldn’t resolve:
input_line_66:2:62: error: use of undeclared identifier 'myfunc'
auto lambda0 = [](ROOT::VecOps::RVec<Double_t>& var0){return myfunc(var0)
^
Traceback (most recent call last):
File "test.py", line 4, in <module>
rdf = rdf.Define('x_new', 'myfunc(x)')
cppyy.gbl.std.runtime_error: Template method resolution failed:
ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void>::Define(basic_string_view<char,char_traits<char> > name, basic_string_view<char,char_traits<char> > expression) =>
runtime_error:
RDataFrame: An error occurred during just-in-time compilation. The lines above might indicate the cause of the crash
All RDF objects that have not run an event loop yet should be considered in an invalid state.
Thanks,
Fanurs