SysError in <TFile::Seek>: cannot seek to position -

Version: 5.34.32

Platform: x86_64-slc6-gcc49-opt

I have a script which opens TTrees in a TFile, does some calculations with the values then adds a new branch. My TFiles contain three trees, each within their own TDirectory and I run my script on the three trees separately. The trees are essentially identical except for the names and sizes .

For the first two trees, my script works fine, it adds the branch and the values are correct, I can then open these trees as normal without any issues. For the third tree the script doesn’t work. It appears to run fine and a print out of the value of the new branch within the filling for loop shows sensible values. However, when I try to open the tree in a TBrowser I get the following error:

SysError in TFile::Seek: cannot seek to position -1364721502 in file D2HH_swum_20-29.root, retpos=-1 (Invalid argument)
Error in TFile::ReadBuffer: error reading all requested bytes from file D2HH_swum_20-29.root, got 0 of 1635022195
Error in TKey::ReadFile: Failed to read data.

Why is it looking in a negative position? I have attached the script which adds the branches. The root file containing the three trees is 33G. The problem tree is the second largest of the three.

You help is much appreciated,
AddDOCAZ_minimal.C (7.74 KB)

Dear Kevin,

Modifying an existing TTree is something only partially supported. Your case, adding a new branch and filling only the new branch, should be supported but you need to make sure that the number of entries is exactly the same as for the other branches.
In your loop filling the new branches you have ‘break’ and ‘continue’ statements which could break the condition.
This may explain your problem. You can try to always fill the branches and see it the problem persists.

G Ganis

Hi ganis

The ‘break’ and ‘continue’ are nested, so the branches must be filled in each loop. I also added a counter to make sure. The number of times the branches are filled is the same as the number of entries in the tree.

Is there something I can do to check the tree before I run my script? It runs fine on smaller trees in test files, it just stops working when I scale up.

Dear Kevin,

Sorry, I was too quick and, also because of the missing indentation, I have overlooked the nested loops.

It would certainly help if you could send a reduced version of the output file to analyse the content and see what could be wrong. Or to send the simplest possible example to reproduce the problem.

I guess you tried to open the resulting file in a shell just with TFile, right? Do you get errors or warnings?

Also, how much do you plan to grow your file in size? Given that your file is already quite large, perhaps you could consider to add the new branches as TTree friends stored in separate files.

G Ganis


I think the problem was that the file was corrupted. The problem may have occured when I hadded smaller files together to created the very large files.

The solution for me was to go back and remove branches from my ntuples that I didn’t need and process the smaller individual files. Then after processing, I hadded them together. I also kept the three trees in separate TFiles.


Dear Kevin,

Glad to read that you have found a solution.
I’ll mark the thread as solved.
Please reopen if there are other problems or you need any additional help.

G Ganis