<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def process_selection(self, instance_count, node_reg, node_ids):
        # Select primaries for current view_no
        if instance_count == 0:
            return []

        '''
        Build a set of names of primaries, it is needed to avoid
        duplicates of primary nodes for different replicas.
        '''

        primaries = []
        primary_rank = None

        for i in range(instance_count):
            if i == 0:
                primary_name = self._next_primary_node_name_for_master(node_reg, node_ids)
                primary_rank = self.node.get_rank_by_name(primary_name, node_reg, node_ids)
                if primary_rank is None:
                    raise LogicError('primary_rank must not be None')
            else:
                primary_name, _ = self.next_primary_replica_name_for_backup(
                    i, primary_rank, primaries, node_reg, node_ids)

            primaries.append(primary_name)
            logger.display("{} selected primary {} for instance {} (view {})"
                           .format(PRIMARY_SELECTION_PREFIX,
                                   primary_name, i, self.viewNo),
                           extra={"cli": "ANNOUNCE",
                                  "tags": ["node-election"]})
        if len(primaries) != instance_count:
            raise LogicError('instances inconsistency')

        if len(primaries) != len(set(primaries)):
            raise LogicError('repeating instances')

        return primaries