Skip to content

Instantly share code, notes, and snippets.

@mmusich mmusich/splitter.py
Created Oct 30, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.