CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
mergeJSON.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 from __future__ import print_function
4 import sys
5 import optparse
6 import re
7 from FWCore.PythonUtilities.LumiList import LumiList
8 
9 
10 def filterRuns (lumiList, minRun, maxRun):
11  allRuns = lumiList.getRuns()
12  runsToRemove = []
13  for run in allRuns:
14  if minRun and int(run) < minRun:
15  runsToRemove.append (run)
16  if maxRun and int(run) > maxRun:
17  runsToRemove.append (run)
18  lumiList.removeRuns (runsToRemove)
19 
20 
21 
22 if __name__ == '__main__':
23 
24  parser = optparse.OptionParser ("Usage: %prog alpha1.json [alpha2.json:142300-145900]")
25  parser.add_option ('--output', dest='output', type='string',
26  help='Save output to file OUTPUT')
27  # required parameters
28  (options, args) = parser.parse_args()
29  if not len (args):
30  raise RuntimeError("Must provide at least one input file")
31 
32  minMaxRE = re.compile (r'(\S+):(\d+)-(\d*)')
33 
34  finalList = LumiList()
35  for filename in args:
36  minRun = maxRun = 0
37  match = minMaxRE.search (filename)
38  if match:
39  filename = match.group(1)
40  minRun = int( match.group(2) )
41  try:
42  maxRun = int( match.group(3) )
43  except:
44  pass
45  if maxRun and minRun > maxRun:
46  raise RuntimeError("Minimum value (%d) is greater than maximum value (%d) for file '%s'" % (minRun, maxRun, filename))
47  localList = LumiList (filename = filename)
48  filterRuns (localList, minRun, maxRun)
49  finalList = finalList | localList
50 
51  if options.output:
52  finalList.writeJSON (options.output)
53  else:
54  print(finalList)
def filterRuns
Definition: mergeJSON.py:10
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47