Skip to content
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

Make duplicate branch check work properly with SwitchProducer that has EDAlias case #40136

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 3 additions & 7 deletions FWCore/Framework/src/ProductSelector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,10 @@ namespace edm {
<< "Please drop at least one of them.\n";
}
};
BranchID const& trueBranchID = desc.originalBranchID();
// In case of SwitchProducer, we have to check the aliased-for
// BranchID for the case that the chosen case is an EDAlias
BranchID const& trueBranchID = desc.isSwitchAlias() ? desc.switchAliasForBranchID() : desc.originalBranchID();
check(trueBranchID);
// In case of SwitchProducer, we have to check also the
// aliased-for BranchID for the case that the chosen case is an EDAlias
if (desc.isSwitchAlias()) {
check(desc.switchAliasForBranchID());
}

trueBranchIDToKeptBranchDesc.insert(std::make_pair(trueBranchID, &desc));
}
}
Expand Down
12 changes: 6 additions & 6 deletions FWCore/Integration/test/run_TestSwitchProducer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ pushd ${LOCAL_TMP_DIR}

echo "*************************************************"
echo "SwitchProducer in a Task"
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py || die "cmsRun ${test}Task_cfg.py 1" $?
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py || die "cmsRun ${test}Task_cfg.py" $?

echo "*************************************************"
echo "SwitchProducer in a Task, case test2 disabled"
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py disableTest2 || die "cmsRun ${test}Task_cfg.py 2" $?
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py -- --disableTest2 || die "cmsRun ${test}Task_cfg.py -- --disableTest2" $?

echo "*************************************************"
echo "SwitchProducer in a Task, SwitchProducers have same labels as products in input file"
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}TaskInput_cfg.py || die "cmsRun ${test}TaskInput_cfg.py 1" $?
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py -- --input|| die "cmsRun ${test}Task_cfg.py -- --input" $?

echo "*************************************************"
echo "SwitchProducer in a Task, SwitchProducers have same labels as products in input file, case test2 disabled"
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}TaskInput_cfg.py disableTest2 || die "cmsRun ${test}TaskInput_cfg.py 2" $?
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py -- --input --disableTest2 || die "cmsRun ${test}TaskInput_cfg.py -- --input --disableTest2" $?

echo "*************************************************"
echo "Merge outputs (Task)"
Expand All @@ -43,11 +43,11 @@ pushd ${LOCAL_TMP_DIR}

echo "*************************************************"
echo "SwitchProducer in a ConditionalTask"
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}ConditionalTask_cfg.py || die "cmsRun ${test}ConditionalTask_cfg.py 1" $?
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py -- --conditionalTask || die "cmsRun ${test}Task_cfg.py -- --conditionalTask" $?

echo "*************************************************"
echo "SwitchProducer in a ConditionalTask, case test2 disabled"
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}ConditionalTask_cfg.py disableTest2 || die "cmsRun ${test}ConditionalTask_cfg.py 2" $?
cmsRun -n ${NUMTHREADS} ${LOCAL_TEST_DIR}/${test}Task_cfg.py -- --conditionalTask --disableTest2 || die "cmsRun ${test}Task_cfg.py -- --conditionalTask --disableTest2" $?

echo "*************************************************"
echo "Merge outputs (ConditionalTask)"
Expand Down
75 changes: 0 additions & 75 deletions FWCore/Integration/test/testSwitchProducerConditionalTask_cfg.py

This file was deleted.

78 changes: 0 additions & 78 deletions FWCore/Integration/test/testSwitchProducerTaskInput_cfg.py

This file was deleted.

61 changes: 46 additions & 15 deletions FWCore/Integration/test/testSwitchProducerTask_cfg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import FWCore.ParameterSet.Config as cms

import argparse
import sys
enableTest2 = (sys.argv[-1] != "disableTest2")

parser = argparse.ArgumentParser(prog=sys.argv[0], description='Test SwitchProducer in Task.')
parser.add_argument("--disableTest2", help="Disable test2 SwitchProducer case", action="store_true")
parser.add_argument("--input", help="Read input file from a previous step of this same configuration", action="store_true")
parser.add_argument("--conditionalTask", help="Use ConditionalTask instead of Task", action="store_true")

