test
CMS 3D CMS Logo

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