New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve early delete configuration in ConfigBuilder #16779
Merged
davidlange6
merged 4 commits into
cms-sw:CMSSW_9_0_X
from
makortel:configBuilderEarlyDelete
Dec 7, 2016
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0641130
Improve maintainability of 'early delete' in ConfigBuilder
makortel 9302986
Add support for refToPSet_ and add a unit test
makortel 006cb19
Extend unit test to cover untracked.InputTag
makortel 8808614
Remove 'RECO' from the customize function name
makortel File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 110 additions & 1 deletion
111
Configuration/StandardSequences/python/earlyDeleteSettings_cff.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,116 @@ | ||
# Abstract all early deletion settings here | ||
|
||
import collections | ||
|
||
import FWCore.ParameterSet.Config as cms | ||
|
||
from RecoTracker.Configuration.customiseEarlyDeleteForSeeding import customiseEarlyDeleteForSeeding | ||
|
||
def _hasInputTagModuleLabel(process, pset, moduleLabel): | ||
for name in pset.parameterNames_(): | ||
value = getattr(pset,name) | ||
if isinstance(value, cms.PSet): | ||
if _hasInputTagModuleLabel(process, value, moduleLabel): | ||
return True | ||
elif isinstance(value, cms.VPSet): | ||
for ps in value: | ||
if _hasInputTagModuleLabel(process, ps, moduleLabel): | ||
return True | ||
elif isinstance(value, cms.VInputTag): | ||
for t in value: | ||
t2 = t | ||
if not isinstance(t, cms.InputTag): | ||
t2 = cms.InputTag(t2) | ||
if t2.getModuleLabel() == moduleLabel: | ||
return True | ||
elif isinstance(value, cms.InputTag): | ||
if value.getModuleLabel() == moduleLabel: | ||
return True | ||
if isinstance(value, cms.string) and name == "refToPSet_": | ||
return _hasInputTagModuleLabel(process, getattr(process, value.value()), moduleLabel) | ||
return False | ||
|
||
def customiseEarlyDeleteForRECO(process): | ||
process = customiseEarlyDeleteForSeeding(process) | ||
# Mapping label -> [branches] | ||
# for the producers whose products are to be deleted early | ||
products = collections.defaultdict(list) | ||
|
||
products = customiseEarlyDeleteForSeeding(process, products) | ||
|
||
# Set process.options.canDeleteEarly | ||
if not hasattr(process.options, "canDeleteEarly"): | ||
process.options.canDeleteEarly = cms.untracked.vstring() | ||
|
||
branchSet = set() | ||
for branches in products.itervalues(): | ||
for branch in branches: | ||
branchSet.add(branch) | ||
process.options.canDeleteEarly.extend(list(branchSet)) | ||
|
||
# Find the consumers | ||
for moduleType in [process.producers_(), process.filters_(), process.analyzers_()]: | ||
for name, module in moduleType.iteritems(): | ||
for producer, branches in products.iteritems(): | ||
if _hasInputTagModuleLabel(process, module, producer): | ||
#print "Module %s mightGet %s" % (name, str(branches)) | ||
if hasattr(module, "mightGet"): | ||
module.mightGet.extend(branches) | ||
else: | ||
module.mightGet = cms.untracked.vstring(branches) | ||
return process | ||
|
||
|
||
if __name__=="__main__": | ||
import unittest | ||
|
||
class TestHasInputTagModuleLabel(unittest.TestCase): | ||
def setUp(self): | ||
"""Nothing to do """ | ||
None | ||
def testHasInputTagModuleLabel(self): | ||
p = cms.Process("A") | ||
p.pset = cms.PSet(a=cms.InputTag("a"),a2=cms.untracked.InputTag("a2")) | ||
p.prod = cms.EDProducer("Producer", | ||
foo = cms.InputTag("foo"), | ||
foo2 = cms.InputTag("foo2", "instance"), | ||
foo3 = cms.InputTag("foo3", "instance", "PROCESS"), | ||
foo4 = cms.untracked.InputTag("foo4"), | ||
nested = cms.PSet( | ||
bar = cms.InputTag("bar"), | ||
bar2 = cms.untracked.InputTag("bar2"), | ||
), | ||
nested2 = cms.untracked.PSet( | ||
bar3 = cms.untracked.InputTag("bar3"), | ||
), | ||
flintstones = cms.VPSet( | ||
cms.PSet(fred=cms.InputTag("fred")), | ||
cms.PSet(wilma=cms.InputTag("wilma")) | ||
), | ||
flintstones2 = cms.VPSet( | ||
cms.PSet(fred2=cms.untracked.InputTag("fred2")), | ||
cms.PSet(wilma2=cms.InputTag("wilma2")) | ||
), | ||
ref = cms.PSet( | ||
refToPSet_ = cms.string("pset") | ||
), | ||
ref2 = cms.untracked.PSet( | ||
refToPSet_ = cms.string("pset") | ||
), | ||
) | ||
|
||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "foo")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "foo2")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "foo3")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "bar")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "fred")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "wilma")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "a")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "foo4")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "bar2")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "bar3")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "fred2")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "wilma2")) | ||
self.assert_(_hasInputTagModuleLabel(p, p.prod, "a2")) | ||
self.assert_(not _hasInputTagModuleLabel(p, p.prod, "joe")) | ||
|
||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since "if RECO" is removed, it's worth changing this to "customiseEarlyDelete" without "ForRECO"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I thought it at some point but (apparently) forgot.