Check corrupted files with pyroot

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


I wrote a small script to check recursively if any of the existing .root files in a given dir is corrupted, basically just printing the entries on screen. However, the script exits on the very first corrupted file. How it would be possible to continue looping for the rest of the files as well?



import ROOT as root
import sys
import glob

txtfiles = []
for file in glob.glob(dir+"/*.root"):

    f = root.TFile(file)
    myTree = f.Get("AC1B")
    print 'the filename is ',file, myTree.GetEntries()

Hi Alex,

What is exactly the exception/error that you are getting as a result of hitting the first corrupted file?

Would it be possible for you to encapsulate the body of your loop in a try ... catch block to keep going if there is an exception?


give that it tries to get the entries from a corrupted file, I get a message like

AttributeError: ‘TObject’ object has no attribute ‘GetEntries’

Even trying something like

if not f.IsZombie() :
        myTree = f.Get("AC1B")
        print 'the filename is ',file, myTree.GetEntries()

still crashes on the first corrupted file

You can then do:

except AttributeError:

Ah, actually that seems to work ! thanks

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