File indexing completed on 2025-03-13 02:31:54
0001
0002 #include "FWCore/Framework/interface/maker/WorkerMaker.h"
0003 #include "FWCore/Framework/interface/SignallingProductRegistryFiller.h"
0004 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0005 #include "FWCore/ParameterSet/interface/Registry.h"
0006 #include "DataFormats/Provenance/interface/ModuleDescription.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/Utilities/interface/ConvertException.h"
0009 #include "FWCore/Utilities/interface/Exception.h"
0010 #include "FWCore/Utilities/interface/EDMException.h"
0011 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0012
0013 #include <sstream>
0014 #include <exception>
0015 namespace edm {
0016
0017 Maker::~Maker() {}
0018
0019 ModuleDescription Maker::createModuleDescription(MakeModuleParams const& p) const {
0020 ParameterSet const& conf = *p.pset_;
0021 ModuleDescription md(conf.id(),
0022 conf.getParameter<std::string>("@module_type"),
0023 conf.getParameter<std::string>("@module_label"),
0024 p.processConfiguration_.get(),
0025 ModuleDescription::getUniqueID());
0026 return md;
0027 }
0028
0029 void Maker::throwValidationException(MakeModuleParams const& p, cms::Exception& iException) const {
0030 ParameterSet const& conf = *p.pset_;
0031 std::string moduleName = conf.getParameter<std::string>("@module_type");
0032 std::string moduleLabel = conf.getParameter<std::string>("@module_label");
0033
0034 std::ostringstream ost;
0035 ost << "Validating configuration of module: class=" << moduleName << " label='" << moduleLabel << "'";
0036 iException.addContext(ost.str());
0037 throw;
0038 }
0039
0040 void Maker::throwConfigurationException(ModuleDescription const& md, cms::Exception& iException) const {
0041 std::ostringstream ost;
0042 ost << "Constructing module: class=" << md.moduleName() << " label='" << md.moduleLabel() << "'";
0043 iException.addContext(ost.str());
0044 throw;
0045 }
0046
0047 void Maker::validateEDMType(std::string const& edmType, MakeModuleParams const& p) const {
0048 std::string expected = p.pset_->getParameter<std::string>("@module_edm_type");
0049 if (edmType != expected) {
0050 throw Exception(errors::Configuration)
0051 << "The base type in the python configuration is " << expected << ", but the base type\n"
0052 << "for the module's C++ class is " << edmType << ". "
0053 << "Please fix the configuration.\n"
0054 << "It must use the same base type as the C++ class.\n";
0055 }
0056 }
0057
0058 std::shared_ptr<maker::ModuleHolder> Maker::makeModule(
0059 MakeModuleParams const& p,
0060 signalslot::Signal<void(ModuleDescription const&)>& pre,
0061 signalslot::Signal<void(ModuleDescription const&)>& post) const {
0062
0063 if (p.pset_->getParameter<std::string>("@module_type") == "SwitchProducer") {
0064 p.pset_->addUntrackedParameter("@process_name", p.processConfiguration_->processName());
0065 }
0066
0067 ConfigurationDescriptions descriptions(baseType(), p.pset_->getParameter<std::string>("@module_type"));
0068 fillDescriptions(descriptions);
0069 try {
0070 convertException::wrap([&]() {
0071 descriptions.validate(*p.pset_, p.pset_->getParameter<std::string>("@module_label"));
0072 validateEDMType(baseType(), p);
0073 });
0074 } catch (cms::Exception& iException) {
0075 throwValidationException(p, iException);
0076 }
0077 p.pset_->registerIt();
0078
0079
0080
0081
0082
0083
0084 edm::pset::Registry::instance()->insertMapped(*(p.pset_), true);
0085
0086 ModuleDescription md = createModuleDescription(p);
0087 std::shared_ptr<maker::ModuleHolder> module;
0088 bool postCalled = false;
0089 try {
0090 convertException::wrap([&]() {
0091 pre(md);
0092 module = makeModule(*(p.pset_));
0093 module->setModuleDescription(md);
0094 module->preallocate(*(p.preallocate_));
0095 module->registerProductsAndCallbacks(p.reg_);
0096
0097 postCalled = true;
0098 post(md);
0099 });
0100 } catch (cms::Exception& iException) {
0101 if (!postCalled) {
0102 CMS_SA_ALLOW try { post(md); } catch (...) {
0103
0104 }
0105 }
0106 throwConfigurationException(md, iException);
0107 }
0108 return module;
0109 }
0110
0111 std::unique_ptr<Worker> Maker::makeWorker(ExceptionToActionTable const* actions,
0112 maker::ModuleHolder const* mod) const {
0113 return makeWorker(actions, mod->moduleDescription(), mod);
0114 }
0115
0116 }