14from ROOT
import pythonization
25ROOT.gInterpreter.Declare(
'''
54@pythonization('MyClass')
55def pythonizor_of_myclass(klass):
56 klass.__str__ =
lambda o :
'This is a MyClass object'
63my_object = ROOT.MyClass()
82ROOT.gInterpreter.Declare(
'''
93@pythonization(['Class1', 'Class2'], ns='NS')
94def pythonize_two_classes(klass):
95 klass.new_attribute = 1
100print(
"Printing new attribute")
102 print(o.new_attribute)
112@pythonization('vector<', ns='std', is_prefix=True)
113def vector_pythonizor(klass):
115 klass.first_elem =
lambda v : v[0]
if v
else None
119v_int = ROOT.std.vector[
'int']([1,2,3])
120v_double = ROOT.std.vector[
'double']([4.,5.,6.])
121print(
"First element of integer vector: {}".format(v_int.first_elem()))
122print(
"First element of double vector: {}".format(v_double.first_elem()))
140@pythonization('pair<', ns='std', is_prefix=True)
141def pair_pythonizor(klass, name):
142 print(
'Pythonizing class ' + name)
148p1 = ROOT.std.pair[
'int',
'int'](1,2)
149p2 = ROOT.std.pair[
'int',
'double'](1,2.)
154ROOT.gInterpreter.Declare(
'''
157 class SecondClass {};
162@pythonization('FirstClass')
163@pythonization('SecondClass', ns='NS')
164def pythonizor_for_first_and_second(klass, name):
165 print(
'Executed for class ' + name)
169s = ROOT.NS.SecondClass()
184ROOT.gInterpreter.Declare(
'''
190except AttributeError:
191 print(
"Object has not been pythonized yet!")
195@pythonization('MyClass2')
196def pythonizor_for_myclass2(klass):
197 klass.pythonized =
True