Go to the documentation of this file.00001 def removeModulesNotOnAPathExcluding( process, keepList=() ):
00002 """Given a 'process', find all modules (EDProducers,EDFilters,EDAnalyzers,OutputModules)
00003 and remove them if they do not appear on a Path or EndPath. One can optionally pass in
00004 a list of modules which even if they are not on a Path or EndPath you wish to have stay
00005 in the configuration [useful for unscheduled execution].
00006 """
00007 allMods=set((x for x in process.producers_().iterkeys()))
00008 allMods.update((x for x in process.filters_().iterkeys()))
00009 allMods.update((x for x in process.analyzers_().iterkeys()))
00010 allMods.update((x for x in process.outputModules_().iterkeys()))
00011
00012 modulesOnPaths = set()
00013 for p in process.paths_():
00014 modulesOnPaths.update( (x for x in getattr(process,p).moduleNames()))
00015 for p in process.endpaths_():
00016 modulesOnPaths.update( (x for x in getattr(process,p).moduleNames()))
00017
00018 notOnPaths = allMods.difference(modulesOnPaths)
00019
00020 keepModuleNames = set( (x.label_() for x in keepList) )
00021
00022 getRidOf = notOnPaths.difference(keepModuleNames)
00023
00024 for n in getRidOf:
00025 delattr(process,n)
00026
00027 if __name__ == "__main__":
00028 import unittest
00029 class TestModuleCommand(unittest.TestCase):
00030 def setup(self):
00031 None
00032 def testConfig(self):
00033 import FWCore.ParameterSet.Config as cms
00034 process = cms.Process("Test")
00035
00036 process.a = cms.EDProducer("A")
00037 process.b = cms.EDProducer("B")
00038 process.c = cms.EDProducer("C")
00039
00040 process.p = cms.Path(process.b*process.c)
00041
00042 process.d = cms.EDAnalyzer("D")
00043
00044 process.o = cms.OutputModule("MyOutput")
00045 process.out = cms.EndPath(process.o)
00046 removeModulesNotOnAPathExcluding(process,(process.b,))
00047
00048 self.assert_(not hasattr(process,'a'))
00049 self.assert_(hasattr(process,'b'))
00050 self.assert_(hasattr(process,'c'))
00051 self.assert_(not hasattr(process,'d'))
00052 self.assert_(hasattr(process,'o'))
00053 unittest.main()