File indexing completed on 2024-04-06 12:13:01
0001
0002
0003 import sys
0004 from argparse import ArgumentParser
0005 from FWCore.PythonUtilities.LumiList import LumiList
0006
0007
0008 if __name__ == '__main__':
0009
0010 parser = ArgumentParser()
0011
0012 cmdGroupTitle = parser.add_argument_group("Command Options")
0013 cmdGroup = cmdGroupTitle.add_mutually_exclusive_group(required=True)
0014 cmdGroup.add_argument('--and', dest='command', action='store_const',
0015 const='and',
0016 help = '"and" (i.e., take intersection) of two files')
0017 cmdGroup.add_argument('--or', dest='command', action='store_const',
0018 const='or',
0019 help = '"or" (i.e., take union) of two files')
0020 cmdGroup.add_argument('--sub', dest='command', action='store_const',
0021 const='sub',
0022 help = '"subtraction" (i.e., lumi sections in alpha not in beta) of two files')
0023 cmdGroup.add_argument('--diff', dest='command', action='store_const',
0024 const='diff',
0025 help = '"All differences" (i.e., alpha - beta AND beta - alpha) of two files. Output will only be to screen (not proper JSON format).')
0026 parser.add_argument("alpha", metavar="alpha.json", type=str)
0027 parser.add_argument("beta", metavar="beta.json", type=str)
0028 parser.add_argument("output", metavar="output.json", type=str, nargs='?', default=None)
0029 options = parser.parse_args()
0030 if not options.command:
0031 parser.error("Exactly one command option must be specified")
0032
0033 alphaList = LumiList (filename = options.alpha)
0034 betaList = LumiList (filename = options.beta)
0035
0036
0037
0038
0039 if options.command == 'diff':
0040 if options.output is not None:
0041 raise RuntimeError("Can not output to file with '--diff' option. The output is not standard JSON.")
0042 firstOnly = alphaList - betaList
0043 secondOnly = betaList - alphaList
0044 if not firstOnly and not secondOnly:
0045 print("Files '%s' and '%s' are the same." % (options.alpha, options.beta))
0046 sys.exit()
0047 print("'%s'-only lumis:" % options.alpha)
0048 if firstOnly:
0049 print(firstOnly)
0050 else:
0051 print("None")
0052 print("\n'%s'-only lumis:" % options.beta)
0053 if secondOnly:
0054 print(secondOnly)
0055 else:
0056 print("None")
0057 sys.exit()
0058
0059
0060
0061
0062 if options.command == 'and':
0063 outputList = alphaList & betaList
0064
0065 if options.command == 'or':
0066 outputList = alphaList | betaList
0067
0068 if options.command == 'sub':
0069 outputList = alphaList - betaList
0070
0071 if options.output is not None:
0072 outputList.writeJSON(options.output)
0073 else:
0074
0075 print(outputList)
0076