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