CMS 3D CMS Logo

usedOutput.py

Go to the documentation of this file.
00001 import FWCore.ParameterSet.SequenceTypes as sqt
00002 import FWCore.ParameterSet.Config as cms
00003 import FWCore.ParameterSet.Modules as mod
00004 
00005 
00006 def getModulesFromSequence(sequence,list):
00007     item = sequence._seq
00008     if isinstance(item,mod._Module):
00009         list.append(item)
00010     elif isinstance(item,cms.Sequence):
00011          getModulesFromSequence(item,list)
00012     else:
00013          _getModulesFromOp(item,list)
00014                                                     
00015 
00016 def _getModulesFromOp(op,list):
00017     for item in dir(op):
00018         o = getattr(op,item)
00019         if isinstance(o,mod._Module):
00020             list.append(o)
00021         elif isinstance(o, cms.Sequence):
00022             _getModulesFromOp(o,list)
00023         elif isinstance(o,sqt._Sequenceable):
00024             _getModulesFromOp(o,list)
00025                     
00026 
00027 def extractUsedOutputs(process):
00028     allEndPathModules = []
00029     for name in process._Process__endpaths:
00030         endpath = getattr(process,name)
00031         list = []
00032         getModulesFromSequence(endpath,list)
00033         allEndPathModules.extend(list)
00034     allUsedOutputModules = []
00035     for module in allEndPathModules:
00036         if isinstance(module, cms.OutputModule):
00037             allUsedOutputModules.append(module)
00038     return allUsedOutputModules
00039 
00040 if __name__ == "__main__":
00041     import unittest
00042     class TestPrintPath(unittest.TestCase):
00043         def testGetModules(self):
00044             p=cms.Process("Test")
00045             p.foo = cms.EDProducer("Foo")
00046             p.p = cms.Path(p.foo)
00047             list = []
00048             getModulesFromSequence(p.p,list)
00049             print len(list)
00050 
00051             p=cms.Process("Test")
00052             p.foo = cms.OutputModule("Foo")
00053             p.bar = cms.OutputModule("Bar")
00054             p.unused = cms.OutputModule("Unused")
00055             p.p = cms.EndPath(p.foo*p.bar)
00056             usedOutputs = extractUsedOutputs(p)
00057             print len(usedOutputs)
00058 
00059             p=cms.Process("Test")
00060             p.foo = cms.EDProducer("Foo")
00061             p.bar = cms.EDProducer("Bar")
00062             p.s = cms.Sequence(p.foo*p.bar)
00063             p.fii = cms.EDProducer("Fii")
00064             p.p = cms.Path(p.s*p.fii)
00065             list = []
00066             getModulesFromSequence(p.p,list)
00067             print len(list)
00068                        
00069 
00070     unittest.main()

Generated on Tue Jun 9 17:36:27 2009 for CMSSW by  doxygen 1.5.4