def select_module(self, module_id):
if not isinstance(module_id, str) and isinstance(module_id, Iterable) and set(module_id) - set(self._modules):<EOL><INDENT>raise ValueError('<STR_LIT>' % "<STR_LIT:U+002CU+0020>".join(set(module_id) - set(self._modules)))<EOL><DEDENT>if isinstance(module_id, str) and module_id not in self._module_cfgs:<EOL><INDENT>raise ValueError('<STR_LIT>' % module_id)<EOL><DEDENT>if self._current_module_handle is not None:<EOL><INDENT>raise RuntimeError('<STR_LIT>' % module_id)<EOL><DEDENT>if module_id is None:<EOL><INDENT>self._selected_modules = list(self._modules.keys())<EOL><DEDENT>elif not isinstance(module_id, str) and isinstance(module_id, Iterable):<EOL><INDENT>self._selected_modules = module_id<EOL><DEDENT>elif module_id in self._modules:<EOL><INDENT>self._selected_modules = [module_id]<EOL><DEDENT>elif module_id in self._tx_module_groups:<EOL><INDENT>self._selected_modules = self._tx_module_groups[module_id]<EOL><DEDENT>else:<EOL><INDENT>RuntimeError('<STR_LIT>' % self.current_module_handle)<EOL><DEDENT>self._selected_fifos = list(set([module_cfg['<STR_LIT>'] for (name, module_cfg) in list(self._module_cfgs.items()) if name in self._selected_modules]))<EOL>self._readout_fifos = []<EOL>self._filter = []<EOL>self._converter = []<EOL>for selected_module_id in self._selected_modules:<EOL><INDENT>module_cfg = self._module_cfgs[selected_module_id]<EOL>self._readout_fifos.append(module_cfg['<STR_LIT>'])<EOL>if '<STR_LIT>' not in module_cfg:<EOL><INDENT>tdc_filter = false<EOL>self._converter.append(None)<EOL><DEDENT>elif module_cfg['<STR_LIT>'] is None:<EOL><INDENT>tdc_filter = is_tdc_word<EOL>self._converter.append(convert_tdc_to_channel(channel=module_cfg['<STR_LIT>']))  <EOL><DEDENT>else:<EOL><INDENT>tdc_filter = logical_and(is_tdc_word, is_tdc_from_channel(module_cfg['<STR_LIT>']))<EOL>self._converter.append(convert_tdc_to_channel(channel=module_cfg['<STR_LIT>']))  <EOL><DEDENT>if '<STR_LIT>' not in module_cfg:<EOL><INDENT>self._filter.append(logical_or(is_trigger_word, tdc_filter))<EOL><DEDENT>elif module_cfg['<STR_LIT>'] is None:<EOL><INDENT>self._filter.append(logical_or(is_trigger_word, logical_or(tdc_filter, is_fe_word)))<EOL><DEDENT>else:<EOL><INDENT>self._filter.append(logical_or(is_trigger_word, logical_or(tdc_filter, logical_and(is_fe_word, is_data_from_channel(module_cfg['<STR_LIT>'])))))<EOL><DEDENT><DEDENT>self._enabled_fe_channels = list(set([config['<STR_LIT>'] for (name, config) in list(self._module_cfgs.items()) if name in self._selected_modules]))<EOL>tx_channels = list(set([<NUM_LIT:1> << config['<STR_LIT>'] for (name, config) in list(self._module_cfgs.items()) if name in self._selected_modules]))<EOL>if tx_channels:<EOL><INDENT>self.dut['<STR_LIT>']['<STR_LIT>'] = reduce(lambda x, y: x | y, tx_channels)<EOL><DEDENT>else:<EOL><INDENT>self.dut['<STR_LIT>']['<STR_LIT>'] = <NUM_LIT:0><EOL><DEDENT>if not isinstance(module_id, str) and isinstance(module_id, Iterable):<EOL><INDENT>self._current_module_handle = None<EOL><DEDENT>else:<EOL><INDENT>self._current_module_handle = module_id<EOL><DEDENT>if module_id is not None and isinstance(module_id, str):<EOL><INDENT>current_thread().name = module_id<EOL><DEDENT>
Select module and give access to the module.