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,
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
void throwValidationException(MakeModuleParams const &p, cms::Exception &iException) const
Definition: WorkerMaker.cc:28
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
#define CMS_SA_ALLOW
roAction_t actions[nactions]
Definition: GenABIO.cc:181
ModuleDescription createModuleDescription(MakeModuleParams const &p) const
Definition: WorkerMaker.cc:18
void validate(ParameterSet &pset, std::string const &moduleLabel) const
void throwConfigurationException(ModuleDescription const &md, cms::Exception &iException) const
Definition: WorkerMaker.cc:39
std::string const & moduleName() const
virtual const std::string & baseType() const =0
void validateEDMType(std::string const &edmType, MakeModuleParams const &p) const
Definition: WorkerMaker.cc:46
static unsigned int getUniqueID()
Returns a unique id each time called. Intended to be passed to ModuleDescription&#39;s constructor&#39;s modI...
ParameterSetID id() const
virtual void fillDescriptions(ConfigurationDescriptions &iDesc) const =0
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:32
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
virtual ~Maker()
Definition: WorkerMaker.cc:16
void addContext(std::string const &context)
Definition: Exception.cc:169
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
HLT enums.
auto wrap(F iFunc) -> decltype(iFunc())
std::unique_ptr< Worker > makeWorker(ExceptionToActionTable const *, maker::ModuleHolder const *) const
Definition: WorkerMaker.cc:110
std::string const & moduleLabel() const
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
static Registry * instance()
Definition: Registry.cc:12