Exemple #1
0
def cleanUnscheduled(proc):
    import FWCore.ParameterSet.Config as cms

    pathsAndEndPaths = dict(proc.paths)
    pathsAndEndPaths.update(dict(proc.endpaths))

    #have to get them now since switching them after the
    # paths have been changed gives null labels
    if proc.schedule:
        pathNamesInScheduled = [p.label_() for p in proc.schedule]
    else:
        pathNamesInScheduled = False

    def getUnqualifiedName(name):
        if name[0] in set(['!', '-']):
            return name[1:]
        return name

    def getQualifiedModule(name, proc):
        unqual_name = getUnqualifiedName(name)
        p = getattr(proc, unqual_name)
        if unqual_name != name:
            if name[0] == '!':
                p = ~p
            elif name[0] == '-':
                p = cms.ignore(p)
        return p

    # Loop over paths
    # On each path we move EDProducers and EDFilters that
    # are ignored to Tasks
    producerList = list()
    import six
    for pName, originalPath in six.iteritems(pathsAndEndPaths):
        producerList[:] = []
        qualified_names = []
        v = cms.DecoratedNodeNamePlusVisitor(qualified_names)
        originalPath.visit(v)
        remaining = []

        for n in qualified_names:
            unqual_name = getUnqualifiedName(n)
            mod = getattr(proc, unqual_name)

            #remove EDProducer's and EDFilter's which are set to ignore
            if not (isinstance(mod, cms.EDProducer) or
                    (n[0] == '-' and isinstance(mod, cms.EDFilter))):
                remaining.append(n)
            else:
                producerList.append(mod)

        taskList = []
        if v.leavesOnTasks():
            taskList.append(cms.Task(*(v.leavesOnTasks())))
        if (producerList):
            taskList.append(cms.Task(*producerList))

        if remaining:
            p = getQualifiedModule(remaining[0], proc)
            for m in remaining[1:]:
                p += getQualifiedModule(m, proc)
            setattr(proc, pName, type(getattr(proc, pName))(p))
        else:
            setattr(proc, pName, type(getattr(proc, pName))())

        newPath = getattr(proc, pName)
        if (taskList):
            newPath.associate(*taskList)

    # If there is a schedule then it needs to point at
    # the new Path objects
    if proc.schedule:
        listOfTasks = list(proc.schedule._tasks)
        proc.schedule = cms.Schedule(
            [getattr(proc, p) for p in pathNamesInScheduled])
        proc.schedule.associate(*listOfTasks)
    return proc