CMS 3D CMS Logo

WorkerMaker.cc
Go to the documentation of this file.
1 
11 
12 #include <sstream>
13 #include <exception>
14 namespace edm {
15 
17 
19  ParameterSet const& conf = *p.pset_;
20  ModuleDescription md(conf.id(),
21  conf.getParameter<std::string>("@module_type"),
22  conf.getParameter<std::string>("@module_label"),
23  p.processConfiguration_.get(),
25  return md;
26  }
27 
29  ParameterSet const& conf = *p.pset_;
30  std::string moduleName = conf.getParameter<std::string>("@module_type");
31  std::string moduleLabel = conf.getParameter<std::string>("@module_label");
32 
33  std::ostringstream ost;
34  ost << "Validating configuration of module: class=" << moduleName << " label='" << moduleLabel << "'";
35  iException.addContext(ost.str());
36  throw;
37  }
38 
40  std::ostringstream ost;
41  ost << "Constructing module: class=" << md.moduleName() << " label='" << md.moduleLabel() << "'";
42  iException.addContext(ost.str());
43  throw;
44  }
45 
46  void Maker::validateEDMType(std::string const& edmType, MakeModuleParams const& p) const {
47  std::string expected = p.pset_->getParameter<std::string>("@module_edm_type");
48  if (edmType != expected) {
50  << "The base type in the python configuration is " << expected << ", but the base type\n"
51  << "for the module's C++ class is " << edmType << ". "
52  << "Please fix the configuration.\n"
53  << "It must use the same base type as the C++ class.\n";
54  }
55  }
56 
57  std::shared_ptr<maker::ModuleHolder> Maker::makeModule(
58  MakeModuleParams const& p,
59  signalslot::Signal<void(ModuleDescription const&)>& pre,
60  signalslot::Signal<void(ModuleDescription const&)>& post) const {
61  // Add process_name for SwitchProducer
62  if (p.pset_->getParameter<std::string>("@module_type") == "SwitchProducer") {
63  p.pset_->addUntrackedParameter("@process_name", p.processConfiguration_->processName());
64  }
65 
66  ConfigurationDescriptions descriptions(baseType(), p.pset_->getParameter<std::string>("@module_type"));
67  fillDescriptions(descriptions);
68  try {
70  descriptions.validate(*p.pset_, p.pset_->getParameter<std::string>("@module_label"));
72  });
73  } catch (cms::Exception& iException) {
74  throwValidationException(p, iException);
75  }
76  p.pset_->registerIt();
77  //Need to be certain top level untracked parameters are stored in
78  // the registry even if another PSet already exists in the
79  // registry from a previous process
80  //NOTE: a better implementation would be to change ParameterSet::registerIt
81  // but that would require rebuilding much more code so will be done at
82  // a later date.
83  edm::pset::Registry::instance()->insertMapped(*(p.pset_), true);
84 
86  std::shared_ptr<maker::ModuleHolder> module;
87  bool postCalled = false;
88  try {
90  pre(md);
91  module = makeModule(*(p.pset_));
92  module->setModuleDescription(md);
93  module->preallocate(*(p.preallocate_));
94  module->registerProductsAndCallbacks(p.reg_);
95  // if exception then post will be called in the catch block
96  postCalled = true;
97  post(md);
98  });
99  } catch (cms::Exception& iException) {
100  if (!postCalled) {
101  CMS_SA_ALLOW try { post(md); } catch (...) {
102  // If post throws an exception ignore it because we are already handling another exception
103  }
104  }
105  throwConfigurationException(md, iException);
106  }
107  return module;
108  }
109 
110  std::unique_ptr<Worker> Maker::makeWorker(ExceptionToActionTable const* actions,
111  maker::ModuleHolder const* mod) const {
112  return makeWorker(actions, mod->moduleDescription(), mod);
113  }
114 
115 } // namespace edm
ConfigurationDescriptions.h
edm::pset::Registry::instance
static Registry * instance()
Definition: Registry.cc:12
edm::ModuleDescription::moduleLabel
std::string const & moduleLabel() const
Definition: ModuleDescription.h:43
edm::Maker::throwConfigurationException
void throwConfigurationException(ModuleDescription const &md, cms::Exception &iException) const
Definition: WorkerMaker.cc:39
edm::Maker::fillDescriptions
virtual void fillDescriptions(ConfigurationDescriptions &iDesc) const =0
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
edm
HLT enums.
Definition: AlignableModifier.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
edm::ModuleDescription::moduleName
std::string const & moduleName() const
Definition: ModuleDescription.h:42
edm::ModuleDescription::getUniqueID
static unsigned int getUniqueID()
Returns a unique id each time called. Intended to be passed to ModuleDescription's constructor's modI...
Definition: ModuleDescription.cc:87
edm::MakeModuleParams
Definition: MakeModuleParams.h:21
edm::maker::ModuleHolder
Definition: ModuleHolder.h:37
edm::ParameterSet::id
ParameterSetID id() const
Definition: ParameterSet.cc:189
WorkerMaker.h
CMS_SA_ALLOW
#define CMS_SA_ALLOW
Definition: thread_safety_macros.h:5
edm::ModuleDescription
Definition: ModuleDescription.h:21
ModuleDescription.h
EDMException.h
edm::convertException::wrap
auto wrap(F iFunc) -> decltype(iFunc())
Definition: ConvertException.h:19
edm::ConfigurationDescriptions::validate
void validate(ParameterSet &pset, std::string const &moduleLabel) const
Definition: ConfigurationDescriptions.cc:123
edm::Maker::createModuleDescription
ModuleDescription createModuleDescription(MakeModuleParams const &p) const
Definition: WorkerMaker.cc:18
ConvertException.h
edm::Maker::makeWorker
std::unique_ptr< Worker > makeWorker(ExceptionToActionTable const *, maker::ModuleHolder const *) const
Definition: WorkerMaker.cc:110
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
edm::Maker::makeModule
std::shared_ptr< maker::ModuleHolder > makeModule(MakeModuleParams const &, signalslot::Signal< void(ModuleDescription const &)> &iPre, signalslot::Signal< void(ModuleDescription const &)> &iPost) const
Definition: WorkerMaker.cc:57
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
thread_safety_macros.h
edm::ExceptionToActionTable
Definition: ExceptionActions.h:16
edm::pset::Registry::insertMapped
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
Registry.h
edm::Maker::baseType
virtual const std::string & baseType() const =0
edm::Maker::validateEDMType
void validateEDMType(std::string const &edmType, MakeModuleParams const &p) const
Definition: WorkerMaker.cc:46
Exception
Definition: hltDiff.cc:246
edm::Maker::throwValidationException
void throwValidationException(MakeModuleParams const &p, cms::Exception &iException) const
Definition: WorkerMaker.cc:28
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
edm::Maker::~Maker
virtual ~Maker()
Definition: WorkerMaker.cc:16
actions
roAction_t actions[nactions]
Definition: GenABIO.cc:181
cms::Exception
Definition: Exception.h:70
ParameterSet.h
HerwigMaxPtPartonFilter_cfi.moduleLabel
moduleLabel
Definition: HerwigMaxPtPartonFilter_cfi.py:4
edm::moduleName
std::string moduleName(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
edm::signalslot::Signal
Definition: DelayedReader.h:26
edm::errors::Configuration
Definition: EDMException.h:36