13 This scripts compares different versions of ECL channel maps,
14 both text files and database payloads
17 0-ECL channel maps are identical
18 1-ECL channel maps are different
19 255-wrong script arguments
22 from ROOT
import TFile
28 ECL_CHANNELS_IN_SHAPER = 16
29 ECL_BARREL_CRATES = 36
38 print(
'Usage: %s file1 file2' % sys.argv[0])
39 print(
' file1 Path to text file or root file with ECL channel map')
40 print(
' file2 Path to text file or root file with ECL channel map')
44 paths = sys.argv[1], sys.argv[2]
46 ch_maps.append(loadFile(paths[0]))
47 ch_maps.append(loadFile(paths[1]))
52 header =
' | crate | shaper | channel | cell_id |'
55 return '| %5d | %6d | %7d | %7d |' % row
57 for partial_ch_maps
in zip(*ch_maps):
58 for row1, row2
in zip(*partial_ch_maps):
64 print(
'file1:', rowToString(row1))
65 print(
'file2:', rowToString(row2))
68 print(
'%s and %s contain identical channel maps.' % paths)
82 if path.endswith(
'.txt'):
83 return loadTextFile(path)
84 elif path.endswith(
'.root'):
85 return loadRootFile(path)
88 print(
'Error: The script only supports *.txt and *.root. Input file: %s' % path)
95 def loadTextFile(path):
100 for line
in f.readlines():
104 items = [int(float(x))
for x
in line.split()]
109 crate, shaper, channel, phi, theta, cell_id = items
111 added_items = (crate, shaper, channel, cell_id)
114 map_bar.append(added_items)
116 map_fwd.append(added_items)
118 map_bwd.append(added_items)
119 return map_bar, map_fwd, map_bwd
124 def loadRootFile(path):
128 root_file = TFile(path,
'read')
129 ecl_ch_map = root_file.Get(
'ECLChannelMap')
132 channel = crate = shaper = 1
138 cell_id = ecl_ch_map.getMappingBAR()[array_index]
139 map_bar.append((crate, shaper, channel, cell_id))
141 cell_id = ecl_ch_map.getMappingFWD()[array_index]
142 map_fwd.append((crate, shaper, channel, cell_id))
144 cell_id = ecl_ch_map.getMappingBWD()[array_index]
145 map_bwd.append((crate, shaper, channel, cell_id))
149 if channel > ECL_CHANNELS_IN_SHAPER:
152 if shaper > max_shapers:
154 if crate == ECL_BARREL_CRATES:
157 elif crate == ECL_BARREL_CRATES + ECL_FWD_CRATES:
162 return map_bar, map_fwd, map_bwd
167 if __name__ ==
'__main__':
int main(int argc, char **argv)
Run all tests.