Check corrupted files with pyroot


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


Hi

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?

Thanks

Alex

import ROOT as root
import sys
import glob


dir=sys.argv[1]
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?

Hi

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:

try:
   your_loop_body_here
except AttributeError:
   print_some_warning_and_continue_looping

Ah, actually that seems to work ! thanks

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