Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved file name checking in Chain #38

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion PhysicsTools/HeppyCore/python/framework/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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)
Expand Down