def fixDataSetTier(dataset):
    """ makes sure that the data tier of the given data set is
    GEN-SIM-RECO (which is what seems to be used in DQM).

    Also supports datasets without any data tier.
    """

    if dataset.startswith('/'):
        dataset = dataset[1:]

    if dataset.endswith('/'):
        dataset = dataset[:-1]
    
    parts = dataset.split("/")

    if len(parts) < 2 or len(parts) > 3:
        raise Exception("expected at two or three parts (found " + str(len(parts)) + ") separated by '/' for dataset '" + dataset +"'")

    if len(parts) == 2:
        # data tier missing
        parts.append("GEN-SIM-RECO")
    else:
        # replace the last part
        parts[-1] = "GEN-SIM-RECO"

    return "/" + "/".join(parts)