Pyroot tutorial errors

root ver 6.20.04
python ver 3.8.3
os  Mac OS X 10.15
homebrew version

using tutorials/pyroot/staff.py create staff.root

but if I use code blow to view the string columns

RDataFrame aData("T","staff.root");
aData.Display({"Nation"})->Print();

the out put
Nation |
‘0x00’ |
‘0x00’ |
‘0x00’ |
‘0x00’ |
‘0x00’ |

It seems to be the error of using wrong pointer at conversion from C to python
how do I transport the string in python correctly

I guess @etejedor can help you.

Hi,
If I print the value of the Nation column of T in staff.root everything seems fine:

>>> import ROOT
>>> f = ROOT.TFile.Open("staff.root")
>>> t = f.T
>>> for entry in t: print(t.Nation)
... 
DE
CH
FR
FR
DE
IT
CH
IT
DE
FR
FR
...

@eguiraud do you know why printing the RDisplay could be giving that output? What I get is slightly different than what the user gets:

root [0] ROOT::RDataFrame aData("T","staff.root");
root [1] aData.Display({"Nation"})->Print();
Nation | 
'D'    | 
...    | 
'0x00' | 
'C'    | 
...    | 
'0x00' | 
'F'    | 
...    | 
'0x00' | 
'F'    | 
...    | 
'0x00' | 

Hi,
given the reproducer in the C++ ROOT prompt above, this looks like a bug in Display, I’ll take a look asap and report back when I have something.

Cheers,
Enrico

did you use python3.8.3?

Hi, just wanted to ping, I have not forgotten about this, but the week was full. It’s close to the top of my to-do list.

one of the solutions is that using TString class instead of char arrays in the structure

for example:

gROOT.ProcessLine("struct data{TString a1; TString a2};");
d2=ROOT.data()
tree=TTree("t1","t1")
tree.Branch('data',d2)

but I cannot use TString outside a struct, below generate wrong file

gROOT.ProcessLine("TString a1;");
# d2=ROOT.a1() # wrong
d2=ROOT.a1
tree=TTree("t1","t1")
tree.Branch('data',d2) # wrong

Hi,
I can reproduce the problem with Display and I’m working on a fix (we are treating char* as an actual vector of characters rather than as a string).

In the meantime I would like to unblock you, but I am not sure what you want to accomplish. If you just want to print the contents of the column, the solution by @etejedor above does the trick.

About your last post: the column has type char *, so I am not sure using a TString as branch type is safe.

What are you trying to accomplish exactly?
Cheers,
Enrico

I have a database which could only opening using python, I want to convert it to ROOT file database. Then I could use it in my c++ code. So I think using TString is a better way. But as you mentioned I’m not sure if TString as branch is safe in PyROOT.

Alright, but this is a completely different topic :smiley: Would you mind opening a new thread with a small self-contained reproducer for this new problem?

About the issue with RDF Display and arrays of characters, I opened this ticket, I should have a fix soon (it will be part of the next ROOT release, v6.24, and maybe also v6.22/02).

Cheers,
Enrico

Hi,
just a follow-up, printing arrays of chars with display is now fixed in ROOT master and 6.22 patches, which will be respectively v6.24 (one day) and v6.22/02 (as soon as we have a patch release).

Cheers,
Enrico

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