From 68ab533301999be27a7a62ee0c31eeae85136260 Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Sat, 6 Jun 2015 12:35:21 +0300 Subject: [PATCH] improved file name checking in chain --- .../HeppyCore/python/framework/chain.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/HeppyCore/python/framework/chain.py b/PhysicsTools/HeppyCore/python/framework/chain.py index c1c8fd407345d..4185f6c0c1465 100644 --- a/PhysicsTools/HeppyCore/python/framework/chain.py +++ b/PhysicsTools/HeppyCore/python/framework/chain.py @@ -6,6 +6,18 @@ import pprint from ROOT import TChain, TFile, TTree, gSystem +def is_pfn(fn): + return not is_lfn(fn) + +def is_lfn(fn): + return fn.startswith("/store") + +def is_rootfn(fn): + """ + To open files like root://, file:// which os.isfile won't find. + """ + return "://" in fn + class Chain( object ): """Wrapper to TChain, with a python iterable interface. @@ -37,7 +49,10 @@ def __init__(self, input, tree_name=None): if len(self.files)==0: raise ValueError('no matching file name: '+input) else: # case of a list of files - if False in [ os.path.isfile(fnam) for fnam in self.files ]: + if False in [ + ((is_pfn(fnam) and os.path.isfile(fnam)) or + is_lfn(fnam)) or is_rootfn(fnam) + for fnam in self.files]: err = 'at least one input file does not exist\n' err += pprint.pformat(self.files) raise ValueError(err)