12This scripts compares different versions of ECL channel maps,
13both text files and database payloads
16 0-ECL channel maps are identical
17 1-ECL channel maps are different
18 255-wrong script arguments
27ECL_CHANNELS_IN_SHAPER = 16
37 print(f
'Usage: {sys.argv[0]} file1 file2')
38 print(
' file1 Path to text file or root file with ECL channel map')
39 print(
' file2 Path to text file or root file with ECL channel map')
43 paths = sys.argv[1], sys.argv[2]
45 ch_maps.append(loadFile(paths[0]))
46 ch_maps.append(loadFile(paths[1]))
51 header =
' | crate | shaper | channel | cell_id |'
54 return '| %5d | %6d | %7d | %7d |' % row
56 for partial_ch_maps
in zip(*ch_maps):
57 for row1, row2
in zip(*partial_ch_maps):
63 print(
'file1:', rowToString(row1))
64 print(
'file2:', rowToString(row2))
67 print(
'%s and %s contain identical channel maps.' % paths)
81 if path.endswith(
'.txt'):
82 return loadTextFile(path)
83 elif path.endswith(
'.root'):
84 return loadRootFile(path)
87 print(f
'Error: The script only supports *.txt and *.root. Input file: {path}')
94def loadTextFile(path):
99 for line
in f.readlines():
103 items = [int(float(x))
for x
in line.split()]
108 crate, shaper, channel, phi, theta, cell_id = items
110 added_items = (crate, shaper, channel, cell_id)
113 map_bar.append(added_items)
115 map_fwd.append(added_items)
117 map_bwd.append(added_items)
118 return map_bar, map_fwd, map_bwd
123def loadRootFile(path):
127 root_file = TFile(path,
'read')
128 ecl_ch_map = root_file.Get(
'ECLChannelMap')
131 channel = crate = shaper = 1
137 cell_id = ecl_ch_map.getMappingBAR()[array_index]
138 map_bar.append((crate, shaper, channel, cell_id))
140 cell_id = ecl_ch_map.getMappingFWD()[array_index]
141 map_fwd.append((crate, shaper, channel, cell_id))
143 cell_id = ecl_ch_map.getMappingBWD()[array_index]
144 map_bwd.append((crate, shaper, channel, cell_id))
148 if channel > ECL_CHANNELS_IN_SHAPER:
151 if shaper > max_shapers:
153 if crate == ECL_BARREL_CRATES:
156 elif crate == ECL_BARREL_CRATES + ECL_FWD_CRATES:
161 return map_bar, map_fwd, map_bwd
166if __name__ ==
'__main__':