Failed to open root file

I have a program for working with root files. After launching, a window appears in which you can select a file (it and the program itself are located in the same directory). But when you select the desired file, the program gives the following errors:

Error in TFile::TFile: file /home/erg/.root does not exist
Traceback (most recent call last):
File “/home/erg/multiple_ADC_viewer -”, line 1217, in
File “/home/erg/multiple_ADC_viewer -”, line 638, in openimagefilename
File “/home/erg/multiple_ADC_viewer -”, line 84, in readfileinitdata
tempfile = ROOT.TFile.Open(filename)
File “/home/erg/root/lib/ROOT/_pythonization/”, line 67, in _TFileOpen
raise OSError(‘Failed to open file {}’.format(str(args[0])))
OSError: Failed to open file /home/erg/

I have attached the programs that are indicated in the errors
multiple_ADC_viewer - (61.5 KB) (3.1 KB)

_ROOT Version: 6.30/04
_Platform: Ubuntu
_Compiler: pycharm community


Thanks for the post.
Are you sure this is an issue related to ROOT and not an issue of the program that does not correctly passes to the TFile constructor the right string?


As Danilo suggests, the error says that you are trying to open a file called “.root”, so you should check that you are passing the correct string to TFile::Open; looks like you are getting the names with some Tkinter modules, so check there (not a ROOT issue); you can start by printing out the string that you are passing to TFile (i.e. the value of filename being passed to readfileinitdata).

I tried to run it through the paycharm terminal as follows:

python -i ‘/home/erg/multiple_ADC_viewer -’ /home/erg/Oct13071907.root

The following errors popped up:

File “/home/erg/multiple_ADC_viewer -”, line 133, in
File “/home/erg/multiple_ADC_viewer -”, line 87, in readfileinitdata
TypeError: int TTree::GetEvent(Long64_t entry, int getall = 0) =>
TypeError: takes at least 1 arguments (0 given)

You are calling GetEvent() without arguments, but you have to pass at least 1 argument to it, namely the event (entry) number you want to read. And to read from the tree with GetEvent() (or with GetEntry()) you also need to use SetBranchAddress(). In Python, alternatively you can also directly iterate on the tree instance; check out the example on the documentation page (scroll down a bit to the “PyROOT” part).

1 Like

Thank you so much!

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