Skip to content

Instantly share code, notes, and snippets.

@mmusich
Created October 30, 2018 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmusich/6a9b4c9f198ada3ea1f52cc9ea4d9b9a to your computer and use it in GitHub Desktop.
Save mmusich/6a9b4c9f198ada3ea1f52cc9ea4d9b9a to your computer and use it in GitHub Desktop.
from collections import defaultdict
f = open('input_list2.txt')
line = f.readline()
APVs=[]
while line:
line = f.readline()
if not line.startswith("FED"):
APVs.append(line.rstrip('\n'))
f.close()
addresses=[]
for APV in APVs:
address=APV.replace("DetId","").replace("APV","").split("_")
addresses.append(address)
addresses.pop()
d = defaultdict(list)
DetIds=[]
for entry in addresses:
#print entry[0],entry[1]
the_det = entry[0]
d[the_det].append(entry[1])
if the_det not in DetIds:
DetIds.append(the_det)
template = """
cms.PSet(
DetId = cms.uint32({}),
APVs = cms.vuint32({}),
),"""
for k,value in d.iteritems():
s=''
for apv in value:
s += apv+","
print template.format(k,s.rstrip(","))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment