CASTing an abstract class in pyROOT

Hi there,

I can do the following in C++ with a ROOT-ified library, that I explain in pseudo-code

TClass *cl = TClass::GetClass( "DerivedClassName" ); AbstractClass *p = (AbstractClass *) cl->New();

Then I have a method that recieves as argument an AbstractClass

This works with out problems in ROOT-C++

However now I try to find out how to do the same in pyROOT

cl = ROOT.TClass.GetClass( "DerivedClassName" )
P = cl.New()

otherClass.Set( p )

But I get an error saying that it cannot convert argument 1.

Then I try to cast it manually by doing

p = ROOT.AbstractClass ( cl.New() )

Then I get the message:
[color=#FF0000]AbstractClass is abstract and can not be instantiated[/color]

Any idea is welcome,

TClass::New() returns a ‘void*’ and this is not mapped to any Python object representing an C++ object. To convert a ‘void*’ to real C++ object you can use the following function:

p = ROOT.TPython.ObjectProxy_FromVoidPtr( cl.New(), 'DerivedClassName')

Later, it can be used as you wanted in a function/method expecting an abstract interface.

otherClass.Set( p )

I do not not know what exactly you want to do, but it is much simple to just ask to the top level PyROOT module the class you are interested and instantiate it.

import ROOT
p  = getattr(ROOT, 'DerivedClassName')()  # or simply ROOT.DerivedClassName()
otherClass.Set( p )