From 31f4f02685aae9c9f69f9a1d61ef2ee8bad8fcdb Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Sat, 13 Jun 2015 19:30:29 +0300 Subject: [PATCH 1/4] 744 --- .../HeppyCore/python/framework/chain.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/PhysicsTools/HeppyCore/python/framework/chain.py b/PhysicsTools/HeppyCore/python/framework/chain.py index 5474b42e758a0..c0ddf571b9872 100644 --- a/PhysicsTools/HeppyCore/python/framework/chain.py +++ b/PhysicsTools/HeppyCore/python/framework/chain.py @@ -6,6 +6,19 @@ 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 +50,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) From 30f730f736a9d60ab770a5457161b2029801726a Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Sat, 13 Jun 2015 22:16:29 +0300 Subject: [PATCH 2/4] fixed pfn check --- PhysicsTools/HeppyCore/python/framework/chain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/HeppyCore/python/framework/chain.py b/PhysicsTools/HeppyCore/python/framework/chain.py index c0ddf571b9872..43117bbcba2c2 100644 --- a/PhysicsTools/HeppyCore/python/framework/chain.py +++ b/PhysicsTools/HeppyCore/python/framework/chain.py @@ -7,7 +7,7 @@ from ROOT import TChain, TFile, TTree, gSystem def is_pfn(fn): - return not is_lfn(fn) + return not (is_lfn(fn) or is_rootfn(fn)) def is_lfn(fn): return fn.startswith("/store") From 0b7515cbd1f4851d0db96d6ebc3bd79ca47e127e Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Sat, 13 Jun 2015 23:08:34 +0300 Subject: [PATCH 3/4] added test for loading lfn/rootfn --- PhysicsTools/HeppyCore/python/framework/chain_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PhysicsTools/HeppyCore/python/framework/chain_test.py b/PhysicsTools/HeppyCore/python/framework/chain_test.py index e124488d18bda..2f53a03be2c0f 100644 --- a/PhysicsTools/HeppyCore/python/framework/chain_test.py +++ b/PhysicsTools/HeppyCore/python/framework/chain_test.py @@ -35,6 +35,11 @@ def test_load_2(self): chain = Chain(testfname.replace('.root', '*.root'), 'test_tree') self.assertEqual(len(chain), 200) os.remove(tmpfile) + + def test_load_3(self): + '''Test chaining of two files.''' + chain = Chain(["root://{0}".format(os.path.abspath(testfname))], 'test_tree') + self.assertEqual(len(chain), 100) def test_iterate(self): '''Test iteration''' From e27e97f30b6db671ef9ed781b52678cdee6dc1f4 Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Sat, 13 Jun 2015 23:09:59 +0300 Subject: [PATCH 4/4] rename --- PhysicsTools/HeppyCore/python/framework/chain_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhysicsTools/HeppyCore/python/framework/chain_test.py b/PhysicsTools/HeppyCore/python/framework/chain_test.py index 2f53a03be2c0f..ccc308f229fea 100644 --- a/PhysicsTools/HeppyCore/python/framework/chain_test.py +++ b/PhysicsTools/HeppyCore/python/framework/chain_test.py @@ -37,7 +37,7 @@ def test_load_2(self): os.remove(tmpfile) def test_load_3(self): - '''Test chaining of two files.''' + '''Test LFN/root-fn loading''' chain = Chain(["root://{0}".format(os.path.abspath(testfname))], 'test_tree') self.assertEqual(len(chain), 100)