CMS 3D CMS Logo

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