CMS 3D CMS Logo

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