File indexing completed on 2022-02-21 23:13:41
0001
0002
0003 import collections
0004
0005 import FWCore.ParameterSet.Config as cms
0006
0007 from RecoTracker.Configuration.customiseEarlyDeleteForSeeding import customiseEarlyDeleteForSeeding
0008 from RecoTracker.Configuration.customiseEarlyDeleteForMkFit import customiseEarlyDeleteForMkFit
0009 from RecoTracker.Configuration.customiseEarlyDeleteForCKF import customiseEarlyDeleteForCKF
0010 from CommonTools.ParticleFlow.Isolation.customiseEarlyDeleteForCandIsoDeposits import customiseEarlyDeleteForCandIsoDeposits
0011
0012 def _hasInputTagModuleLabel(process, pset, psetModLabel, moduleLabels, result):
0013 for name in pset.parameterNames_():
0014 value = getattr(pset,name)
0015 if isinstance(value, cms.PSet):
0016 _hasInputTagModuleLabel(process, value, psetModLabel, moduleLabels, result)
0017 elif isinstance(value, cms.VPSet):
0018 for ps in value:
0019 _hasInputTagModuleLabel(process, ps, psetModLabel, moduleLabels, result)
0020 elif isinstance(value, cms.VInputTag):
0021 for t in value:
0022 t2 = t
0023 if not isinstance(t, cms.InputTag):
0024 t2 = cms.InputTag(t2)
0025 for i,moduleLabel in enumerate(moduleLabels):
0026 if result[i]: continue
0027 if t2.getModuleLabel() == moduleLabel:
0028 result[i]=True
0029 elif isinstance(value, cms.InputTag):
0030 for i,moduleLabel in enumerate(moduleLabels):
0031 if result[i]: continue
0032 if value.getModuleLabel() == moduleLabel:
0033 result[i]=True
0034 elif isinstance(value, cms.string) and name == "refToPSet_":
0035 try:
0036 ps = getattr(process, value.value())
0037 except AttributeError:
0038 raise RuntimeError("Module %s has a 'PSet(refToPSet_ = cms.string(\"%s\"))', but the referenced-to PSet does not exist in the Process." % (psetModLabel, value.value()))
0039 _hasInputTagModuleLabel(process, ps, psetModLabel, moduleLabels, result)
0040
0041
0042 def customiseEarlyDelete(process):
0043
0044
0045 products = collections.defaultdict(list)
0046
0047 products = customiseEarlyDeleteForSeeding(process, products)
0048 products = customiseEarlyDeleteForMkFit(process, products)
0049 products = customiseEarlyDeleteForCKF(process, products)
0050
0051 products = customiseEarlyDeleteForCandIsoDeposits(process, products)
0052
0053
0054 if not hasattr(process.options, "canDeleteEarly"):
0055 process.options.canDeleteEarly = cms.untracked.vstring()
0056
0057 branchSet = set()
0058 for branches in products.values():
0059 for branch in branches:
0060 branchSet.add(branch)
0061 branchList = sorted(branchSet)
0062 process.options.canDeleteEarly.extend(branchList)
0063
0064
0065 for prod in process.producers_().values():
0066 if prod.type_() == "LogErrorHarvester":
0067 if not hasattr(prod,'excludeModules'):
0068 prod.excludeModules = cms.untracked.vstring()
0069 t = prod.excludeModules.value()
0070 t.extend([b.split('_')[1] for b in branchList])
0071 prod.excludeModules = t
0072
0073
0074 producers=[]
0075 branchesList=[]
0076 for producer, branches in products.items():
0077 producers.append(producer)
0078 branchesList.append(branches)
0079
0080 for moduleType in [process.producers_(), process.filters_(), process.analyzers_()]:
0081 for name, module in moduleType.items():
0082 result=[]
0083 for producer in producers:
0084 result.append(False)
0085
0086 _hasInputTagModuleLabel(process, module, name, producers, result)
0087 for i in range(len(result)):
0088 if result[i]:
0089
0090 if hasattr(module, "mightGet") and module.mightGet:
0091 module.mightGet.extend(branchesList[i])
0092 else:
0093 module.mightGet = cms.untracked.vstring(branchesList[i])
0094 return process
0095
0096
0097 if __name__=="__main__":
0098 import unittest
0099
0100 class TestHasInputTagModuleLabel(unittest.TestCase):
0101 def setUp(self):
0102 """Nothing to do """
0103 None
0104 def testHasInputTagModuleLabel(self):
0105 p = cms.Process("A")
0106 p.pset = cms.PSet(a=cms.InputTag("a"),a2=cms.untracked.InputTag("a2"))
0107 p.prod = cms.EDProducer("Producer",
0108 foo = cms.InputTag("foo"),
0109 foo2 = cms.InputTag("foo2", "instance"),
0110 foo3 = cms.InputTag("foo3", "instance", "PROCESS"),
0111 foo4 = cms.untracked.InputTag("foo4"),
0112 nested = cms.PSet(
0113 bar = cms.InputTag("bar"),
0114 bar2 = cms.untracked.InputTag("bar2"),
0115 ),
0116 nested2 = cms.untracked.PSet(
0117 bar3 = cms.untracked.InputTag("bar3"),
0118 ),
0119 flintstones = cms.VPSet(
0120 cms.PSet(fred=cms.InputTag("fred")),
0121 cms.PSet(wilma=cms.InputTag("wilma"))
0122 ),
0123 flintstones2 = cms.VPSet(
0124 cms.PSet(fred2=cms.untracked.InputTag("fred2")),
0125 cms.PSet(wilma2=cms.InputTag("wilma2"))
0126 ),
0127 ref = cms.PSet(
0128 refToPSet_ = cms.string("pset")
0129 ),
0130 ref2 = cms.untracked.PSet(
0131 refToPSet_ = cms.string("pset")
0132 ),
0133 )
0134 p.prod2 = cms.EDProducer("Producer2",
0135 foo = cms.PSet(
0136 refToPSet_ = cms.string("nonexistent")
0137 )
0138 )
0139
0140 result=[False,False,False,False,False,False,False,False,False,False,False,False,False,False]
0141 _hasInputTagModuleLabel(p, p.prod, "prod", ["foo","foo2","foo3","bar","fred","wilma","a","foo4","bar2","bar3","fred2","wilma2","a2","joe"], result)
0142 for i in range (0,13):
0143 self.assert_(result[i])
0144 self.assert_(not result[13])
0145
0146 result = [False]
0147 self.assertRaises(RuntimeError, _hasInputTagModuleLabel, p, p.prod2, "prod2", ["foo"], result)
0148
0149 unittest.main()