CMS 3D CMS Logo

edmTracerLogToSimpleConfig.py
Go to the documentation of this file.
1 #==============================
2 #
3 # First argument is a log file from cmsRun
4 # containing output from Tracer service with
5 # the configuration containing
6 # dumpPathsAndConsumes = cms.untracked.bool(True)
7 #
8 # A new configuration will be created with the same
9 # topology as the original configuration but with
10 # the modules replaced with 'trivial' versions.
11 # This allows studying the cost of the framework infrastructure
12 # on realistic module topologies.
13 #==============================
14 
15 import sys
16 
17 f = open(sys.argv[1])
18 
19 
20 def fixName(name):
21  return name.replace("_","IoI")
22 
24  def __init__(self):
26  self._isEndPath = set()
27  self._presentPath = []
28  self._presentPathName = None
29  self.__preamble = 'modules on '
30  def parse(self,line):
31  if line[:len(self.__preamble)] == self.__preamble:
32  if self._presentPathName:
34  self._presentPathName = line.split(" ")[3][:-2]
35  if -1 != line.find('end path'):
36  self._isEndPath.add(self._presentPathName)
37  self._presentPath = []
38  else:
39  n = line.strip()
40  if self._presentPathName != n:
41  self._presentPath.append( fixName(n) )
42  def finish(self):
43  if self._presentPathName:
45 
47  def __init__(self):
49  self._isAnalyzer = set()
50  self._presentConsumes = []
51  self._presentModuleName = None
52  self.__preramble = ' '
53  def parse(self,line):
54  if line[:len(self.__preramble)] != self.__preramble:
55  if self._presentModuleName:
57  start = line.find("'")+1
58  length = line[start:].find("'")
59  self._presentModuleName = fixName(line[start:length+start])
60  self._presentConsumes = []
61  if -1 != l.find("Analyzer"):
62  self._isAnalyzer.add(self._presentModuleName)
63  else:
64  self._presentConsumes.append( fixName(line[line.find("'")+1:-2]) )
65  def finish(self):
66  if self._presentModuleName:
68 
69 pathParser = PathParser()
70 consumesParser = ConsumesParser()
71 
72 parser = pathParser
73 
74 foundPaths = False
75 pathStartsWith = "modules on "
76 
77 startOfConsumes = "All modules and modules in the current process whose products they consume:"
78 skipLineAfterConsumes = False
79 doneWithPaths = False
80 
81 endOfConsumes = "All modules (listed by class and label) and all their consumed products."
82 for l in f.readlines():
83  if not foundPaths:
84  if l[:len(pathStartsWith)] == pathStartsWith:
85  foundPaths = True
86  else:
87  #skip lines till find paths
88  continue
89  if not doneWithPaths:
90  if l[:len(startOfConsumes)] == startOfConsumes:
91  skipLineAfterConsumes = True
92  doneWithPaths = True
93  pathParser.finish()
94  parser = consumesParser
95  continue
96  if skipLineAfterConsumes:
97  skipLineAfterConsumes = False
98  continue
99  if l[:len(endOfConsumes)] == endOfConsumes:
100  break
101  parser.parse(l)
102 
103 parser.finish()
104 
105 print "import FWCore.ParameterSet.Config as cms"
106 print "process = cms.Process('RECO')"
107 
108 print """process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(2000))
109 process.options = cms.untracked.PSet(
110 # numberOfThreads = cms.untracked.uint32(8),
111  numberOfThreads = cms.untracked.uint32(1),
112  numberOfStreams = cms.untracked.uint32(0),
113 # wantSummary = cms.untracked.bool(True)
114 )
115 
116 process.add_(cms.Service("Timing", summaryOnly = cms.untracked.bool(True)))
117 
118 # The following two lines reduce the clutter of repeated printouts
119 # of the same exception message.
120 process.load("FWCore.MessageLogger.MessageLogger_cfi")
121 process.MessageLogger.destinations = ['cerr']
122 process.MessageLogger.statistics = []
123 process.MessageLogger.fwkJobReports = []
124 process.MessageLogger.cerr.FwkReport.reportEvery = 50000
125 process.MessageLogger.cerr.threshold = 'WARNING'
126 """
127 
128 print "process.source = cms.Source('EmptySource')"
129 
130 allModules = set()
131 modulesWithConsumes = set()
132 #needed to get rid of PathStatus modules at end of paths
133 pathNamesAsModules = set( (fixName(n) for n in pathParser._pathToModules.iterkeys()) )
134 
135 for m,c in consumesParser._consumesForModule.iteritems():
136  if m in pathNamesAsModules:
137  continue
138  if m in consumesParser._isAnalyzer:
139  print "process.%s = cms.EDAnalyzer('MultipleIntsAnalyzer', getFromModules = cms.untracked.VInputTag(*[%s]))"%(m,",".join(["cms.InputTag('%s')"%i for i in (n for n in c if n != 'TriggerResults')]))
140  elif not c:
141  print "process.%s = cms.EDProducer('IntProducer', ivalue = cms.int32(1))"%m
142  else:
143  print "process.%s = cms.EDProducer('AddIntsProducer', labels = cms.vstring(*[%s]))"%(m,",".join(["'%s'"%i for i in (n for n in c if n != 'TriggerResults')]))
144  allModules.add(m)
145  for o in c:
146  allModules.add(o)
147  modulesWithConsumes.add(m)
148 
149 for m in pathParser._pathToModules.itervalues():
150  for i in m:
151  allModules.add(i)
152 
153 for m in allModules.difference(modulesWithConsumes):
154  print "process.%s = cms.EDProducer('IntProducer', ivalue = cms.int32(1))"%(m)
155 
156 
157 print 't = cms.Task(*[%s])'%(",".join(["process.%s"%i for i in allModules if i not in consumesParser._isAnalyzer]))
158 for p,m in pathParser._pathToModules.iteritems():
159  if p in pathParser._isEndPath:
160  print "process.%s = cms.EndPath(%s)"%(p,"+".join(["process.%s"%i for i in m]))
161  else:
162  if m:
163  print "process.%s = cms.Path(%s,t)"%(p,"+".join(["process.%s"%i for i in m]))
164  else:
165  print "process.%s = cms.Path()"%(p)
166 
167 
168 #print "paths = ",pathParser._pathToModules
169 #print "modulesToConsumes =",consumesParser._consumesForModule
170 
171 
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
static std::string join(char **cmd)
Definition: RemoteFile.cc:18