Slash in keyname

71 views Asked by At

This might be a stupid question but unfortunately I have root files which contain keys with names such as "DQMInfo/runno". This is the the actual name. Because it represents a 2d histogram someone thought that it would be a good idea to indicate that with a slash.

Unfortunately, uproot thinks that this is part of a path so it is not able to access this key.

import uproot
f = uproot.open("myfile.root")
f['DQMInfo/runno']

gives the KeyInFileError: not found: 'DQMInfo' (with any cycle number) Available keys: 'DQMInfo/runno;1'

I tried to give it bytes instead of strings but I guess I made an error on the way since I never worked with bytes before...

keyname = 'DQMInfo/runno'
bytename= bytes(keyname,'utf-8')
f[bytename] 

gives the error TypeError: a bytes-like object is required, not 'str'

but print(type(bytename)) gives <class 'bytes'>?

I assume this would be the easiest work around. Another idea was to rename the keys but for this I somehow have to iterate through the keys without calling them by name and then rename them (which I also don't know how to do it) and if it is possible to call them without their name then I don't need the name in the first place.

So, is there a way to give uproot a keyname containing a '/' or do I have to some other solution to this?

0

There are 0 answers