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 import six
17 
18 f = open(sys.argv[1])
19 
20 
21 def fixName(name):
22  return name.replace("_","IoI")
23 
25  def __init__(self):
27  self._isEndPath = set()
28  self._presentPath = []
29  self._presentPathName = None
30  self.__preamble = 'modules on '
31  def parse(self,line):
32  if line[:len(self.__preamble)] == self.__preamble:
33  if self._presentPathName:
35  self._presentPathName = line.split(" ")[3][:-2]
36  if -1 != line.find('end path'):
37  self._isEndPath.add(self._presentPathName)
38  self._presentPath = []
39  else:
40  n = line.strip()
41  if self._presentPathName != n:
42  self._presentPath.append( fixName(n) )
43  def finish(self):
44  if self._presentPathName:
46 
48  def __init__(self):
50  self._isAnalyzer = set()
51  self._presentConsumes = []
52  self._presentModuleName = None
53  self.__preramble = ' '
54  def parse(self,line):
55  if line[:len(self.__preramble)] != self.__preramble:
56  if self._presentModuleName:
58  start = line.find("'")+1
59  length = line[start:].find("'")
60  self._presentModuleName = fixName(line[start:length+start])
61  self._presentConsumes = []
62  if -1 != l.find("Analyzer"):
63  self._isAnalyzer.add(self._presentModuleName)
64  else:
65  self._presentConsumes.append( fixName(line[line.find("'")+1:-2]) )
66  def finish(self):
67  if self._presentModuleName:
69 
70 pathParser = PathParser()
71 consumesParser = ConsumesParser()
72 
73 parser = pathParser
74 
75 foundPaths = False
76 pathStartsWith = "modules on "
77 
78 startOfConsumes = "All modules and modules in the current process whose products they consume:"
79 skipLineAfterConsumes = False
80 doneWithPaths = False
81 
82 endOfConsumes = "All modules (listed by class and label) and all their consumed products."
83 for l in f.readlines():
84  if not foundPaths:
85  if l[:len(pathStartsWith)] == pathStartsWith:
86  foundPaths = True
87  else:
88  #skip lines till find paths
89  continue
90  if not doneWithPaths:
91  if l[:len(startOfConsumes)] == startOfConsumes:
92  skipLineAfterConsumes = True
93  doneWithPaths = True
94  pathParser.finish()
95  parser = consumesParser
96  continue
97  if skipLineAfterConsumes:
98  skipLineAfterConsumes = False
99  continue
100  if l[:len(endOfConsumes)] == endOfConsumes:
101  break
102  parser.parse(l)
103 
104 parser.finish()
105 
106 print "import FWCore.ParameterSet.Config as cms"
107 print "process = cms.Process('RECO')"
108 
109 print """process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(2000))
110 process.options = cms.untracked.PSet(
111 # numberOfThreads = cms.untracked.uint32(8),
112  numberOfThreads = cms.untracked.uint32(1),
113  numberOfStreams = cms.untracked.uint32(0),
114 # wantSummary = cms.untracked.bool(True)
115 )
116 
117 process.add_(cms.Service("Timing", summaryOnly = cms.untracked.bool(True)))
118 
119 # The following two lines reduce the clutter of repeated printouts
120 # of the same exception message.
121 process.load("FWCore.MessageLogger.MessageLogger_cfi")
122 process.MessageLogger.destinations = ['cerr']
123 process.MessageLogger.statistics = []
124 process.MessageLogger.fwkJobReports = []
125 process.MessageLogger.cerr.FwkReport.reportEvery = 50000
126 process.MessageLogger.cerr.threshold = 'WARNING'
127 """
128 
129 print "process.source = cms.Source('EmptySource')"
130 
131 allModules = set()
132 modulesWithConsumes = set()
133 #needed to get rid of PathStatus modules at end of paths
134 pathNamesAsModules = set( (fixName(n) for n in pathParser._pathToModules.iterkeys()) )
135 
136 for m,c in six.iteritems(consumesParser._consumesForModule):
137  if m in pathNamesAsModules:
138  continue
139  if m in consumesParser._isAnalyzer:
140  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')]))
141  elif not c:
142  print "process.%s = cms.EDProducer('IntProducer', ivalue = cms.int32(1))"%m
143  else:
144  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')]))
145  allModules.add(m)
146  for o in c:
147  allModules.add(o)
148  modulesWithConsumes.add(m)
149 
150 for m in six.itervalues(pathParser._pathToModules):
151  for i in m:
152  allModules.add(i)
153 
154 for m in allModules.difference(modulesWithConsumes):
155  print "process.%s = cms.EDProducer('IntProducer', ivalue = cms.int32(1))"%(m)
156 
157 
158 print 't = cms.Task(*[%s])'%(",".join(["process.%s"%i for i in allModules if i not in consumesParser._isAnalyzer]))
159 for p,m in six.iteritems(pathParser._pathToModules):
160  if p in pathParser._isEndPath:
161  print "process.%s = cms.EndPath(%s)"%(p,"+".join(["process.%s"%i for i in m]))
162  else:
163  if m:
164  print "process.%s = cms.Path(%s,t)"%(p,"+".join(["process.%s"%i for i in m]))
165  else:
166  print "process.%s = cms.Path()"%(p)
167 
168 
169 #print "paths = ",pathParser._pathToModules
170 #print "modulesToConsumes =",consumesParser._consumesForModule
171 
172 
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