5 from FWCore.PythonUtilities.LumiList
import LumiList
8 if __name__ ==
'__main__':
10 parser = optparse.OptionParser (
"Usage: %prog --command [--options] alpha.json beta.json [output.json]")
12 cmdGroup = optparse.OptionGroup (parser,
"Command Options ")
13 cmdGroup.add_option (
'--and', dest=
'command', action=
'store_const',
15 help =
'"and" (i.e., take intersection) of two files')
16 cmdGroup.add_option (
'--or', dest=
'command', action=
'store_const',
18 help =
'"or" (i.e., take union) of two files')
19 cmdGroup.add_option (
'--sub', dest=
'command', action=
'store_const',
21 help =
'"subtraction" (i.e., lumi sections in alpha not in beta) of two files')
22 cmdGroup.add_option (
'--diff', dest=
'command', action=
'store_const',
24 help =
'"All differences (i.e., alpha - beta AND beta - alpha) of two files. Output will only be to screen (not proper JSON format).')
25 parser.add_option_group (cmdGroup)
26 (options, args) = parser.parse_args()
27 if len (args) < 2
or len (args) > 3:
28 raise RuntimeError(
"Two input filenames with one optional output filename must be provided.")
29 if not options.command:
30 raise RuntimeError(
"Exactly one command option must be specified")
32 alphaList = LumiList (filename = args[0])
33 betaList = LumiList (filename = args[1])
38 if options.command ==
'diff':
40 raise RuntimeError(
"Can not output to file with '--diff' option. The output is not standard JSON.")
41 firstOnly = alphaList - betaList
42 secondOnly = betaList - alphaList
43 if not firstOnly
and not secondOnly:
44 print "Files '%s' and '%s' are the same." % (args[0], args[1])
46 print "'%s'-only lumis:" % args[0]
51 print "\n'%s'-only lumis:" % args[1]
61 if options.command ==
'and':
62 outputList = alphaList & betaList
64 if options.command ==
'or':
65 outputList = alphaList | betaList
67 if options.command ==
'sub':
68 outputList = alphaList - betaList
71 outputList.writeJSON (args[2])