Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:52:48

0001 #!/usr/bin/env python
0002 from __future__ import print_function
0003 import FWCore.ParameterSet.Config as cms
0004 import sys
0005 import FWCore.ParameterSet.SequenceTypes as sqt
0006 import FWCore.ParameterSet.Modules as mod
0007 
0008 
0009 def checkOutputModuleConfig(module):
0010     """Check if a PoolOutputModule is properly configured"""
0011     if hasattr(module,"dataset"):
0012         dataset = getattr(module,"dataset")
0013         try:
0014             dataTier = getattr(dataset,"dataTier")
0015             filterName = getattr(dataset,"filterName")
0016         except:
0017             print("Module", module, "has a malformed PSet dataset")
0018     else:
0019         print("Module", module, "has no PSet dataset defined")
0020 
0021 
0022 def getModulesFromSequence(sequence,list):
0023     item = sequence._seq
0024     if isinstance(item,mod._Module):
0025         list.append(item)
0026     elif isinstance(item,cms.Sequence):
0027          getModulesFromSequence(item,list)
0028     else:
0029          _getModulesFromOp(item,list)
0030                                                     
0031 
0032 def _getModulesFromOp(op,list):
0033     for item in dir(op):
0034         o = getattr(op,item)
0035         if isinstance(o,mod._Module):
0036             list.append(o)
0037         elif isinstance(o, cms.Sequence):
0038             _getModulesFromOp(o,list)
0039         elif isinstance(o,sqt._Sequenceable):
0040             _getModulesFromOp(o,list)
0041                     
0042 
0043 def extractUsedOutputs(process):
0044     allEndPathModules = []
0045     for name in process._Process__endpaths:
0046         endpath = getattr(process,name)
0047         list = []
0048         getModulesFromSequence(endpath,list)
0049         allEndPathModules.extend(list)
0050     allUsedOutputModules = []
0051     for module in allEndPathModules:
0052         if isinstance(module, cms.OutputModule):
0053             allUsedOutputModules.append(module)
0054     return allUsedOutputModules
0055 
0056 
0057 
0058 ##########################
0059 if __name__ == "__main__":
0060 
0061     if len(sys.argv) < 2:
0062         print("usage: testSkimConfig <filenames>")
0063 
0064     for scriptName in sys.argv[1:]:      
0065         print("Checking skim config file", scriptName)
0066 
0067         process = cms.include(scriptName)
0068         #print "+ python parseable"
0069     
0070         print("checking", len (process._Process__outputmodules), "output modules")
0071         for outputModuleName in process._Process__outputmodules:
0072             print("  ", outputModuleName)
0073             outputModule = getattr(process, outputModuleName)
0074             checkOutputModuleConfig(outputModule)
0075 
0076         usedOutputs = extractUsedOutputs(process)
0077         print("Actually used: ", len(usedOutputs))
0078         for module in usedOutputs:
0079             print("  ", module.label())