CMS 3D CMS Logo

usedOutput.py
Go to the documentation of this file.
2 import FWCore.ParameterSet.Config as cms
3 import FWCore.ParameterSet.Modules as mod
4 
5 
6 def getModulesFromSequence(sequence,list):
7  item = sequence._seq
8  if isinstance(item,mod._Module):
9  list.append(item)
10  elif isinstance(item,cms.Sequence):
11  getModulesFromSequence(item,list)
12  else:
13  _getModulesFromOp(item,list)
14 
15 
16 def _getModulesFromOp(op,list):
17  for item in dir(op):
18  o = getattr(op,item)
19  if isinstance(o,mod._Module):
20  list.append(o)
21  elif isinstance(o, cms.Sequence):
22  _getModulesFromOp(o,list)
23  elif isinstance(o,sqt._Sequenceable):
24  _getModulesFromOp(o,list)
25 
26 
27 def extractUsedOutputs(process):
28  allEndPathModules = []
29  for name in process._Process__endpaths:
30  endpath = getattr(process,name)
31  list = []
32  getModulesFromSequence(endpath,list)
33  allEndPathModules.extend(list)
34  allUsedOutputModules = []
35  for module in allEndPathModules:
36  if isinstance(module, cms.OutputModule):
37  allUsedOutputModules.append(module)
38  return allUsedOutputModules
39 
40 if __name__ == "__main__":
41  import unittest
42  class TestPrintPath(unittest.TestCase):
43  def testGetModules(self):
44  p=cms.Process("Test")
45  p.foo = cms.EDProducer("Foo")
46  p.p = cms.Path(p.foo)
47  list = []
48  getModulesFromSequence(p.p,list)
49  print len(list)
50 
51  p=cms.Process("Test")
52  p.foo = cms.OutputModule("Foo")
53  p.bar = cms.OutputModule("Bar")
54  p.unused = cms.OutputModule("Unused")
55  p.p = cms.EndPath(p.foo*p.bar)
56  usedOutputs = extractUsedOutputs(p)
57  print len(usedOutputs)
58 
59  p=cms.Process("Test")
60  p.foo = cms.EDProducer("Foo")
61  p.bar = cms.EDProducer("Bar")
62  p.s = cms.Sequence(p.foo*p.bar)
63  p.fii = cms.EDProducer("Fii")
64  p.p = cms.Path(p.s*p.fii)
65  list = []
66  getModulesFromSequence(p.p,list)
67  print len(list)
68 
69 
70  unittest.main()
def extractUsedOutputs(process)
Definition: usedOutput.py:27
def _getModulesFromOp(op, list)
Definition: usedOutput.py:16
def getModulesFromSequence(sequence, list)
Definition: usedOutput.py:6
dbl *** dir
Definition: mlp_gen.cc:35