5 This scripts compares different versions of ECL channel maps,
6 both text files and database payloads
9 0-ECL channel maps are identical
10 1-ECL channel maps are different
11 255-wrong script arguments
14 from ROOT
import Belle2, TFile
15 from ROOT.Belle2
import ECLChannelMap
21 ECL_CHANNELS_IN_SHAPER = 16
22 ECL_BARREL_CRATES = 36
31 print(
'Usage: %s file1 file2' % sys.argv[0])
32 print(
' file1 Path to text file or root file with ECL channel map')
33 print(
' file2 Path to text file or root file with ECL channel map')
37 paths = sys.argv[1], sys.argv[2]
39 ch_maps.append(loadFile(paths[0]))
40 ch_maps.append(loadFile(paths[1]))
45 header =
' | crate | shaper | channel | cell_id |'
48 return '| %5d | %6d | %7d | %7d |' % row
50 for partial_ch_maps
in zip(*ch_maps):
51 for row1, row2
in zip(*partial_ch_maps):
57 print(
'file1:', rowToString(row1))
58 print(
'file2:', rowToString(row2))
61 print(
'%s and %s contain identical channel maps.' % paths)
75 if path.endswith(
'.txt'):
76 return loadTextFile(path)
77 elif path.endswith(
'.root'):
78 return loadRootFile(path)
81 print(
'Error: The script only supports *.txt and *.root. Input file: %s' % path)
88 def loadTextFile(path):
93 for line
in f.readlines():
97 items = [int(float(x))
for x
in line.split()]
102 crate, shaper, channel, phi, theta, cell_id = items
104 added_items = (crate, shaper, channel, cell_id)
107 map_bar.append(added_items)
109 map_fwd.append(added_items)
111 map_bwd.append(added_items)
112 return map_bar, map_fwd, map_bwd
117 def loadRootFile(path):
121 root_file = TFile(path,
'read')
122 ecl_ch_map = root_file.Get(
'ECLChannelMap')
125 channel = crate = shaper = 1
131 cell_id = ecl_ch_map.getMappingBAR()[array_index]
132 map_bar.append((crate, shaper, channel, cell_id))
134 cell_id = ecl_ch_map.getMappingFWD()[array_index]
135 map_fwd.append((crate, shaper, channel, cell_id))
137 cell_id = ecl_ch_map.getMappingBWD()[array_index]
138 map_bwd.append((crate, shaper, channel, cell_id))
142 if channel > ECL_CHANNELS_IN_SHAPER:
145 if shaper > max_shapers:
147 if crate == ECL_BARREL_CRATES:
150 elif crate == ECL_BARREL_CRATES + ECL_FWD_CRATES:
155 return map_bar, map_fwd, map_bwd
160 if __name__ ==
'__main__':