4 from argparse
import ArgumentParser
5 from FWCore.PythonUtilities.LumiList
import LumiList
8 if __name__ ==
'__main__':
10 parser = ArgumentParser()
12 cmdGroupTitle = parser.add_argument_group(
"Command Options")
13 cmdGroup = cmdGroupTitle.add_mutually_exclusive_group(required=
True)
14 cmdGroup.add_argument(
'--and', dest=
'command', action=
'store_const',
16 help =
'"and" (i.e., take intersection) of two files')
17 cmdGroup.add_argument(
'--or', dest=
'command', action=
'store_const',
19 help =
'"or" (i.e., take union) of two files')
20 cmdGroup.add_argument(
'--sub', dest=
'command', action=
'store_const',
22 help =
'"subtraction" (i.e., lumi sections in alpha not in beta) of two files')
23 cmdGroup.add_argument(
'--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_argument(
"alpha", metavar=
"alpha.json", type=str)
27 parser.add_argument(
"beta", metavar=
"beta.json", type=str)
28 parser.add_argument(
"output", metavar=
"output.json", type=str, nargs=
'?', default=
None)
29 options = parser.parse_args()
30 if not options.command:
31 parser.error(
"Exactly one command option must be specified")
33 alphaList = LumiList (filename = options.alpha)
34 betaList = LumiList (filename = options.beta)
39 if options.command ==
'diff':
40 if options.output
is not None:
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." % (options.alpha, options.beta))
47 print(
"'%s'-only lumis:" % options.alpha)
52 print(
"\n'%s'-only lumis:" % options.beta)
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
71 if options.output
is not None:
72 outputList.writeJSON(options.output)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)