CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WorkerMaker.cc
Go to the documentation of this file.
1 
9 
10 #include <sstream>
11 #include <exception>
12 namespace edm {
13 
15  }
16 
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 
28  void
30  cms::Exception & iException) const {
31  ParameterSet const& conf = *p.pset_;
32  std::string moduleName = conf.getParameter<std::string>("@module_type");
33  std::string moduleLabel = conf.getParameter<std::string>("@module_label");
34 
35  std::ostringstream ost;
36  ost << "Validating configuration of module: class=" << moduleName
37  << " label='" << moduleLabel << "'";
38  iException.addContext(ost.str());
39  throw;
40  }
41 
42  void
44  cms::Exception & iException) const {
45  std::ostringstream ost;
46  ost << "Constructing module: class=" << md.moduleName() << " label='" << md.moduleLabel() << "'";
47  iException.addContext(ost.str());
48  throw;
49  }
50 
51  void
52  Maker::validateEDMType(std::string const& edmType, MakeModuleParams const& p) const {
53  std::string expected = p.pset_->getParameter<std::string>("@module_edm_type");
54  if (edmType != expected) {
56  << "The base type in the python configuration is " << expected << ", but the base type\n"
57  << "for the module's C++ class is " << edmType << ". "
58  << "Please fix the configuration.\n"
59  << "It must use the same base type as the C++ class.\n";
60  }
61  }
62 
63  std::shared_ptr<maker::ModuleHolder>
65  signalslot::Signal<void(ModuleDescription const&)>& pre,
66  signalslot::Signal<void(ModuleDescription const&)>& post) const {
67  ConfigurationDescriptions descriptions(baseType());
68  fillDescriptions(descriptions);
69  try {
70  try {
71  descriptions.validate(*p.pset_, p.pset_->getParameter<std::string>("@module_label"));
73  }
74  catch (cms::Exception& e) { throw; }
75  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
78  catch(char const* c) { convertException::charPtrToEDM(c); }
79  catch (...) { convertException::unknownToEDM(); }
80  }
81  catch (cms::Exception & iException) {
82  throwValidationException(p, iException);
83  }
84  p.pset_->registerIt();
85 
87  std::shared_ptr<maker::ModuleHolder> module;
88  bool postCalled = false;
89  try {
90  try {
91  pre(md);
92  module = makeModule(*(p.pset_));
93  module->setModuleDescription(md);
94  module->preallocate(*(p.preallocate_));
95  module->registerProductsAndCallbacks(p.reg_);
96  // if exception then post will be called in the catch block
97  postCalled = true;
98  post(md);
99  }
100  catch (cms::Exception& e) { throw; }
101  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
102  catch (std::exception& e) { convertException::stdToEDM(e); }
104  catch(char const* c) { convertException::charPtrToEDM(c); }
105  catch (...) { convertException::unknownToEDM(); }
106  }
107  catch(cms::Exception & iException){
108  if(!postCalled) {
109  try {
110  post(md);
111  }
112  catch (...) {
113  // If post throws an exception ignore it because we are already handling another exception
114  }
115  }
116  throwConfigurationException(md, iException);
117  }
118  return module;
119  }
120 
121  std::unique_ptr<Worker>
123  maker::ModuleHolder const* mod) const {
124 
125  return makeWorker(actions,mod->moduleDescription(),mod);
126  }
127 
128 } // end of edm::
T getParameter(std::string const &) const
boost::shared_ptr< ProcessConfiguration const > processConfiguration_
ProductRegistry * reg_
void throwConfigurationException(ModuleDescription const &md, cms::Exception &iException) const
Definition: WorkerMaker.cc:43
ParameterSetID id() const
std::string const & moduleName() const
virtual const std::string & baseType() const =0
actions
Definition: Schedule.cc:362
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:122
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
void stdToEDM(std::exception const &e)
virtual void fillDescriptions(ConfigurationDescriptions &iDesc) const =0
void validateEDMType(std::string const &edmType, MakeModuleParams const &p) const
Definition: WorkerMaker.cc:52
tuple conf
Definition: dbtoconf.py:185
void charPtrToEDM(char const *c)
virtual ~Maker()
Definition: WorkerMaker.cc:14
void stringToEDM(std::string &s)
void addContext(std::string const &context)
Definition: Exception.cc:227
std::shared_ptr< maker::ModuleHolder > makeModule(MakeModuleParams const &, signalslot::Signal< void(ModuleDescription const &)> &iPre, signalslot::Signal< void(ModuleDescription const &)> &iPost) const
Definition: WorkerMaker.cc:64
ModuleDescription createModuleDescription(MakeModuleParams const &p) const
Definition: WorkerMaker.cc:18
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()
void throwValidationException(MakeModuleParams const &p, cms::Exception &iException) const
Definition: WorkerMaker.cc:29