argv = sys.argv[:]
if '--' in argv:
argv.remove("--")
args, unknown = parser.parse_known_args(argv)

enableTest2 = not args.disableTest2
class SwitchProducerTest(cms.SwitchProducer):
def __init__(self, **kargs):
super(SwitchProducerTest,self).__init__(
Expand All @@ -10,18 +22,30 @@ def __init__(self, **kargs):
test2 = lambda accelerators: (enableTest2, -9)
), **kargs)

process = cms.Process("PROD1")

process.source = cms.Source("EmptySource")
if enableTest2:
process.source.firstLuminosityBlock = cms.untracked.uint32(2)
process = cms.Process("PROD2" if args.input else "PROD1")

process.maxEvents = cms.untracked.PSet(
input = cms.untracked.int32(3)
)
if args.input:
# Test that having SwitchProducers with same labels as products from
# earlier processes works
process.source = cms.Source("PoolSource",
fileNames = cms.untracked.vstring("file:testSwitchProducer{}Task{}.root".format(
"Conditional" if args.conditionalTask else "",
1 if enableTest2 else 2,
))
)
process.maxEvents.input = -1
else:
process.source = cms.Source("EmptySource")
process.maxEvents.input = 3
if enableTest2:
process.source.firstLuminosityBlock = cms.untracked.uint32(2)

process.out = cms.OutputModule("PoolOutputModule",
fileName = cms.untracked.string('testSwitchProducerTask%d.root' % (1 if enableTest2 else 2,)),
fileName = cms.untracked.string('testSwitchProducer{}Task{}{}.root'.format(
"Conditional" if args.conditionalTask else "",
"Input" if args.input else "",
1 if enableTest2 else 2,
)),
outputCommands = cms.untracked.vstring(
'keep *_intProducer_*_*',
'keep *_intProducerOther_*_*',
Expand All @@ -37,11 +61,13 @@ def __init__(self, **kargs):
process.intProducer2 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(2))
process.intProducer3 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(2), values = cms.VPSet(cms.PSet(instance=cms.string("foo"),value=cms.int32(2))))
process.intProducer4 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(42), throw = cms.untracked.bool(True))
process.intProducer5 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(3), values = cms.VPSet(cms.PSet(instance=cms.string("foo"),value=cms.int32(3))))
if enableTest2:
process.intProducer1.throw = cms.untracked.bool(True)
else:
process.intProducer2.throw = cms.untracked.bool(True)
process.intProducer3.throw = cms.untracked.bool(True)
process.intProducer5.throw = cms.untracked.bool(True)

process.intProducer = SwitchProducerTest(
test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
Expand All @@ -62,17 +88,22 @@ def __init__(self, **kargs):
process.intProducerAlias2 = SwitchProducerTest(
test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")),
test2 = cms.EDAlias(intProducer4 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string(""), toProductInstance = cms.string(""))),
intProducer3 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string("foo"), toProductInstance = cms.string("other"))))
intProducer5 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string("foo"), toProductInstance = cms.string("other"))))
)

# Test multiple consumers of a SwitchProducer
process.intProducerDep1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))
process.intProducerDep2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))
process.intProducerDep3 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer"))

process.t = cms.Task(process.intProducer, process.intProducerOther, process.intProducerAlias, process.intProducerAlias2,
process.intProducerDep1, process.intProducerDep2, process.intProducerDep3,
process.intProducer1, process.intProducer2, process.intProducer3, process.intProducer4)
process.p = cms.Path(process.t)
if args.conditionalTask:
process.ct = cms.ConditionalTask(process.intProducer, process.intProducerOther, process.intProducerAlias, process.intProducerAlias2,
process.intProducer1, process.intProducer2, process.intProducer3, process.intProducer4, process.intProducer5)
process.p = cms.Path(process.intProducerDep1+process.intProducerDep2+process.intProducerDep3, process.ct)
else:
process.t = cms.Task(process.intProducer, process.intProducerOther, process.intProducerAlias, process.intProducerAlias2,
process.intProducerDep1, process.intProducerDep2, process.intProducerDep3,
process.intProducer1, process.intProducer2, process.intProducer3, process.intProducer4, process.intProducer5)
process.p = cms.Path(process.t)

process.e = cms.EndPath(process.out)