CMS 3D CMS Logo

mergeJSON.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 import sys
4 from argparse import ArgumentParser
5 import re
6 from FWCore.PythonUtilities.LumiList import LumiList
7 
8 def filterRuns (lumiList, minRun, maxRun):
9  allRuns = lumiList.getRuns()
10  runsToRemove = []
11  for run in allRuns:
12  if minRun and int(run) < minRun:
13  runsToRemove.append (run)
14  if maxRun and int(run) > maxRun:
15  runsToRemove.append (run)
16  lumiList.removeRuns (runsToRemove)
17 
18 if __name__ == '__main__':
19 
20  parser = ArgumentParser()
21  parser.add_argument('--output', dest='output', type=str,
22  help='Save output to file OUTPUT')
23  parser.add_argument("alpha_json", metavar="alpha.json[:142300-145900]", type=str, nargs='+')
24  # required parameters
25  options = parser.parse_args()
26 
27  minMaxRE = re.compile (r'(\S+):(\d+)-(\d*)')
28 
29  finalList = LumiList()
30  for filename in options.alpha_json:
31  minRun = maxRun = 0
32  match = minMaxRE.search (filename)
33  if match:
34  filename = match.group(1)
35  minRun = int( match.group(2) )
36  try:
37  maxRun = int( match.group(3) )
38  except:
39  pass
40  if maxRun and minRun > maxRun:
41  raise RuntimeError("Minimum value (%d) is greater than maximum value (%d) for file '%s'" % (minRun, maxRun, filename))
42  localList = LumiList (filename = filename)
43  filterRuns (localList, minRun, maxRun)
44  finalList = finalList | localList
45 
46  if options.output:
47  finalList.writeJSON (options.output)
48  else:
49  print(finalList)
def filterRuns(lumiList, minRun, maxRun)
Definition: mergeJSON.py:8
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47