Created
October 30, 2018 12:21
-
-
Save mmusich/6a9b4c9f198ada3ea1f52cc9ea4d9b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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