TParameters in PyROOT

I am trying to pass inputs to a TSelector from a PyROOT script via the TSelector.SetInputList method. However, I am encountering some weird issues that I don’t understand. Here is an iPython version of how I stumbled upon the issue:

Python 2.7.10 (default, Aug 17 2018, 19:45:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import *
>>> inputs = TList()
>>> useLumiParam = TParameter<bool>("blah", False)
>>> inputs.Add(useLumiParam)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: none of the 2 overloaded methods succeeded. Full details:
  void TList::Add(TObject* obj) =>
    could not convert argument 1
  void TList::Add(TObject* obj, const char* opt) =>
    takes at least 2 arguments (1 given)

It seems the TParameter is not being understood by the interpreter as a TObject (which of course TParameter does actually inherit from). Some other weird things:

>>> type(TParameter<bool>("blah", False))
<type 'bool'>

and even more strange:

Python 2.7.10 (default, Aug 17 2018, 19:45:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import *
>>> intParam = TParameter<int>("test", 3)
>>> type(intParam)
<type 'bool'>
>>> intParam.IsA()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bool' object has no attribute 'IsA'

Is this a bug, or am I making a mistake with my attempts at using TParameter?

Here is my ROOT version:

6.14/06

Well, I just figured it out on my own. The correct way to make a TParameter in PyROOT is like this:

>>> useLumiParam = TParameter(bool)("test", False)
>>> useLumiParam.IsA()
<ROOT.TClass object ("TParameter<bool>") at 0x7fd3b1c2b880>

Sorry for the spam!

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