CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.
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
ProductRegistry * reg_
#define CMS_SA_ALLOW
void throwConfigurationException(ModuleDescription const &md, cms::Exception &iException) const
Definition: WorkerMaker.cc:39
ParameterSetID id() const
std::string const & moduleName() const
virtual const std::string & baseType() const =0
actions
Definition: Schedule.cc:687
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...
virtual ModuleDescription const & moduleDescription() const =0
std::unique_ptr< Worker > makeWorker(ExceptionToActionTable const *, maker::ModuleHolder const *) const
Definition: WorkerMaker.cc:110
virtual void fillDescriptions(ConfigurationDescriptions &iDesc) const =0
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:46
virtual ~Maker()
Definition: WorkerMaker.cc:16
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:192
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
void addContext(std::string const &context)
Definition: Exception.cc:165
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
std::string moduleName(StableProvenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:27
ModuleDescription createModuleDescription(MakeModuleParams const &p) const
Definition: WorkerMaker.cc:18
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()
static Registry * instance()
Definition: Registry.cc:12
tuple module
Definition: callgraph.py:69
std::shared_ptr< ProcessConfiguration const > processConfiguration_
void throwValidationException(MakeModuleParams const &p, cms::Exception &iException) const
Definition: WorkerMaker.cc:28