From b4dc251f7719f506f4973a4052c68b2e3dab0176 Mon Sep 17 00:00:00 2001 From: Kevin Pedro Date: Tue, 24 Oct 2023 07:39:40 -0500 Subject: [PATCH] argparse migration for DataFormats/FWLite --- DataFormats/FWLite/python/__init__.py | 2 -- DataFormats/FWLite/scripts/edmLumisInFiles.py | 25 ++++++++----------- DataFormats/FWLite/test/chainEvent_python.py | 1 - 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/DataFormats/FWLite/python/__init__.py b/DataFormats/FWLite/python/__init__.py index 048123ae959db..f09c1a032435d 100644 --- a/DataFormats/FWLite/python/__init__.py +++ b/DataFormats/FWLite/python/__init__.py @@ -1,10 +1,8 @@ #! /usr/bin/env python -from __future__ import print_function import ROOT import inspect import sys -import optparse from FWCore.ParameterSet.VarParsing import VarParsing from builtins import int diff --git a/DataFormats/FWLite/scripts/edmLumisInFiles.py b/DataFormats/FWLite/scripts/edmLumisInFiles.py index 1e537dbadbf66..1d779b41eee53 100755 --- a/DataFormats/FWLite/scripts/edmLumisInFiles.py +++ b/DataFormats/FWLite/scripts/edmLumisInFiles.py @@ -1,24 +1,19 @@ #! /usr/bin/env python3 -from __future__ import print_function -from FWCore.PythonUtilities.LumiList import LumiList -import optparse - +from FWCore.PythonUtilities.LumiList import LumiList +from argparse import ArgumentParser if __name__ == '__main__': - - parser = optparse.OptionParser ("Usage: %prog [--options] edm1.root [edm2.root...]", - description='Runs over input EDM files and prints out a list of contained lumi sections') - parser.add_option ('--intLumi', dest='intLumi', action='store_true', - help='print out total recorded and delivered integrated luminosity') - parser.add_option ('--output', dest='output', type='string', - help='save lumi sections output to file OUTPUT') - (options, args) = parser.parse_args() + parser = ArgumentParser(description='Runs over input EDM files and prints out a list of contained lumi sections') + parser.add_argument('--intLumi', dest='intLumi', action='store_true', + help='print out total recorded and delivered integrated luminosity') + parser.add_argument('--output', dest='output', type=str, + help='save lumi sections output to file OUTPUT') + parser.add_argument("edm", metavar="edm.root", type=str, nargs='+') + options = parser.parse_args() # put this here after parsing the arguments since ROOT likes to # grab command line arguments even when it shouldn't. from DataFormats.FWLite import Lumis, Handle - if not args: - raise RuntimeError("Must provide at least one input file") # do we want to get the luminosity summary? if options.intLumi: @@ -28,7 +23,7 @@ handle, lable = None, None runsLumisDict = {} - lumis = Lumis (args) + lumis = Lumis (options.edm) delivered = recorded = 0 for lum in lumis: runList = runsLumisDict.setdefault (lum.aux().run(), []) diff --git a/DataFormats/FWLite/test/chainEvent_python.py b/DataFormats/FWLite/test/chainEvent_python.py index febb7eb48fc00..81337732ceb33 100644 --- a/DataFormats/FWLite/test/chainEvent_python.py +++ b/DataFormats/FWLite/test/chainEvent_python.py @@ -3,7 +3,6 @@ from __future__ import print_function from builtins import range from DataFormats.FWLite import Events, Handle -import optparse print("starting python test")