Skip to content

Forward slashes in object names break reading #1541

@alexander-held

Description

@alexander-held

I came across a ROOT-produced file containing histograms with names like "SR/Signal/Nominal". Instead of being organized into folders, these objects all sit at the same level. Reading this with uproot fails, presumably because the path is being interpreted as a folder structure. Is there a way to read such objects? I'm using uproot v5.6.8.

import uproot
import ROOT

fname = "test.root"
objname = "a/b/c"

f = ROOT.TFile(fname, "RECREATE")
h = ROOT.TH1D("h", "h", 1, 0, 1)
h.Write(objname)
f.Close()

with uproot.open(fname) as f:
    f[objname]

leads to

Traceback (most recent call last):
  File "[...]/reproducer.py", line 13, in <module>
    f[objname]
    ~^^^^^^^^^
  File "[...]/uproot/reading.py", line 2099, in __getitem__
    step = step[item]
           ~~~~^^^^^^
  File "[...]/uproot/reading.py", line 2122, in __getitem__
    return self.key(where).get()
           ~~~~~~~~^^^^^^^
  File "[...]/uproot/reading.py", line 2064, in key
    raise uproot.KeyInFileError(
        item, cycle="any", keys=self.keys(), file_path=self._file.file_path
    )
uproot.exceptions.KeyInFileError: not found: 'a' (with any cycle number)

    Available keys: 'a/b/c;1'

in file test.root

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug (unverified)The problem described would be a bug, but needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions