Loading .C root scripts into PYROOT script

Hi,

I am experiencing some strange behaviour when trying to load a .C root script into PYROOT.

I have 2 scripts,

script1.C

float script1(TString arg1="1", TString arg2="2") { cout << "script1" << endl; cout << arg1 << endl; cout << arg2 << endl; return 7.12; }

and script2.py

from ROOT import * gROOT.ProcessLine('.L script1.C') script1("2", "1")

so the PYROOT script (script2.py) loads the CINT script/function into ROOT and then calls it. When I do this I get the error

[code]= macbook: == python script2.py
Traceback (most recent call last):
File “script2.py”, line 3, in
script1(“2”, “1”)
RuntimeError: (file “script1.C”, line 1) Ambiguous overload resolution (10000,2)
Calling :
TString::
TString(
long
);
Match rank: file line signature
ffffffff
(compiled) 0
TString
TString::
TString(
const TSubString&
);
ffffffff
(compiled) 0
TString
TString::
TString(
char
,
Ssiz_t
);

  • 10000
    (compiled) 0
    TString
    TString::
    TString(
    char
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const string&
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const char*
    ,
    Ssiz_t
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const char*
    );
    1000001
    (compiled) 0
    TString
    TString::
    TString(
    const TString&
    );
  • 10000
    (compiled) 0
    TString
    TString::
    TString(
    Ssiz_t
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const char*
    ,
    Ssiz_t
    ,
    const char*
    ,
    Ssiz_t
    );
    [/code]

Furthermore, if I change the script so that instead of passing TStrings I pass integers, there is no error. Any idea why or how to get around this?

thanks

David Voong

I should also point out that seems only to be a problem with PyROOT. I tried the equivalent scripts in CINT and they worked okay

David,

PyROOT does not support implicit conversions (although a few are programmed in by hand), so the conversion of a python str object to a TString is not made. Haven’t tested it, but calling script1( TString(“1”), TString(“2”) ) should work as expected.

Cheers,
Wim

When I try that it still errors with,

[code]== macbook: == python script2.py
Traceback (most recent call last):
File “script2.py”, line 3, in
script1(TString(“2”), TString(“1”))
RuntimeError: (file “script1.C”, line 1) Ambiguous overload resolution (10000,2)
Calling :
TString::
TString(
long
);
Match rank: file line signature
ffffffff
(compiled) 0
TString
TString::
TString(
const TSubString&
);
ffffffff
(compiled) 0
TString
TString::
TString(
char
,
Ssiz_t
);

  • 10000
    (compiled) 0
    TString
    TString::
    TString(
    char
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const string&
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const char*
    ,
    Ssiz_t
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const char*
    );
    1000001
    (compiled) 0
    TString
    TString::
    TString(
    const TString&
    );
  • 10000
    (compiled) 0
    TString
    TString::
    TString(
    Ssiz_t
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    );
    ffffffff
    (compiled) 0
    TString
    TString::
    TString(
    const char*
    ,
    Ssiz_t
    ,
    const char*
    ,
    Ssiz_t
    );
    [/code]

David,

okay … I tried to run with .L script1.C+ and that works fine (I found that I forgot that I do have a hard-coded converter str -> TString, given that TString is so common).

What does seem to work for me, is to use const TString& arg=“1” etc. in script1.C, both from CINT and PyROOT, both compiled and interpreted.

I’ll see what goes wrong in the by-value case (is a different converter in PyROOT than the by-ref case).

Cheers,
Wim

David,

for the interpreted script, CINT needs to be told that the value it receives is already a TString since it’s checking the value (pointers are being handed around and for the compiled version, no checks are made, which is why it works as-is).

I have a fix, but want to clean it up a bit and write a few new tests. Will check-in on Monday.

Cheers,
Wim

thanks Wim

David,

a fix for the original problem that you posted is in, but it opened a can of worms, so I’m not done yet (in particular, I think there’s some behavior that’s different between compiled and interpreted in how temporaries are handled and I haven’t nailed that yet).

Cheers,
Wim

Hi,

I am experiencing the same kind of problem. Where can I find the solution that Wim say is available?

Cheers,

Tanya

Actually, I just tried Wim’s first recipe: to put “const TString& arg” in the .C argument and in pyROOT use a normal string and this seem to work.

Cheers,

Tanya