3 from __future__
import print_function
6 from FWCore.PythonUtilities.LumiList
import LumiList
9 if __name__ ==
'__main__':
11 parser = optparse.OptionParser (
"Usage: %prog --command [--options] alpha.json beta.json [output.json]")
13 cmdGroup = optparse.OptionGroup (parser,
"Command Options ")
14 cmdGroup.add_option (
'--and', dest=
'command', action=
'store_const',
16 help =
'"and" (i.e., take intersection) of two files')
17 cmdGroup.add_option (
'--or', dest=
'command', action=
'store_const',
19 help =
'"or" (i.e., take union) of two files')
20 cmdGroup.add_option (
'--sub', dest=
'command', action=
'store_const',
22 help =
'"subtraction" (i.e., lumi sections in alpha not in beta) of two files')
23 cmdGroup.add_option (
'--diff', dest=
'command', action=
'store_const',
25 help =
'"All differences (i.e., alpha - beta AND beta - alpha) of two files. Output will only be to screen (not proper JSON format).')
26 parser.add_option_group (cmdGroup)
27 (options, args) = parser.parse_args()
28 if len (args) < 2
or len (args) > 3:
29 raise RuntimeError(
"Two input filenames with one optional output filename must be provided.")
30 if not options.command:
31 raise RuntimeError(
"Exactly one command option must be specified")
33 alphaList = LumiList (filename = args[0])
34 betaList = LumiList (filename = args[1])
39 if options.command ==
'diff':
41 raise RuntimeError(
"Can not output to file with '--diff' option. The output is not standard JSON.")
42 firstOnly = alphaList - betaList
43 secondOnly = betaList - alphaList
44 if not firstOnly
and not secondOnly:
45 print(
"Files '%s' and '%s' are the same." % (args[0], args[1]))
47 print(
"'%s'-only lumis:" % args[0])
52 print(
"\n'%s'-only lumis:" % args[1])
62 if options.command ==
'and':
63 outputList = alphaList & betaList
65 if options.command ==
'or':
66 outputList = alphaList | betaList
68 if options.command ==
'sub':
69 outputList = alphaList - betaList
72 outputList.writeJSON (args[2])
S & print(S &os, JobReport::InputFile const &f)