Nested namespaces and unloaded classes with a dictionnary from C++ to python

Bonjour

I’ve a question about dictionary generation and the library auto-loading done with ROOT when dealing with python interface. I’m so far amazed by how simple that is (thanks a lot for that) and would like to know whether I might be doing something wrong in my mwe.

I’m defining new classes within nested namespace, all inheriting from ROOT and I’ve realised that if I have several namespace I cannot access by autocompletion the content of the underlying objects.

In order to be a but clearer, I’ve created a mwe only defining a poinless class (taken out of your documentation actually :stuck_out_tongue:) and I’ll use it either in single namespace level or a two namespace one.
In the attached tarball you’ll find the twoints.(cpp/hpp) that define the TwoInts class with a preprocessor argument (-DTWOLEVELS) that states that there will be two nested namespace (CHOCOLAT::JBB::slight_smile: instead of one (only JBB::).

Once ROOT is setup and I’m doing

export LD_LIBRARY_PATH=$PWD:$LD_LIBRARY_PATH
make single

I’m producing a libJBB.so, libJBB.rootmap and libJBB_rdict.pcm which allow me to get this in the python console

from ROOT import JBB
dir(JBB)

[‘TwoInts’,
add’,
bool’,
class’,
delattr’,
destruct’,
dict’,
dir’,
dispatch’,
doc’,
eq’,
format’,
ge’,
getattribute’,
gt’,
hash’,
init’,
init_subclass’,
invert’,
le’,
lt’,
module’,
mul’,
ne’,
neg’,
new’,
pos’,
python_owns’,
radd’,
reduce’,
reduce_ex’,
repr’,
rmul’,
rsub’,
rtruediv’,
setattr’,
sizeof’,
smartptr’,
str’,
sub’,
subclasshook’,
truediv’,
weakref’]

It’s nice to see that I can see the class TwoInts from here and so from the auto-completion approach as well.

now changing the compilation to get two levels of namespace (CHOCOLAT::JBB) by doing this

make double

I can see this kind of results once in python

from ROOT import CHOCOLAT
dir(CHOCOLAT.JBB)

[‘add’,
bool’,
class’,
delattr’,
destruct’,
dict’,
dir’,
dispatch’,
doc’,
eq’,
format’,
ge’,
getattribute’,
gt’,
hash’,
init’,
init_subclass’,
invert’,
le’,
lt’,
module’,
mul’,
ne’,
neg’,
new’,
pos’,
python_owns’,
radd’,
reduce’,
reduce_ex’,
repr’,
rmul’,
rsub’,
rtruediv’,
setattr’,
sizeof’,
smartptr’,
str’,
sub’,
subclasshook’,
truediv’,
weakref’]

Do you have any idea why the TwoInts class is not shown anymore ?
It is working anyway, as once I’m typing this, I have no problem

p=CHOCOLAT.JBB.TwoInts(1,2)
p.GetA(), p.GetB()

(1, 2)

To be fair it’s all working smoothly, but it would be even nicer if all classes were to be seen disregarding the number of namespace. It might come from my LinkDef configuration as well, I haven’t find an example like mine so far.

Thanks in advance
cheers
jb
RootExample.tar.gz (903 Bytes)

ROOT Version: 6.26.00
Platform: fedora 32
Compiler: 10.0.1


Maybe @Axel can explain this behavior

Morning

Thanks for you reply. Just to be sure, without my message, you would have guessed that it would have worked as it is now or that all the classes would have been accessible as I was expected ?

Just out of curiosity :stuck_out_tongue:
cheers
jb

I’ll let @Axel comment on this :wink:

From first principles if you do exactly the same to JBB:: as you do to CHOCOLATE::JBB: yes, this should have worked identically. So there’s something “broken” (at least not working as optimally as it should) and I’ll have to debug that.

Hi

Thanks for the reply. What I’m doing is exactly what’s done in my mwe, when going from JBB:: to CHOCOLAT::JBB::.

Thanks for the investigations if you have time to do so.
Cheers
jb

Hi there.

Is there any lead on this topic ?

Thanks
jb

Hi @jbb,

Not that I’m aware of, sorry! @Axel is on vacations these days. However, I might be able to get it some time in the next days, let’s see.

Cheers,
J.

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