I modified my code to put the Poly functions in a class MySpline. I also added namespace for the sake of the C+±side of my code. Also it turns out I need this to work for both ROOT5 and ROOT6 (and with PyROOT), I don’t know if that’s even possible anymore…
Unfortunately my example was too simplified. The full code is attached to this post.
Here’s what I see with ROOT6:
* ROOT v6.02/00-rc1 *
root [0] .L MySpline.C+
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/jfcaron/Projects/Proto2BeamTest2/code_test/./MySpline_C.so
root [1] double x[] = {5}
(double [1]) { 5.000000e+00 }
root [2] double c[] = {1,2,3,4,5}
(double [5]) { 1.000000e+00, 2.000000e+00, 3.000000e+00, 4.000000e+00, 5.000000e+00 }
root [3] MySpline::MySpline::Poly<5>(x,c)
(double) 3.711000e+03
root [4] MySpline::MySpline::PolyDeriv<5,2>(x,c)
(double) 1.626000e+03
root [5] double k[] = {3}
(double [1]) { 3.000000e+00 }
root [6] MySpline::PieceWise<1,3> pw(k)
(MySpline::PieceWise<1, 3> &) @0x1145430a0
root [7] pw(x,c)
(double) 1.220000e+02
and I can use the test1, test2, test3, test4 functions from MySpline.
In PyROOT, I see this:
In [1]: import ROOT
In [2]: ROOT.gROOT.ProcessLine(".L MySpline.C+")
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/jfcaron/Projects/Proto2BeamTest2/code_test/./MySpline_C.so
ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/cStringIO.so' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in <ACLiC>: Compilation failed!
Out[2]: 0L
Actually that’s a separate problem where somehow ACLiC doesn’t work in PyROOT, but if I .L MySpline.C+ from regular ROOT before, then I can load and use the .so without problems:
In [1]: import ROOT,array
In [2]: ROOT.gROOT.ProcessLine(".L MySpline.C+")
Out[2]: 0L
In [3]: x = array.array('d',[5])
In [4]: c = array.array('d',[1,2,3,4,5])
In [5]: k = array.array('d',[3])
In [6]: ROOT.MySpline.MySpline.Poly(5)(x,c)
Out[6]: 3711.0
In [7]: ROOT.MySpline.MySpline.PolyDeriv(5,2)(x,c)
Out[7]: 1626.0
In [8]: pw = ROOT.MySpline.PieceWise(1,3)(k)
In [9]: pw(x,c)
Out[9]: 122.0
Now if I switch to ROOT5, the nothing works in CINT:
* ROOT v5.34/18 *
root [0] .L MySpline.C++
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/jfcaron/Projects/Proto2BeamTest2/code_test/./MySpline_C.so
root [1] double x[] = {5}
root [2] double c[] = {1,2,3,4,5}
root [3] double k[] = {3}
root [4] MySpline::MySpline::Poly<5>(x,c)
Error: > Illegal operator for pointer 3 (tmpfile):1:
(const int)0
*** Interpreter error recovered ***
root [5] MySpline::MySpline::PolyDeriv<5,2>(x,c)
Error: Symbol PolyDeriv is not defined in current scope (tmpfile):1:
Warning: Illegal numerical expression 5,2 (tmpfile):1:
Error: > Illegal operator for pointer 3 (tmpfile):1:
(const int)0
*** Interpreter error recovered ***
root [6] MySpline::PieceWise<1,3> pw;
Error: Symbol PieceWise is not defined in current scope (tmpfile):1:
Warning: Illegal numerical expression 1,3 (tmpfile):1:
Error: Symbol pw is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
and now PyROOT with ROOT5:
In [1]: import ROOT,array
In [2]: ROOT.gROOT.GetVersion()
Out[2]: '5.34/18'
In [3]: ROOT.gROOT.ProcessLine(".L MySpline.C+")
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/jfcaron/Projects/Proto2BeamTest2/code_test/./MySpline_C.so
Out[3]: 0L
In [4]: x = array.array('d',[5])
In [5]: c = array.array('d',[1,2,3,4,5])
In [6]: k = array.array('d',[3])
In [7]: ROOT.MySpline.MySpline.Poly(5)(x,c)
*** Break *** segmentation violation
Generating stack trace...
0x0000000105144303 in PyObject_Call (in Python) + 99
0x00000001051e21ae in PyEval_EvalFrameEx (in Python) + 16030
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e2e70 in PyEval_EvalFrameEx (in Python) + 19296
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x0000000105169dfc in function_call (in Python) + 364
0x0000000105144303 in PyObject_Call (in Python) + 99
0x00000001051e180d in PyEval_EvalFrameEx (in Python) + 13565
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051e5c29 in fast_function (in Python) + 297
0x00000001051e14e5 in PyEval_EvalFrameEx (in Python) + 12757
0x00000001051de09d in PyEval_EvalCodeEx (in Python) + 1725
0x00000001051dd9d6 in PyEval_EvalCode (in Python) + 54
0x0000000105207544 in PyRun_FileExFlags (in Python) + 164
0x00000001052070c1 in PyRun_SimpleFileExFlags (in Python) + 769
0x000000010521cd1e in Py_Main (in Python) + 3070
0x00007fff90dd75fd in start (in libdyld.dylib) + 1
I tried removing the namespace for ROOT5, but it doesn’t change anything. In ROOT5 I can run the test1()…test4() functions and they work.
So, is it possible to make my few templated classes work? Why does MySpline::MySpline::Poly work but MySpline::PieceWise? I guess it’s because PieceWise is itself templated, while Poly is a templated method of a non-templated class?
Jean-François
MySpline.C (7.98 KB)