From c068623c36fee29a652ffe8b0ec877a0861b388b Mon Sep 17 00:00:00 2001 From: "W. David Dagenhart" Date: Wed, 17 Jun 2015 15:46:17 -0500 Subject: [PATCH] Bug fix. Add function to get top level PSet Add a new function that allows one to get a top level ParameterSet by passing in a ModuleDescription which is available in all modules. This is the Core part of the changes needed to fix modules that were using the old getProcessParameterSet function. This depends on a single global static ParameterSetID. It fails when used in SubProcesses would return the ParameterSet for the wrong process/SubProcess. The bug only affects jobs with SubProcesses. This global was also problematic for multithreading (had to be protected with a mutex). More changes will follow this to convert all uses of the old function to an alternative and then eventually to delete it. Merging this PR quickly will make it easier to test the others quickly. --- FWCore/Framework/test/stubs/HistoryAnalyzer.cc | 11 +++++++++++ .../Integration/test/EventHistory_SubProcess_cfg.py | 10 ++++++++++ FWCore/ParameterSet/interface/ParameterSet.h | 4 ++++ FWCore/ParameterSet/src/ParameterSet.cc | 13 ++++++++++--- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/FWCore/Framework/test/stubs/HistoryAnalyzer.cc b/FWCore/Framework/test/stubs/HistoryAnalyzer.cc index dd3a25aa68459..e568f650c45ce 100644 --- a/FWCore/Framework/test/stubs/HistoryAnalyzer.cc +++ b/FWCore/Framework/test/stubs/HistoryAnalyzer.cc @@ -86,6 +86,17 @@ namespace edmtest { edm::ParameterSet proc_pset; event.getProcessParameterSet(event.processHistory().rbegin()->processName(),proc_pset); + { + // test the function getProcessParameterSetContainingModule this is a + // convenient spot to test because this module is run in both a + // a single process and in a subprocess. + edm::ParameterSet proc_pset2 = edm::getProcessParameterSetContainingModule(moduleDescription()); + assert(proc_pset2.id() == proc_pset.id()); + vstring paths1 = proc_pset.getParameter("@paths"); + vstring paths2 = proc_pset2.getParameter("@paths"); + assert(paths1 == paths2); + } + edm::pset::Registry* reg = edm::pset::Registry::instance(); if (!expectedPaths_.empty()) { diff --git a/FWCore/Integration/test/EventHistory_SubProcess_cfg.py b/FWCore/Integration/test/EventHistory_SubProcess_cfg.py index 9045b2b494173..f3d9497926818 100644 --- a/FWCore/Integration/test/EventHistory_SubProcess_cfg.py +++ b/FWCore/Integration/test/EventHistory_SubProcess_cfg.py @@ -260,3 +260,13 @@ process6.ep61 = cms.EndPath(process6.out) process6.ep62 = cms.EndPath(process6.producerOnEndPath*process6.filterOnEndPath*process6.out*process6.historytest) process6.ep63 = cms.EndPath(process6.analyzerOnEndPath*process6.out2*process6.out) + +process7 = cms.Process("SEVENTH") + +process6.subProcess = cms.SubProcess(process7) + +process7.dummyproducerxxx = cms.EDProducer("IntProducer", + ivalue = cms.int32(2) +) + +process7.p1 = cms.Path(process7.dummyproducerxxx) diff --git a/FWCore/ParameterSet/interface/ParameterSet.h b/FWCore/ParameterSet/interface/ParameterSet.h index 84503329daafc..a83e87382795a 100644 --- a/FWCore/ParameterSet/interface/ParameterSet.h +++ b/FWCore/ParameterSet/interface/ParameterSet.h @@ -30,6 +30,7 @@ namespace cms { } namespace edm { + class ModuleDescription; typedef std::vector VParameterSet; class ParameterSet { @@ -335,6 +336,9 @@ namespace edm { ParameterSet const& getParameterSet(ParameterSetID const& id); + ParameterSet const& + getProcessParameterSetContainingModule(ModuleDescription const& moduleDescription); + // specializations // ---------------------------------------------------------------------- diff --git a/FWCore/ParameterSet/src/ParameterSet.cc b/FWCore/ParameterSet/src/ParameterSet.cc index a562219ed5fd0..cf8f79c0817ae 100644 --- a/FWCore/ParameterSet/src/ParameterSet.cc +++ b/FWCore/ParameterSet/src/ParameterSet.cc @@ -16,6 +16,8 @@ #include "FWCore/Utilities/interface/Digest.h" #include "FWCore/Utilities/interface/EDMException.h" +#include "DataFormats/Provenance/interface/ModuleDescription.h" + #include #include #include @@ -951,14 +953,19 @@ namespace edm { // Free function to return a parameterSet given its ID. ParameterSet const& getParameterSet(ParameterSetID const& id) { - ParameterSet const* result = 0; - if(0 == (result = pset::Registry::instance()->getMapped(id))) { - throw Exception(errors::Configuration, "MissingParameterSet:") + ParameterSet const* result = nullptr; + if(nullptr == (result = pset::Registry::instance()->getMapped(id))) { + throw Exception(errors::LogicError, "MissingParameterSet:") << "Parameter Set ID '" << id << "' not found."; } return *result; } + ParameterSet const& + getProcessParameterSetContainingModule(ModuleDescription const& moduleDescription) { + return getParameterSet(moduleDescription.mainParameterSetID()); + } + void ParameterSet::deprecatedInputTagWarning(std::string const& name, std::string const& label) const { LogWarning("Configuration") << "Warning:\n\tstring " << name