Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-23 02:25:42

0001 from __future__ import print_function
0002 #==============================
0003 #
0004 # First argument is a log file from cmsRun
0005 # containing output from Tracer service with
0006 # the configuration containing
0007 #     dumpPathsAndConsumes = cms.untracked.bool(True)
0008 #
0009 # A new configuration will be created with the same
0010 # topology as the original configuration but with
0011 # the modules replaced with 'trivial' versions.
0012 # This allows studying the cost of the framework infrastructure
0013 # on realistic module topologies.
0014 #==============================
0015 
0016 import sys
0017 
0018 f = open(sys.argv[1])
0019 
0020 
0021 def fixName(name):
0022     return name.replace("_","IoI")
0023 
0024 class PathParser(object):
0025     def __init__(self):
0026         self._pathToModules = dict()
0027         self._isEndPath = set()
0028         self._presentPath = []
0029         self._presentPathName = None
0030         self.__preamble = 'modules on '
0031     def parse(self,line):
0032         if line[:len(self.__preamble)] == self.__preamble:
0033             if self._presentPathName:
0034                 self._pathToModules[self._presentPathName] = self._presentPath
0035             self._presentPathName = line.split(" ")[3][:-2]
0036             if -1 != line.find('end path'):
0037                 self._isEndPath.add(self._presentPathName)
0038             self._presentPath = []
0039         else:
0040             n = line.strip()
0041             if self._presentPathName != n:
0042                 self._presentPath.append( fixName(n) )
0043     def finish(self):
0044         if self._presentPathName:
0045             self._pathToModules[self._presentPathName] = self._presentPath
0046 
0047 class ConsumesParser(object):
0048     def __init__(self):
0049         self._consumesForModule = dict()
0050         self._isAnalyzer = set()
0051         self._presentConsumes = []
0052         self._presentModuleName = None
0053         self.__preramble = '    '
0054     def parse(self,line):
0055         if line[:len(self.__preramble)] != self.__preramble:
0056             if self._presentModuleName:
0057                 self._consumesForModule[self._presentModuleName] = self._presentConsumes
0058             start = line.find("'")+1
0059             length = line[start:].find("'")
0060             self._presentModuleName = fixName(line[start:length+start])
0061             self._presentConsumes = []
0062             if -1 != l.find("Analyzer"):
0063                 self._isAnalyzer.add(self._presentModuleName)
0064         else:
0065             self._presentConsumes.append( fixName(line[line.find("'")+1:-2]) )
0066     def finish(self):
0067         if self._presentModuleName:
0068             self._consumesForModule[self._presentModuleName] = self._presentConsumes
0069     
0070 pathParser = PathParser()
0071 consumesParser = ConsumesParser()
0072 
0073 parser = pathParser
0074 
0075 foundPaths = False
0076 pathStartsWith = "modules on "
0077 
0078 startOfConsumes = "All modules and modules in the current process whose products they consume:"
0079 skipLineAfterConsumes = False
0080 doneWithPaths = False
0081 
0082 endOfConsumes = "All modules (listed by class and label) and all their consumed products."
0083 for l in f.readlines():
0084     if not foundPaths:
0085         if l[:len(pathStartsWith)] == pathStartsWith:
0086             foundPaths = True
0087         else:
0088             #skip lines till find paths
0089             continue
0090     if not doneWithPaths:
0091         if l[:len(startOfConsumes)] == startOfConsumes:
0092             skipLineAfterConsumes = True
0093             doneWithPaths = True
0094             pathParser.finish()
0095             parser = consumesParser
0096             continue
0097     if skipLineAfterConsumes:
0098         skipLineAfterConsumes = False
0099         continue
0100     if l[:len(endOfConsumes)] == endOfConsumes:
0101         break
0102     parser.parse(l)
0103 
0104 parser.finish()
0105 
0106 print("import FWCore.ParameterSet.Config as cms")
0107 print("process = cms.Process('RECO')")
0108 
0109 print("""process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(2000))
0110 process.options = cms.untracked.PSet(
0111 #    numberOfThreads = cms.untracked.uint32(8),
0112     numberOfThreads = cms.untracked.uint32(1),
0113     numberOfStreams = cms.untracked.uint32(0),
0114 #    wantSummary = cms.untracked.bool(True)
0115 )
0116 
0117 process.add_(cms.Service("Timing", summaryOnly = cms.untracked.bool(True)))
0118 
0119 # The following two lines reduce the clutter of repeated printouts
0120 # of the same exception message.
0121 process.load("FWCore.MessageLogger.MessageLogger_cfi")
0122 
0123 process.MessageLogger.cerr.enableStatistics = False
0124 
0125 process.MessageLogger.cerr.FwkReport.reportEvery = 50000
0126 process.MessageLogger.cerr.threshold = 'WARNING'
0127 """)
0128 
0129 print("process.source = cms.Source('EmptySource')")
0130 
0131 allModules = set()
0132 modulesWithConsumes = set()
0133 #needed to get rid of PathStatus modules at end of paths
0134 pathNamesAsModules = set( (fixName(n) for n in pathParser._pathToModules.iterkeys()) )
0135 
0136 for m,c in consumesParser._consumesForModule.items():
0137     if m in pathNamesAsModules:
0138         continue
0139     if m in consumesParser._isAnalyzer:
0140         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')])))
0141     elif not c:
0142         print("process.%s = cms.EDProducer('IntProducer', ivalue = cms.int32(1))"%m)
0143     else:
0144         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')])))
0145     allModules.add(m)
0146     for o  in c:
0147         allModules.add(o)
0148     modulesWithConsumes.add(m)
0149 
0150 for m in pathParser._pathToModules.values():
0151     for i in m:
0152         allModules.add(i)
0153 
0154 for m in allModules.difference(modulesWithConsumes):
0155     print("process.%s = cms.EDProducer('IntProducer', ivalue = cms.int32(1))"%(m))
0156 
0157 
0158 print('t = cms.Task(*[%s])'%(",".join(["process.%s"%i for i in allModules if i not in consumesParser._isAnalyzer])))
0159 for p,m in pathParser._pathToModules.items():
0160     if p in pathParser._isEndPath:
0161         print("process.%s = cms.EndPath(%s)"%(p,"+".join(["process.%s"%i for i in m])))
0162     else:
0163         if m:
0164             print("process.%s = cms.Path(%s,t)"%(p,"+".join(["process.%s"%i for i in m])))
0165         else:
0166             print("process.%s = cms.Path()"%(p))
0167     
0168 
0169 #print "paths = ",pathParser._pathToModules
0170 #print "modulesToConsumes =",consumesParser._consumesForModule
0171 
0172