I like using namespaces in my C++ code. It really helps to avoid name collisions and keep code blocks coherent.
I just ran into a problem where the namespace is confusing PyROOT. I have some code in a file MySpline2.C (attached), which I load in PyROOT with ROOT.gROOT.ProcessLine(".L MySpline2.C+").
If I do help(ROOT.MySpline2.CorrectionVerifier) I see the following constructors:
| __init__(self, MySpline2::MySpline2::Spline& corr)
| CorrectionVerifier::CorrectionVerifier()
| CorrectionVerifier::CorrectionVerifier(MySpline2::MySpline2::Spline& corr)
| CorrectionVerifier::CorrectionVerifier(const MySpline2::MySpline2::CorrectionVerifier&)
But in the C++ file, the structure looks like this:
namespace MySpline2{
class Spline
class CorrectionVerifier
}
So there’s a weird inconsistency, I can access things with ROOT.MySpline2.Spline, not ROOT.MySpline2.MySpline2.Spline, but the constructor clearly expects that extra “MySpline2” namespace or nested class. When I try to use it naively with a ROOT.MySpline2.Spline object, I get this error:
RuntimeWarning: creating converter for unknown type "MySpline2::MySpline2::Spline&"
I am pretty sure that this is related to my #pragma statements at the bottom of the .C file. Unfortunately the documentation for the various #pragma statements, especially around namespaces, is terrible. I can’t even tell if I’m supposed to have “#pragma link on nestedclass” or “#pragma link on nestedclasses” because the documentation is inconsistent. Because of the nature of #pragma, if I make a mistake, I don’t get an error, it’s just ignored. Hopefully an expert can advise on the proper #pragmas needed to see all the classes, functions, namespaces, etc, in the C file from PyROOT.
Jean-François
MySpline2.C (26.1 KB)