How to get number of args a user-made class' __init__ needs?

Hello all,
I’m trying to write a Python script to load classes made by RooClassFactory::makePdf(). I use gROOT.LoadMacro() to load class successfully, now I want to get information about what parameters the class need. I’ve browsed all functions of RooAbsPdf and its parent classes and found nothing (maybe I missed something…)

I’ve also tried Python’s way as

MyClass.__init__.__code__.co_argcount

and it didn’t work.

So, is there any way to know what parameters the user-made RooAbsPdf need?


ROOT Version: 6.22
Platform: Ubuntu20.04

@etejedor could please take a look? Thanks!

Hi,

MyClass is a C++ class, right?

You can try with:

c = ROOT.TClass.GetClass("MyClass")
methods = c.GetListOfMethods()

methods is a list of TMethod instances. You need to find in that list the constructor you are looking for and obtain the number of parameters.

See:
https://root.cern.ch/doc/master/classTClass.html#a5648dadc9ffaf897181fcc6309e7c9d3

and:
https://root.cern.ch/doc/master/classTMethod.html

1 Like

Thanks a lot!
That’s quite complicated for me, as your advide I tried command below and figure it out! ( as one line)

TClass.GetClass(‘MyClass’).GetListOfMethods().FindObject(‘MyClass’).GetListOfMethodArgs().GetEntries()
# That’s quite complicated