Get() on lxplus

after writing a script with pyroot that runs as intended on my local machine, I have problems running it on lxplus. I essentially want to draw all histograms in a given directory inside a file. To get the names of the histograms inside the given path I use and then accessing these histograms I do:

for key in file.Get(path).GetListOfKeys():
        complete_path = path+"/"+key.GetName()
        hist = file.Get(complete_path)

As I said, this works on my local machine, but on lxplus the first usage of Get() results in an error: AttributeError: 'TObject' object has no attribute 'GetListOfKeys'. I can prevent that by using GetDirectory() instead of Get(), however than the second usage of Get() only gives me a null pointer for hist. The histogram I am trying to access exists, so I am not sure why I get a null pointer.
I am thankful for any advice. Below you find the information of the used root versions as shown on the opening message.

On lxplus:
ROOT 6.24/06
Built for linuxx8664gcc on Sep 02 2021, 14:20:23
From tags/v6-24-06@v6-24-06
With c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)

ROOT 6.24/06
Built for linuxx8664gcc on Sep 03 2021, 23:37:00
From tag , 1 September 2021


I believe the error you get means that file.Get(path) is not a valid path in the file. Can you double check the path with which the file is created is correct and that the path you want to get in the file is also correct?


Hello Enric,

using for key in file.GetDirectory(path).GetListOfKeys(): I can extract the correct names of the histograms I want to get, so my script seems to be able to see these. I also double checked manually using a TBrowser that the path/histograms exist. What is weird to me is, that the script runs fine on my local machine. I only get this strange behaviour when I copy all the files on lxplus and run the script.


When you are on lxplus, can you run:

file = ROOT.TFile(...)
d = file.GetDirectory(path)

What does it print?

With path = "TrigTauRecMerged_TauCaloOnlyMVA" it prints:
Name: TrigTauRecMerged_TauCaloOnlyMVA Title: TrigTauRecMerged_TauCaloOnlyMVA
So the path is valid, right?

It seems ok, then after print(d), can you run print(d.GetListOfKeys())?

A THashList gets printed:

{ @0x7fffdefa7950, @0x7fffdefa7940, … }

It is of length 35, the number of histograms in this path. It continues with the repetition of the second hash 0x7fffdefa7940. Since I can’t “@” more than two people in a post I was not able to include the whole output. But again, it is just a repetition of the second hash.

Thank you for your ideas and your time @etejedor. While my local machine uses python 3.9.10, lxplus uses 2.7.5. The variable complete_path I showed in my original post is of type string on my local machine, but of type unicode on lxplus. This seemed to be the problem. So after conversion to string: complete_path = str(path+"/"+key.GetName()) my script finally runs on lxplus as well.