File indexing completed on 2025-06-17 01:30:20
0001
0002 #include "FWCore/Framework/interface/maker/ModuleMaker.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 ModuleMakerBase::~ModuleMakerBase() {}
0018
0019 ModuleDescription ModuleMakerBase::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 ModuleMakerBase::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 ModuleMakerBase::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 ModuleMakerBase::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> ModuleMakerBase::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->finishModuleInitialization(md, *p.preallocate_, p.reg_);
0094
0095 postCalled = true;
0096 post(md);
0097 });
0098 } catch (cms::Exception& iException) {
0099 if (!postCalled) {
0100 CMS_SA_ALLOW try { post(md); } catch (...) {
0101
0102 }
0103 }
0104 throwConfigurationException(md, iException);
0105 }
0106 return module;
0107 }
0108 }