diff --git a/FWCore/Framework/bin/cmsRun.cpp b/FWCore/Framework/bin/cmsRun.cpp index 76eb411df5947..00ad06ed62f5b 100644 --- a/FWCore/Framework/bin/cmsRun.cpp +++ b/FWCore/Framework/bin/cmsRun.cpp @@ -306,12 +306,15 @@ int main(int argc, char* argv[]) { { if(not setNThreadsOnCommandLine) { std::shared_ptr pset = processDesc->getProcessPSet(); - if(pset->existsAs("options",false)) { + // Note: it is important to not check the type or trackedness in + // exists() call to ensure that the getUntrackedParameter() calls + // will fail if the parameters have an incorrect type + if(pset->exists("options")) { auto const& ops = pset->getUntrackedParameterSet("options"); - if(ops.existsAs("numberOfThreads",false)) { + if(ops.exists("numberOfThreads")) { unsigned int nThreads = ops.getUntrackedParameter("numberOfThreads"); unsigned int stackSize=kDefaultSizeOfStackForThreadsInKB; - if(ops.existsAs("sizeOfStackForThreadsInKB",false)) { + if(ops.exists("sizeOfStackForThreadsInKB")) { stackSize = ops.getUntrackedParameter("sizeOfStackForThreadsInKB"); } const auto nThreadsUsed = setNThreads(nThreads,stackSize,tsiPtr); @@ -326,7 +329,7 @@ int main(int argc, char* argv[]) { //inject it into the top level ParameterSet edm::ParameterSet newOp; std::shared_ptr pset = processDesc->getProcessPSet(); - if(pset->existsAs("options",false)) { + if(pset->exists("options")) { newOp = pset->getUntrackedParameterSet("options"); } newOp.addUntrackedParameter("numberOfThreads",nThreadsOnCommandLine); diff --git a/FWCore/Framework/src/EventProcessor.cc b/FWCore/Framework/src/EventProcessor.cc index 35d9ba53affb0..2caf93af0307d 100644 --- a/FWCore/Framework/src/EventProcessor.cc +++ b/FWCore/Framework/src/EventProcessor.cc @@ -404,7 +404,7 @@ namespace edm { forceESCacheClearOnNewRun_ = optionsPset.getUntrackedParameter("forceEventSetupCacheClearOnNewRun", false); //threading unsigned int nThreads=1; - if(optionsPset.existsAs("numberOfThreads",false)) { + if(optionsPset.exists("numberOfThreads")) { nThreads = optionsPset.getUntrackedParameter("numberOfThreads"); if(nThreads == 0) { nThreads = 1; @@ -414,7 +414,7 @@ namespace edm { unsigned int nStreams =nThreads; */ unsigned int nStreams =1; - if(optionsPset.existsAs("numberOfStreams",false)) { + if(optionsPset.exists("numberOfStreams")) { nStreams = optionsPset.getUntrackedParameter("numberOfStreams"); if(nStreams==0) { nStreams = nThreads; diff --git a/FWCore/Framework/test/BuildFile.xml b/FWCore/Framework/test/BuildFile.xml index affc4a13d3913..23c4c30488759 100644 --- a/FWCore/Framework/test/BuildFile.xml +++ b/FWCore/Framework/test/BuildFile.xml @@ -315,3 +315,8 @@ + + + + + diff --git a/FWCore/Framework/test/run_wrongOptionsType.sh b/FWCore/Framework/test/run_wrongOptionsType.sh new file mode 100755 index 0000000000000..9e929cac18360 --- /dev/null +++ b/FWCore/Framework/test/run_wrongOptionsType.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +NAME=$1 +VALUE=$2 + +function die { echo $1: status $2 ; echo === Log file === ; cat ${3:-/dev/null} ; echo === End log file === ; exit $2; } + +cmsRun ${LOCALTOP}/src/FWCore/Framework/test/test_wrongOptionsType_cfg.py -- --name=${NAME} --value="$VALUE" > ${NAME}.log 2>&1 && die "cmsRun for ${NAME} succeeded, should have failed" 1 ${NAME}.log +grep -E "(The type in the configuration is incorrect)|(ValueError type of .* is expected to be .* but declared as)" ${NAME}.log > /dev/null || die "cmsRun for ${NAME} failed for other reason than incorrect configuration type" $? ${NAME}.log + diff --git a/FWCore/Framework/test/test_wrongOptionsType_cfg.py b/FWCore/Framework/test/test_wrongOptionsType_cfg.py new file mode 100644 index 0000000000000..07449b67fc72b --- /dev/null +++ b/FWCore/Framework/test/test_wrongOptionsType_cfg.py @@ -0,0 +1,23 @@ +import FWCore.ParameterSet.Config as cms + +import argparse +import sys + +parser = argparse.ArgumentParser(prog=sys.argv[0], description='Test wrong process.options parameter types') + +parser.add_argument("--name", help="Name of parameter", type=str) +parser.add_argument("--value", help="Value of the parameter", type=str) + +argv = sys.argv[:] +if '--' in argv: + argv.remove("--") +args, unknown = parser.parse_known_args(argv) + +process = cms.Process("TEST") +process.source = cms.Source("EmptySource") + +process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(2)) + +# sizeOfStackForThreadsInKB is checked only if numberOfThreads is set +process.options = cms.untracked.PSet(numberOfThreads = cms.untracked.int32(1)) +setattr(process.options, args.name, eval(str(args.value)))