Exemple #1
0
def cleanUnscheduled(proc):
    import FWCore.ParameterSet.Config as cms
    l = dict(proc.paths)
    l.update(dict(proc.endpaths))
    droppedPaths = []
    #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 drop EDProducers except we
    # keep the EDProducers that depend on EDFilters
    for pName, p in l.iteritems():
        qualified_names = []
        v = cms.DecoratedNodeNameVisitor(qualified_names)
        p.visit(v)
        remaining = []

        for n in qualified_names:
            unqual_name = getUnqualifiedName(n)
            #remove EDProducer's and EDFilter's which are set to ignore
            if not (isinstance(getattr(proc, unqual_name), cms.EDProducer) or
                    (n[0] == '-' and isinstance(getattr(proc, unqual_name),
                                                cms.EDFilter))):
                remaining.append(n)

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

    # If there is a schedule then it needs to point at
    # the new Path objects
    if proc.schedule:
        proc.schedule = cms.Schedule(
            [getattr(proc, p) for p in pathNamesInScheduled])
    return proc
Exemple #2
0
def convertToUnscheduled(proc):
    import FWCore.ParameterSet.Config as cms
    """Given a 'Process', convert the python configuration from scheduled execution to unscheduled. This is done by
    1. Removing all modules not on Paths or EndPaths
    2. Pulling EDProducers not dependent on EDFilters off of all Paths
    3. Dropping any Paths which are now empty
    4. Fixing up the Schedule if needed
  """
    # Warning: It is not always possible to convert a configuration
    # where EDProducers are all run on Paths to an unscheduled
    # configuration by modifying only the python configuration.
    # There is more than one kind of pathological condition
    # that can cause this conversion to produce a configuration
    # that gives different results than the original configuration
    # when run under cmsRun. One should view the converted configuration
    # as a thing which needs to be validated. It is possible for there
    # to be pathologies that cannot be resolved by modifying only the
    # python configuration and may require redesign inside the C++ code
    # of the modules and redesign of the logic. For example,
    # an EDAnalyzer might try to get a product and check if the
    # returned handle isValid. Then it could behave differently
    # depending on whether or not the product was present.
    # The behavior when the product is not present could
    # be meaningful and important. In the unscheduled case,
    # the EDProducer will always run and the product could
    # always be there.

    # Remove all modules not on Paths or EndPaths
    proc.prune()

    # Turn on unschedule mode
    if not hasattr(proc, 'options'):
        proc.options = cms.untracked.PSet()
    proc.options.allowUnscheduled = cms.untracked.bool(True)

    l = proc.paths
    droppedPaths = []
    #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

    # Look for EDProducers that depend on an EDFilter, either
    # directly or indirectly through another EDProducer. These
    # EDProducers must stay in a path and run scheduled. The
    # first loop will find all the direct dependencies, but then
    # the loop must be repeated until no more dependencies
    # are found in order to find the indirect dependencies.
    # Note that here we are assuming that if a module
    # has a configuration parameter that is an InputTag, then
    # it depends on the module with the same module label as in
    # the InputTag. In addition, there are a number of special
    # cases where we have identified specific types of modules
    # which use particular string parameters like InputTag
    # module labels. And so we have some special code to
    # handle those cases also. If there are other cases where
    # the module gets things without using InputTags, then this
    # conversion script can fail, which might result in ProductNotFound
    # exceptions or other problems when the converted configuration is run.

    # The dictionary keys are are the types of the EDProducers
    # The dictionary values are lists of parameter names that are strings
    # used like InputTags.
    knownStringInputLabels = {}
    knownStringInputLabels['KProd'] = ['xSrc'
                                       ]  # a fake entry for a unit test below
    knownStringInputLabels['SeedGeneratorFromRegionHitsEDProducer'] = [
        'vertexSrc'
    ]
    knownStringInputLabels['PixelTrackProducer'] = ['vertexSrc']
    knownStringInputLabels['PixelTracksProducer'] = ['vertexSrc']
    knownStringInputLabels['SimpleTrackListMerger'] = [
        'TrackProducer1', 'TrackProducer2'
    ]

    allEDFilters = set(proc.filters_().keys())
    allEDProducers = set(proc.producers_().keys())

    dependentProducers = set()
    firstPass = True

    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

    while True:

        dependentsFoundThisPass = False

        for producer in allEDProducers:
            if producer not in dependentProducers:
                iModule = getattr(proc, producer)

                stringInputLabels = []
                moduleType = iModule.type_()
                if moduleType in knownStringInputLabels:
                    stringInputLabels = knownStringInputLabels[moduleType]

                inputTagLabels = InputTagLabelSet()
                traverseInputTags(getattr(proc, producer), inputTagLabels,
                                  stringInputLabels)

                if firstPass:
                    if not inputTagLabels.labels.isdisjoint(allEDFilters):
                        dependentProducers.add(producer)
                        dependentsFoundThisPass = True

                if not inputTagLabels.labels.isdisjoint(dependentProducers):
                    dependentProducers.add(producer)
                    dependentsFoundThisPass = True

        if not dependentsFoundThisPass:
            break
        firstPass = False

    # Loop over paths
    # On each path we drop EDProducers except we
    # keep the EDProducers that depend on EDFilters
    for pName, p in l.iteritems():
        qualified_names = []
        v = cms.DecoratedNodeNameVisitor(qualified_names)
        p.visit(v)
        remaining = []

        for n in qualified_names:
            unqual_name = getUnqualifiedName(n)
            if not isinstance(getattr(proc, unqual_name), cms.EDProducer):
                remaining.append(n)
            else:
                if unqual_name in dependentProducers:
                    remaining.append(n)

        if remaining:
            p = getQualifiedModule(remaining[0], proc)
            for m in remaining[1:]:
                p += getQualifiedModule(m, proc)
            setattr(proc, pName, cms.Path(p))
        # drop empty paths
        else:
            setattr(proc, pName, cms.Path())

    # If there is a schedule then it needs to point at
    # the new Path objects
    if proc.schedule:
        proc.schedule = cms.Schedule(
            [getattr(proc, p) for p in pathNamesInScheduled])
    return proc
