From 3c0a55dec0132d9c0c6d24c3f4106a6df101bec3 Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Fri, 4 Jan 2019 16:10:47 +0100 Subject: [PATCH] PyDumper: Add --exclude to sg-dumper. Add option to selectively exclude items from the dump. --- Event/PyDumper/bin/sg-dump.py | 6 ++++++ Event/PyDumper/python/PyComps.py | 14 ++++++++++++-- Event/PyDumper/python/SgDumpLib.py | 6 ++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Event/PyDumper/bin/sg-dump.py b/Event/PyDumper/bin/sg-dump.py index 91f6496b5214..f0736d745b8f 100755 --- a/Event/PyDumper/bin/sg-dump.py +++ b/Event/PyDumper/bin/sg-dump.py @@ -114,6 +114,11 @@ if __name__ == "__main__": default = "any", help = "(optional) input file type (RDO,BS,ESD,AOD,DPD, or ANY)") + _add("--exclude", + dest = "exclude", + default = "", + help = "comma-separated list of glob patterns of keys/types to ignore") + (options, args) = parser.parse_args() input_files = [] @@ -143,6 +148,7 @@ if __name__ == "__main__": dump_jobo=options.dump_jobo, use_recex_links=options.use_recex_links, pyalg_cls=options.pyalg_cls, + exclude=options.exclude, file_type=options.file_type, do_clean_up=options.do_clean_up, athena_opts=options.athena_opts, diff --git a/Event/PyDumper/python/PyComps.py b/Event/PyDumper/python/PyComps.py index c40644506768..3d544ff3864e 100644 --- a/Event/PyDumper/python/PyComps.py +++ b/Event/PyDumper/python/PyComps.py @@ -1,4 +1,4 @@ -# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +# Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration # @file: PyDumper/python/PyComps.py # @purpose: A set of PyAthena components to test reading/writing EDM classes @@ -10,6 +10,7 @@ __version__ = '$Revision: 1.11 $' __author__ = 'Sebastien Binet <binet@cern.ch>' import os +from fnmatch import fnmatch import AthenaCommon.SystemOfUnits as Units import AthenaPython.PyAthena as PyAthena from AthenaPython.PyAthena import StatusCode @@ -225,6 +226,7 @@ class PySgDumper (PyAthena.Alg): ## properties and data members self.items = kw.get('items', '*') + self.exclude = kw.get('exclude', '') self.ofile = kw.get('ofile', '') ## handle to event store @@ -290,8 +292,9 @@ class PySgDumper (PyAthena.Alg): self.ofile.writelines (['%s\n'%('='*40), '==> evt nbr [%s]\n' % self._evt_nbr]) self._evt_nbr += 1 - + if self.items is None: + elist = self.exclude.split(',') proxies = self.sg.proxies() sg = dict() _typename = self.clidsvc.typename @@ -302,6 +305,13 @@ class PySgDumper (PyAthena.Alg): n = str(p.name()) tp = _typename(clid) if n.endswith('Aux.'): continue + excluded = False + for exc in elist: + if fnmatch (n, exc) or (tp and fnmatch(tp, exc)): + excluded = True + break + if excluded: + continue if tp: sg[n] = tp else: diff --git a/Event/PyDumper/python/SgDumpLib.py b/Event/PyDumper/python/SgDumpLib.py index 6d5a90446889..1365d31a5e17 100644 --- a/Event/PyDumper/python/SgDumpLib.py +++ b/Event/PyDumper/python/SgDumpLib.py @@ -114,6 +114,7 @@ def _gen_jobo(dct): from %(pyalg_pkg)s import %(pyalg_cls)s as pyalg job += pyalg('pyalg', ofile='%(ofile-name)s', + exclude='%(exclude)s', OutputLevel=Lvl.INFO) """) % dct else: @@ -211,6 +212,7 @@ def _gen_jobo(dct): from %(pyalg_pkg)s import %(pyalg_cls)s as pyalg job += pyalg('pyalg', ofile='%(ofile-name)s', + exclude='%(exclude)s', OutputLevel=Lvl.INFO) """) % dct @@ -359,6 +361,7 @@ def run_sg_dump(files, output, dump_jobo=False, use_recex_links=True, pyalg_cls='PyDumper.PyComps:PySgDumper', + exclude='', file_type=None, do_clean_up=False, athena_opts=None, @@ -373,6 +376,7 @@ def run_sg_dump(files, output, it) `use_recex_links` switch to run RecExCommon_links and thus a local db replica `pyalg_cls` the fully qualified name of the PyAthena.Alg class to process the file(s) content (PySgDumper or DataProxyLoader) + `exclude`: comma-separated list of glob patterns for keys/types to ignore. `file_type` the input file's type (RDO,BS,ESD,AOD,DPD or ANY) `do_clean_up` flag to enable the attempt at removing all the files sg-dump produces during the course of its execution @@ -426,6 +430,7 @@ def run_sg_dump(files, output, 'input-files': files, 'evts' : nevts, 'skip' : skip, + 'exclude' : exclude, 'pyalg_pkg': pyalg_pkg, 'pyalg_cls': pyalg_cls, 'input-type': file_type.upper(), @@ -439,6 +444,7 @@ def run_sg_dump(files, output, msg.info('use recex links: %s', use_recex_links) msg.info('pyalg-class: %s:%s', pyalg_pkg, pyalg_cls) msg.info('file_type: %s', file_type) + msg.info('exclude: %s', exclude) if dump_jobo and isinstance(dump_jobo, basestring): try: -- GitLab