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):
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'):
38  self._isEndPath.add(self._presentPathName)
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):
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"):
64  self._isAnalyzer.add(self._presentModuleName)
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 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
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