Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bindings/pyroot/pythonizations/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ ROOT_ADD_PYUNITTEST(pyroot_pyz_decorator pythonization_decorator.py)

# Miscellaneous small pythonizations grouped in a single file to avoid paying the
# Python-startup + import-ROOT overhead once per tiny test: TClass::DynamicCast,
# TContext context manager, TComplex operators, TIter iteration and TGraph getters.
# TContext context manager, TComplex operators, TIter iteration, TGraph getters
# and TParameter arithmetic instantiations.
ROOT_ADD_PYUNITTEST(pyroot_pyz_misc misc_pyz.py)

# RVec and subclasses pythonizations
Expand Down
57 changes: 57 additions & 0 deletions bindings/pyroot/pythonizations/test/misc_pyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,5 +372,62 @@ def test_graphmultierrors(self):
self.assertEqual(list(eyhigh), list(aeyh))


class TParameterTemplateInstantiations(unittest.TestCase):
"""
Instantiating TParameter<T> for a type without a dictionary (e.g. char)
from the interpreter used to fail with unresolved
TParameter<T>::Class() and TParameter<T>::Streamer(TBuffer&) symbols,
see https://github.com/root-project/root/issues/10724. Check that all
standard arithmetic types can be constructed, printed and serialized
from the interpreter.
"""

# (type name, value passed to the constructor, value expected from GetVal())
# cppyy maps the character types to Python str, so 42 comes back as "*"
instantiations = [
("bool", True, True),
("char", 42, "*"),
("signed char", 42, "*"),
("unsigned char", 42, "*"),
("short", 42, 42),
("unsigned short", 42, 42),
("int", 42, 42),
("unsigned int", 42, 42),
("long", 42, 42),
("unsigned long", 42, 42),
("long long", 42, 42),
("unsigned long long", 42, 42),
("float", 0.5, 0.5),
("double", 0.5, 0.5),
]

def test_construct_and_print(self):
for typename, val, expected in self.instantiations:
with self.subTest(typename=typename):
param = ROOT.TParameter[typename]("p", val)
self.assertEqual(param.GetVal(), expected)
# Print and ls write to std::cout; exercise the code path
# (they used to be uncallable without arguments)
param.Print()
param.ls()

def test_has_dictionary(self):
for typename, _, _ in self.instantiations:
with self.subTest(typename=typename):
tclass = ROOT.TClass.GetClass(f"TParameter<{typename}>")
self.assertIsNotNone(tclass)
self.assertTrue(tclass.HasDictionary())

def test_io_roundtrip(self):
for typename, val, expected in self.instantiations:
with self.subTest(typename=typename):
param = ROOT.TParameter[typename]("p", val)
memfile = ROOT.TMemFile("TParameterTemplateInstantiations.root", "recreate")
memfile.WriteObject(param, "p")
param_read = memfile.Get("p")
self.assertEqual(param_read.GetVal(), expected)
memfile.Close()


if __name__ == '__main__':
unittest.main()
8 changes: 8 additions & 0 deletions core/base/inc/LinkDef3.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,18 @@

#pragma extra_include "Rtypes.h";
#pragma link C++ class TParameter<Bool_t>+;
#pragma link C++ class TParameter<Char_t>+;
#pragma link C++ class TParameter<signed char>+;
#pragma link C++ class TParameter<UChar_t>+;
#pragma link C++ class TParameter<Short_t>+;
#pragma link C++ class TParameter<UShort_t>+;
#pragma link C++ class TParameter<Float_t>+;
#pragma link C++ class TParameter<Double_t>+;
#pragma link C++ class TParameter<Int_t>+;
#pragma link C++ class TParameter<UInt_t>+;
#pragma link C++ class TParameter<Long_t>+;
#pragma link C++ class TParameter<ULong_t>+;
#pragma link C++ class TParameter<Long64_t>+;
#pragma link C++ class TParameter<ULong64_t>+;

#endif
4 changes: 2 additions & 2 deletions core/base/inc/TParameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ class TParameter : public TObject {
return fName.CompareTo(obj->GetName());
}

void ls(Option_t *) const override
void ls(Option_t * = "") const override
{
// Print this parameter content
TROOT::IndentLevel();
std::cout << "OBJ: " << IsA()->GetName() << "\t" << fName << " = " << fVal << std::endl;
}

void Print(Option_t *) const override
void Print(Option_t * = "") const override
{
// Print this parameter content
TROOT::IndentLevel();
Expand Down
Loading