Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-12-01 23:40:21

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