Exemple #3
0
def cleanUnscheduled(proc):
    import FWCore.ParameterSet.Config as cms
    l = dict(proc.paths)
    l.update(dict(proc.endpaths))
    droppedPaths = []
    #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

    # Look for EDProducers that depend on an EDFilter, either
    # directly or indirectly through another EDProducer. These
    # EDProducers must stay in a path and run scheduled. The
    # first loop will find all the direct dependencies, but then
    # the loop must be repeated until no more dependencies
    # are found in order to find the indirect dependencies.
    # Note that here we are assuming that if a module
    # has a configuration parameter that is an InputTag, then
    # it depends on the module with the same module label as in
    # the InputTag. In addition, there are a number of special
    # cases where we have identified specific types of modules
    # which use particular string parameters like InputTag
    # module labels. And so we have some special code to
    # handle those cases also. If there are other cases where
    # the module gets things without using InputTags, then this
    # conversion script can fail, which might result in ProductNotFound
    # exceptions or other problems when the converted configuration is run.

    # The dictionary keys are are the types of the EDProducers
    # The dictionary values are lists of parameter names that are strings
    # used like InputTags.
    knownStringInputLabels = {}
    knownStringInputLabels['KProd'] = ['xSrc'
                                       ]  # a fake entry for a unit test below
    knownStringInputLabels['SeedGeneratorFromRegionHitsEDProducer'] = [
        'vertexSrc'
    ]
    knownStringInputLabels['PixelTrackProducer'] = ['vertexSrc']
    knownStringInputLabels['PixelTracksProducer'] = ['vertexSrc']
    knownStringInputLabels['SimpleTrackListMerger'] = [
        'TrackProducer1', 'TrackProducer2'
    ]

    allEDFilters = set(proc.filters_().keys())
    allEDProducers = set(proc.producers_().keys())

    dependentProducers = set()
    firstPass = True

    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

    while True:

        dependentsFoundThisPass = False

        for producer in allEDProducers:
            if producer not in dependentProducers:
                iModule = getattr(proc, producer)

                stringInputLabels = []
                moduleType = iModule.type_()
                if moduleType in knownStringInputLabels:
                    stringInputLabels = knownStringInputLabels[moduleType]

                inputTagLabels = InputTagLabelSet()
                traverseInputTags(getattr(proc, producer), inputTagLabels,
                                  stringInputLabels)

                if firstPass:
                    if not inputTagLabels.labels.isdisjoint(allEDFilters):
                        dependentProducers.add(producer)
                        dependentsFoundThisPass = True

                if not inputTagLabels.labels.isdisjoint(dependentProducers):
                    dependentProducers.add(producer)
                    dependentsFoundThisPass = True

        if not dependentsFoundThisPass:
            break
        firstPass = False

    # Loop over paths
    # On each path we drop EDProducers except we
    # keep the EDProducers that depend on EDFilters
    for pName, p in l.iteritems():
        qualified_names = []
        v = cms.DecoratedNodeNameVisitor(qualified_names)
        p.visit(v)
        remaining = []

        for n in qualified_names:
            unqual_name = getUnqualifiedName(n)
            if not isinstance(getattr(proc, unqual_name), cms.EDProducer):
                remaining.append(n)
            else:
                if unqual_name in dependentProducers:
                    remaining.append(n)

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

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