CMS 3D CMS Logo

edmTracerLogToSimpleConfig.py
Go to the documentation of this file.
1 from __future__ import print_function
2 #==============================
3 #
4 # First argument is a log file from cmsRun
5 # containing output from Tracer service with
6 # the configuration containing
7 # dumpPathsAndConsumes = cms.untracked.bool(True)
8 #
9 # A new configuration will be created with the same
10 # topology as the original configuration but with
11 # the modules replaced with 'trivial' versions.
12 # This allows studying the cost of the framework infrastructure
13 # on realistic module topologies.
14 #==============================
15 
16 import sys
17 
18 f = open(sys.argv[1])
19 
20 
21 def fixName(name):
22  return name.replace("_","IoI")
23 
25  def __init__(self):
26  self._pathToModules = dict()
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'):
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):
49  self._consumesForModule = dict()
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"):
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 
123 process.MessageLogger.cerr.enableStatistics = False
124 
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 consumesParser._consumesForModule.items():
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.VInputTag(*[%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 pathParser._pathToModules.values():
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 pathParser._pathToModules.items():
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 
edmTracerLogToSimpleConfig.ConsumesParser.parse
def parse(self, line)
Definition: edmTracerLogToSimpleConfig.py:54
edmTracerLogToSimpleConfig.PathParser.parse
def parse(self, line)
Definition: edmTracerLogToSimpleConfig.py:31
edmTracerLogToSimpleConfig.PathParser.__init__
def __init__(self)
Definition: edmTracerLogToSimpleConfig.py:25
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
edmTracerLogToSimpleConfig.PathParser._presentPathName
_presentPathName
Definition: edmTracerLogToSimpleConfig.py:29
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
edmTracerLogToSimpleConfig.ConsumesParser._presentConsumes
_presentConsumes
Definition: edmTracerLogToSimpleConfig.py:51
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edmTracerLogToSimpleConfig.PathParser.finish
def finish(self)
Definition: edmTracerLogToSimpleConfig.py:43
edmTracerLogToSimpleConfig.PathParser
Definition: edmTracerLogToSimpleConfig.py:24
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
PVValHelper::add
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
Definition: PVValidationHelpers.cc:12
mps_setup.append
append
Definition: mps_setup.py:85
edmTracerLogToSimpleConfig.fixName
def fixName(name)
Definition: edmTracerLogToSimpleConfig.py:21
edmTracerLogToSimpleConfig.ConsumesParser._consumesForModule
_consumesForModule
Definition: edmTracerLogToSimpleConfig.py:49
edmTracerLogToSimpleConfig.ConsumesParser
Definition: edmTracerLogToSimpleConfig.py:47
edmTracerLogToSimpleConfig.ConsumesParser.__preramble
__preramble
Definition: edmTracerLogToSimpleConfig.py:53
edmTracerLogToSimpleConfig.ConsumesParser.__init__
def __init__(self)
Definition: edmTracerLogToSimpleConfig.py:48
edmTracerLogToSimpleConfig.ConsumesParser._presentModuleName
_presentModuleName
Definition: edmTracerLogToSimpleConfig.py:52
edmTracerLogToSimpleConfig.ConsumesParser._isAnalyzer
_isAnalyzer
Definition: edmTracerLogToSimpleConfig.py:50
edmTracerLogToSimpleConfig.ConsumesParser.finish
def finish(self)
Definition: edmTracerLogToSimpleConfig.py:66
edmTracerLogToSimpleConfig.PathParser._presentPath
_presentPath
Definition: edmTracerLogToSimpleConfig.py:28
edmTracerLogToSimpleConfig.PathParser._isEndPath
_isEndPath
Definition: edmTracerLogToSimpleConfig.py:27
edmTracerLogToSimpleConfig.PathParser._pathToModules
_pathToModules
Definition: edmTracerLogToSimpleConfig.py:26
edmTracerLogToSimpleConfig.PathParser.__preamble
__preamble
Definition: edmTracerLogToSimpleConfig.py:30