SetOpenTimeout with TDCacheFile

I am running a simple python script (simplified version is below) which goes through many files and reads two integers from a tree.
Basically there are times when a file is unreachable in dcache, so I would like to set it to timeout rather quickly rather than the whole script hanging for hours(ever?). I see that there is a function SetOpenTimeout but I’m not exactly sure how to use it as the point in the script where it hangs is at file = TDCacheFile("…"), so how do I set the timeout before I even have the file? Besides that, once I have a good file I can print file.GetOpenTimeout() and it gives 999999999, and if I then try file.SetOpenTimeout(2000) I still get 999999999 when I print it out again, so what does SetOpenTimeout actually do?

Well, I think it’s clear I don’t know what I’m doing here. Anyone know how to do this?

Thanks for any help.

#! /usr/bin/env python
import sys
import getopt

from ROOT import TFile, TRFIOFile, TTree, TDCacheFile

tot_events = 0
sel_events = 0

for i in range(1, 100+1):
print “Index :”, i
index = str(i)
file = TDCacheFile(“dcap://dcap-2.BLAH-BLAH-BLAH”+index+".root")
print “timeout default:”, file.GetOpenTimeout() # PRINTS 999999999
print “timeout after:”, file.GetOpenTimeout() # ALSO PRINTS 999999999
tree = file.Get(“global_variables”)
sel_events = sel_events + tree.sel_events
tot_events = tot_events + tree.tot_events
except AttributeError:

print “Total events :”, tot_events
print “Selected events:”, sel_events
if (tot_events != 0):
print “Efficiency :”, float(sel_events)/float(tot_events)
print “Efficiency : 1”


SetOpenTimeout is a static function of both TFile and TDCacheFile but GetOpenTimeout is only present in TFile.

You need to use the one in TDCacheFile explicitly (C++ syntax listed here):

TDCacheFile::SetOpenTimeout(20000); and you should call that before creating the TDacheFile object (the constructor is the function that actually opens the file).