@staticmethod
def do_selection_reduction_to_one_parent(selection):
    """ Find and reduce selection to one parent state.

        :param selection:
        :return: state model which is parent of selection or None if root state
        """
    all_models_selected = selection.get_all()
    parent_m_count_dict = {}
    for model in all_models_selected:
        parent_m_count_dict[model.parent] = parent_m_count_dict[model.parent
            ] + 1 if model.parent in parent_m_count_dict else 1
    parent_m = None
    current_count_parent = 0
    for possible_parent_m, count in parent_m_count_dict.items():
        parent_m = (possible_parent_m if current_count_parent < count else
            parent_m)
    if len(selection.states) == 1 and selection.get_selected_state(
        ).state.is_root_state:
        parent_m = None
        if len(all_models_selected) > 1:
            selection.set(selection.get_selected_state())
    if parent_m is not None:
        for model in all_models_selected:
            if model.parent is not parent_m:
                selection.remove(model)
    return parent_m
