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  }
17 
20  ParameterSet const& conf = *p.pset_;
21  ModuleDescription md(conf.id(),
22  conf.getParameter<std::string>("@module_type"),
23  conf.getParameter<std::string>("@module_label"),
24  p.processConfiguration_.get(),
26  return md;
27  }
28 
29  void
31  cms::Exception & iException) const {
32  ParameterSet const& conf = *p.pset_;
33  std::string moduleName = conf.getParameter<std::string>("@module_type");
34  std::string moduleLabel = conf.getParameter<std::string>("@module_label");
35 
36  std::ostringstream ost;
37  ost << "Validating configuration of module: class=" << moduleName
38  << " label='" << moduleLabel << "'";
39  iException.addContext(ost.str());
40  throw;
41  }
42 
43  void
45  cms::Exception & iException) const {
46  std::ostringstream ost;
47  ost << "Constructing module: class=" << md.moduleName() << " label='" << md.moduleLabel() << "'";
48  iException.addContext(ost.str());
49  throw;
50  }
51 
52  void
53  Maker::validateEDMType(std::string const& edmType, MakeModuleParams const& p) const {
54  std::string expected = p.pset_->getParameter<std::string>("@module_edm_type");
55  if (edmType != expected) {
57  << "The base type in the python configuration is " << expected << ", but the base type\n"
58  << "for the module's C++ class is " << edmType << ". "
59  << "Please fix the configuration.\n"
60  << "It must use the same base type as the C++ class.\n";
61  }
62  }
63 
64  std::shared_ptr<maker::ModuleHolder>
66  signalslot::Signal<void(ModuleDescription const&)>& pre,
67  signalslot::Signal<void(ModuleDescription const&)>& post) const {
68  ConfigurationDescriptions descriptions(baseType(), p.pset_->getParameter<std::string>("@module_type"));
69  fillDescriptions(descriptions);
70  try {
72  descriptions.validate(*p.pset_, p.pset_->getParameter<std::string>("@module_label"));
74  });
75  }
76  catch (cms::Exception & iException) {
77  throwValidationException(p, iException);
78  }
79  p.pset_->registerIt();
80  //Need to be certain top level untracked parameters are stored in
81  // the registry even if another PSet already exists in the
82  // registry from a previous process
83  //NOTE: a better implementation would be to change ParameterSet::registerIt
84  // but that would require rebuilding much more code so will be done at
85  // a later date.
87 
89  std::shared_ptr<maker::ModuleHolder> module;
90  bool postCalled = false;
91  try {
93  pre(md);
94  module = makeModule(*(p.pset_));
95  module->setModuleDescription(md);
96  module->preallocate(*(p.preallocate_));
97  module->registerProductsAndCallbacks(p.reg_);
98  // if exception then post will be called in the catch block
99  postCalled = true;
100  post(md);
101  });
102  }
103  catch(cms::Exception & iException){
104  if(!postCalled) {
105  try {
106  post(md);
107  }
108  catch (...) {
109  // If post throws an exception ignore it because we are already handling another exception
110  }
111  }
112  throwConfigurationException(md, iException);
113  }
114  return module;
115  }
116 
117  std::unique_ptr<Worker>
119  maker::ModuleHolder const* mod) const {
120 
121  return makeWorker(actions,mod->moduleDescription(),mod);
122  }
123 
124 } // end of edm::
virtual ModuleDescription const & moduleDescription() const =0
T getParameter(std::string const &) const
ProductRegistry * reg_
roAction_t actions[nactions]
Definition: GenABIO.cc:187
void throwConfigurationException(ModuleDescription const &md, cms::Exception &iException) const
Definition: WorkerMaker.cc:44
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:118
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
bool insertMapped(value_type const &v, bool forceUpdate=false)
Definition: Registry.cc:36
void validateEDMType(std::string const &edmType, MakeModuleParams const &p) const
Definition: WorkerMaker.cc:53
virtual ~Maker()
Definition: WorkerMaker.cc:15
virtual void fillDescriptions(ConfigurationDescriptions &iDesc) const =0
void addContext(std::string const &context)
Definition: Exception.cc:227
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:65
HLT enums.
ModuleDescription createModuleDescription(MakeModuleParams const &p) const
Definition: WorkerMaker.cc:19
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:13
std::shared_ptr< ProcessConfiguration const > processConfiguration_
void throwValidationException(MakeModuleParams const &p, cms::Exception &iException) const
Definition: WorkerMaker.cc:30