diff --git a/FWCore/Framework/src/ProductSelector.cc b/FWCore/Framework/src/ProductSelector.cc index ccb622ca1573b..388303e0401e5 100644 --- a/FWCore/Framework/src/ProductSelector.cc +++ b/FWCore/Framework/src/ProductSelector.cc @@ -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)); } } diff --git a/FWCore/Integration/test/run_TestSwitchProducer.sh b/FWCore/Integration/test/run_TestSwitchProducer.sh index 55e78493a7d2f..909413dffb960 100755 --- a/FWCore/Integration/test/run_TestSwitchProducer.sh +++ b/FWCore/Integration/test/run_TestSwitchProducer.sh @@ -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)" @@ -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)" diff --git a/FWCore/Integration/test/testSwitchProducerConditionalTask_cfg.py b/FWCore/Integration/test/testSwitchProducerConditionalTask_cfg.py deleted file mode 100644 index 5a4d6b23e1cb8..0000000000000 --- a/FWCore/Integration/test/testSwitchProducerConditionalTask_cfg.py +++ /dev/null @@ -1,75 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -import sys -enableTest2 = (sys.argv[-1] != "disableTest2") -class SwitchProducerTest(cms.SwitchProducer): - def __init__(self, **kargs): - super(SwitchProducerTest,self).__init__( - dict( - test1 = lambda accelerators: (True, -10), - 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.maxEvents.input = 3 - -process.out = cms.OutputModule("PoolOutputModule", - fileName = cms.untracked.string('testSwitchProducerConditionalTask%d.root' % (1 if enableTest2 else 2,)), - outputCommands = cms.untracked.vstring( - 'keep *_intProducer_*_*', - 'keep *_intProducerOther_*_*', - 'keep *_intProducerAlias_*_*', - 'keep *_intProducerAlias2_other_*', - 'keep *_intProducerDep1_*_*', - 'keep *_intProducerDep2_*_*', - 'keep *_intProducerDep3_*_*', - ) -) - -process.intProducer1 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(1)) -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)) -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.intProducer = SwitchProducerTest( - test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")), - test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2")) -) -# Test also existence of another SwitchProducer here -process.intProducerOther = SwitchProducerTest( - test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")), - test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2")) -) -# SwitchProducer with an alias -process.intProducerAlias = SwitchProducerTest( - test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")), - test2 = cms.EDAlias(intProducer3 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string(""), toProductInstance = cms.string("")), - cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string("foo"), toProductInstance = cms.string("other")))) -) - -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")))) -) - -# 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.ct = cms.ConditionalTask(process.intProducer, process.intProducerOther, process.intProducerAlias, process.intProducerAlias2, - process.intProducer1, process.intProducer2, process.intProducer3, process.intProducer4) -process.p = cms.Path(process.intProducerDep1+process.intProducerDep2+process.intProducerDep3, process.ct) - -process.e = cms.EndPath(process.out) diff --git a/FWCore/Integration/test/testSwitchProducerTaskInput_cfg.py b/FWCore/Integration/test/testSwitchProducerTaskInput_cfg.py deleted file mode 100644 index dd9438c6eebbc..0000000000000 --- a/FWCore/Integration/test/testSwitchProducerTaskInput_cfg.py +++ /dev/null @@ -1,78 +0,0 @@ -import FWCore.ParameterSet.Config as cms - -import sys -enableTest2 = (sys.argv[-1] != "disableTest2") -class SwitchProducerTest(cms.SwitchProducer): - def __init__(self, **kargs): - super(SwitchProducerTest,self).__init__( - dict( - test1 = lambda accelerators: (True, -10), - test2 = lambda accelerators: (enableTest2, -9) - ), **kargs) - -process = cms.Process("PROD2") - -# Test that having SwitchProducers with same labels as products from -# earlier processes works -process.source = cms.Source("PoolSource", - fileNames = cms.untracked.vstring("file:testSwitchProducerTask%d.root" % (1 if enableTest2 else 2,)) -) - -process.maxEvents.input = -1 - -process.out = cms.OutputModule("PoolOutputModule", - fileName = cms.untracked.string('testSwitchProducerTaskInput%d.root' % (1 if enableTest2 else 2,)), - outputCommands = cms.untracked.vstring( - 'keep *_intProducer_*_*', - 'keep *_intProducerOther_*_*', - 'keep *_intProducerAlias_*_*', - 'keep *_intProducerAlias2_other_*', - 'keep *_intProducerDep1_*_*', - 'keep *_intProducerDep2_*_*', - 'keep *_intProducerDep3_*_*', - ) -) - -process.intProducer1 = cms.EDProducer("ManyIntProducer", ivalue = cms.int32(1)) -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)) -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.intProducer = SwitchProducerTest( - test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")), - test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2")) -) -# Test also existence of another SwitchProducer here -process.intProducerOther = SwitchProducerTest( - test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")), - test2 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer2")) -) -# SwitchProducer with an alias -process.intProducerAlias = SwitchProducerTest( - test1 = cms.EDProducer("AddIntsProducer", labels = cms.VInputTag("intProducer1")), - test2 = cms.EDAlias(intProducer3 = cms.VPSet(cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string(""), toProductInstance = cms.string("")), - cms.PSet(type = cms.string("edmtestIntProduct"), fromProductInstance = cms.string("foo"), toProductInstance = cms.string("other")))) -) - -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")))) -) - -# 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) - -process.e = cms.EndPath(process.out) diff --git a/FWCore/Integration/test/testSwitchProducerTask_cfg.py b/FWCore/Integration/test/testSwitchProducerTask_cfg.py index 731568a4ed257..83ff028752ef4 100644 --- a/FWCore/Integration/test/testSwitchProducerTask_cfg.py +++ b/FWCore/Integration/test/testSwitchProducerTask_cfg.py @@ -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__( @@ -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_*_*', @@ -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")), @@ -62,7 +88,7 @@ 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 @@ -70,9 +96,14 @@ def __init__(self, **kargs): 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)