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 
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());
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  signalslot::Signal<void(ModuleDescription const&)>& post,
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  post(md);
50  throw;
51 }
52 
53 void
54 Maker::validateEDMType(std::string const& edmType, WorkerParams const& p) const {
55  std::string expected = p.pset_->getParameter<std::string>("@module_edm_type");
56  if (edmType != expected) {
58  << "The base type in the python configuration is " << expected << ", but the base type\n"
59  << "for the module's C++ class is " << edmType << ". "
60  << "Please fix the configuration.\n"
61  << "It must use the same base type as the C++ class.\n";
62  }
63 }
64 
65 std::unique_ptr<Worker>
67  signalslot::Signal<void(ModuleDescription const&)>& pre,
68  signalslot::Signal<void(ModuleDescription const&)>& post) const {
69  ConfigurationDescriptions descriptions(baseType());
70  fillDescriptions(descriptions);
71  try {
72  try {
73  descriptions.validate(*p.pset_, p.pset_->getParameter<std::string>("@module_label"));
75  }
76  catch (cms::Exception& e) { throw; }
77  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
80  catch(char const* c) { convertException::charPtrToEDM(c); }
81  catch (...) { convertException::unknownToEDM(); }
82  }
83  catch (cms::Exception & iException) {
84  throwValidationException(p, iException);
85  }
86  p.pset_->registerIt();
87 
89 
90  std::unique_ptr<Worker> worker;
91  try {
92  try {
93  pre(md);
94  worker = makeWorker(p,md);
95  post(md);
96  }
97  catch (cms::Exception& e) { throw; }
98  catch(std::bad_alloc& bda) { convertException::badAllocToEDM(); }
101  catch(char const* c) { convertException::charPtrToEDM(c); }
102  catch (...) { convertException::unknownToEDM(); }
103  }
104  catch(cms::Exception & iException){
105  throwConfigurationException(md, post, iException);
106  }
107  return worker;
108 }
109 
110 void
112  implSwapModule(w,p);
113 }
114 
115 } // end of edm::
T getParameter(std::string const &) const
ParameterSetID id() const
ParameterSet * pset_
Definition: WorkerParams.h:38
std::string const & moduleName() const
virtual const std::string & baseType() const =0
void swapModule(Worker *, ParameterSet const &)
Definition: WorkerMaker.cc:111
std::string const & moduleLabel() const
void validateEDMType(std::string const &edmType, WorkerParams const &p) const
Definition: WorkerMaker.cc:54
virtual void implSwapModule(Worker *, ParameterSet const &)=0
ModuleDescription createModuleDescription(WorkerParams const &p) const
Definition: WorkerMaker.cc:19
void stdToEDM(std::exception const &e)
virtual void fillDescriptions(ConfigurationDescriptions &iDesc) const =0
tuple conf
Definition: dbtoconf.py:185
void charPtrToEDM(char const *c)
virtual ~Maker()
Definition: WorkerMaker.cc:15
void stringToEDM(std::string &s)
void throwConfigurationException(ModuleDescription const &md, signalslot::Signal< void(ModuleDescription const &)> &post, cms::Exception &iException) const
Definition: WorkerMaker.cc:43
void addContext(std::string const &context)
Definition: Exception.cc:227
std::unique_ptr< Worker > makeWorker(WorkerParams const &, signalslot::Signal< void(ModuleDescription const &)> &iPre, signalslot::Signal< void(ModuleDescription const &)> &iPost) const
Definition: WorkerMaker.cc:66
boost::shared_ptr< ProcessConfiguration const > processConfiguration_
Definition: WorkerParams.h:40
T w() const
void validate(ParameterSet &pset, std::string const &moduleLabel) const
ParameterSet const & registerIt()
void throwValidationException(WorkerParams const &p, cms::Exception &iException) const
Definition: WorkerMaker.cc:29