Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:23:25

0001 #!/usr/bin/env python
0002 
0003 import os
0004 
0005 in_path = 'L1Trigger/L1TMuonEndCap/test/tools/pc_luts/firmware_data/'
0006 # in_path = 'L1Trigger/L1TMuonEndCap/test/tools/pc_luts/firmware_MC/'
0007 
0008 def main():
0009   full_path = os.environ['CMSSW_BASE'] + '/src/' + in_path + '%s'
0010   out_dir   = os.environ['CMSSW_BASE'] + '/src/' + in_path.replace('firmware', 'emulator')
0011 
0012   if not os.path.exists(out_dir):
0013     os.makedirs(out_dir)
0014 
0015   all_files = []
0016 
0017   ph_init_array = []
0018   ph_disp_array = []
0019   th_init_array = []
0020   th_disp_array = []
0021   th_lut_array = []
0022   th_corr_lut_array = []
0023 
0024   # ____________________________________________________________________________
0025   def read_file_into_array(fn, arr, resize=0):
0026     old_size = len(arr)
0027     with open(fn) as f:
0028       for line in f:
0029         for s in line.split():
0030           x = int(s, 16)
0031           arr.append(x)
0032 
0033     new_size = len(arr)
0034     if resize:
0035       for i in xrange(new_size-old_size, resize):
0036         arr.append(0)
0037     return
0038 
0039   def dump_array_into_file(arr, fn):
0040     with open(fn, 'w') as f:
0041       s = ""
0042       for i in xrange(len(arr)):
0043         x = arr[i]
0044         s += ("%i " % x)
0045         if (i+1)%30 == 0:
0046           s += "\n"
0047       f.write(s)
0048 
0049   # ____________________________________________________________________________
0050   for endcap in [1,2]:
0051     for sector in [1,2,3,4,5,6]:
0052 
0053       # ph_init
0054       for st in [0,1,2,3,4]:
0055         ph_init_filename = 'ph_init_full_endcap_%i_sect_%i_st_%i.lut' % (endcap, sector, st)
0056         read_file_into_array((full_path % ph_init_filename), ph_init_array)
0057         all_files.append(ph_init_filename)
0058 
0059       # ph_disp
0060       ph_disp_filename = 'ph_disp_endcap_%i_sect_%i.lut' % (endcap, sector)
0061       read_file_into_array((full_path % ph_disp_filename), ph_disp_array)
0062       all_files.append(ph_disp_filename)
0063 
0064       # th_init
0065       th_init_filename = 'th_init_endcap_%i_sect_%i.lut' % (endcap, sector)
0066       read_file_into_array((full_path % th_init_filename), th_init_array)
0067       all_files.append(th_init_filename)
0068 
0069       # th_disp
0070       th_disp_filename = 'th_disp_endcap_%i_sect_%i.lut' % (endcap, sector)
0071       read_file_into_array((full_path % th_disp_filename), th_disp_array)
0072       all_files.append(th_disp_filename)
0073 
0074       # th_lut
0075       for sub in [1]:
0076         for st in [1]:
0077           for ch in [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]:
0078             th_lut_filename = 'vl_th_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0079             read_file_into_array((full_path % th_lut_filename), th_lut_array, resize=128)
0080             all_files.append(th_lut_filename)
0081 
0082       for sub in [2]:
0083         for st in [1]:
0084           for ch in [1,2,3,4,5,6,7,8,9,10,11,12]:
0085             th_lut_filename = 'vl_th_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0086             read_file_into_array((full_path % th_lut_filename), th_lut_array, resize=128)
0087             all_files.append(th_lut_filename)
0088 
0089       for st in [2,3,4]:
0090         for ch in [1,2,3,4,5,6,7,8,9,10,11]:
0091           th_lut_filename = 'vl_th_lut_endcap_%i_sec_%i_st_%i_ch_%i.lut' % (endcap, sector, st, ch)
0092           read_file_into_array((full_path % th_lut_filename), th_lut_array, resize=128)
0093           all_files.append(th_lut_filename)
0094 
0095       # th_corr_lut
0096       for sub in [1]:
0097         for st in [1]:
0098           for ch in [1,2,3,13]:
0099             th_corr_lut_filename = 'vl_th_corr_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0100             read_file_into_array((full_path % th_corr_lut_filename), th_corr_lut_array, resize=128)
0101             all_files.append(th_corr_lut_filename)
0102 
0103       for sub in [2]:
0104         for st in [1]:
0105           for ch in [1,2,3]:
0106             th_corr_lut_filename = 'vl_th_corr_lut_endcap_%i_sec_%i_sub_%i_st_%i_ch_%i.lut' % (endcap, sector, sub, st, ch)
0107             read_file_into_array((full_path % th_corr_lut_filename), th_corr_lut_array, resize=128)
0108             all_files.append(th_corr_lut_filename)
0109 
0110       pass  # end loop over sector
0111     pass  # end loop over endcap
0112 
0113   # ____________________________________________________________________________
0114   assert(len(all_files) == 12*76)
0115   assert(len(ph_init_array) == 12*61)
0116   assert(len(ph_disp_array) == 12*61)
0117   assert(len(th_init_array) == 12*61)
0118   assert(len(th_disp_array) == 12*61)
0119   assert(len(th_lut_array) == 12*61*128)
0120   assert(len(th_corr_lut_array) == 12*7*128)
0121 
0122   dump_array_into_file(ph_init_array, out_dir+"ph_init_neighbor.txt")
0123   dump_array_into_file(ph_disp_array, out_dir+"ph_disp_neighbor.txt")
0124   dump_array_into_file(th_init_array, out_dir+"th_init_neighbor.txt")
0125   dump_array_into_file(th_disp_array, out_dir+"th_disp_neighbor.txt")
0126   dump_array_into_file(th_lut_array, out_dir+"th_lut_neighbor.txt")
0127   dump_array_into_file(th_corr_lut_array, out_dir+"th_corr_lut_neighbor.txt")
0128 
0129   return
0130 
0131 
0132 # ______________________________________________________________________________
0133 if __name__ == '__main__':
0134 
0135   main()