CMS 3D CMS Logo

create_idmaps.py
Go to the documentation of this file.
1 import pandas as pd
2 import argparse
3 
4 parser = argparse.ArgumentParser()
5 parser.add_argument("-l","--logicid", help="Logicid mapping", default="params_EBEE_logicid.csv")
6 parser.add_argument("-i","--inputfile", type=str, help="Input file", required=True)
7 parser.add_argument("-o","--outputfile", type=str, help="Output file", required=True)
8 args = parser.parse_args()
9 
10 
11 gmap = pd.read_csv(args.logicid, sep=",")
12 
13 final_map = {}
14 for lid in gmap.stripid:
15  final_map[lid] = 0
16 
17 
18 with open(args.inputfile) as lm:
19  for l in lm.readlines():
20  if l.startswith("#") or len(l)==0 : continue
21  n = l.strip().split(" ")
22  # Now apply the rules
23  if n[0] == "ALL":
24  # set all the strips to the value
25  for k in final_map.keys():
26  final_map[k] = n[1]
27 
28  if n[0] == "SUBDET":
29  if n[1] == "EB":
30  for strip in gmap[(gmap.FED >= 610)&(gmap.FED <=645)].stripid:
31  final_map[strip] = n[2]
32  if n[1] == "EE":
33  for strip in gmap[(gmap.FED < 610)&(gmap.FED >645)].stripid:
34  final_map[strip] = n[2]
35  if n[1] == "EE-":
36  for strip in gmap[gmap.FED < 610].stripid:
37  final_map[strip] = n[2]
38  if n[1] == "EE+":
39  for strip in gmap[gmap.FED > 645].stripid:
40  final_map[strip] = n[2]
41 
42  if n[0] == "FED":
43  # set all the strips with the FED to value
44  for strip in gmap[gmap.FED == int(n[1])].stripid:
45  final_map[strip] = n[2]
46 
47  if n[0] == "TT":
48  # all strips of the same TT(EB) or CCU(EE) for all the FEDs
49  for strip in gmap[gmap.TT == int(n[1])].stripid:
50  final_map[strip] = n[2]
51 
52  if n[0] == "FEDTT":
53  # all strips of the same TT(EB) or CCU(EE) for a specific FEDs
54  for strip in gmap[(gmap.FED == int(n[1])) & (gmap.TT == int(n[2]))].stripid:
55  final_map[strip] = n[3]
56 
57  if n[0] == "STRIP":
58  final_map[int(n[1])] = n[2]
59 
60 # Write the final IDMap file
61 with open(args.outputfile, "w") as of:
62  for k,v in final_map.items():
63  of.write("{} {}\n".format(k,v))
64 
65