27 std::cout <<
"Start preparing PythonService" << std::endl;
30 using namespace boost::python;
32 command_ =
"from " + fileName +
" import *\n";
33 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule(const_cast<char*>(
"__main__"))))));
34 object main_namespace = main_module.attr(
"__dict__");
36 object result((boost::python::handle<>(PyRun_String(
command_.c_str(),
39 main_namespace.ptr()))));
40 service_ = main_namespace[
"service"];
42 throw cms::Exception(
"Configuration") <<
"No 'service' python variable defined in given fileName parameter.\n Please create an instance of the python class you want to use and pass that instance to the variable named 'service'.";
64 using namespace boost::python;
65 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule(const_cast<char *>(
"__main__"))))));
66 object main_namespace = main_module.attr(
"__dict__");
67 main_namespace[
"tempService"] =
service_;
70 object result((boost::python::handle<>(PyRun_String(
"tempService.postBeginJob()",
73 main_namespace.ptr()))));
74 }
catch(error_already_set) {
80 using namespace boost::python;
81 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule(const_cast<char *>(
"__main__"))))));
82 object main_namespace = main_module.attr(
"__dict__");
83 main_namespace[
"tempService"] =
service_;
86 object result((boost::python::handle<>(PyRun_String(
"tempService.postEndJob()",
89 main_namespace.ptr()))));
90 }
catch(error_already_set) {
99 using namespace boost::python;
100 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule(const_cast<char *>(
"__main__"))))));
101 object main_namespace = main_module.attr(
"__dict__");
102 main_namespace[
"tempService"] =
service_;
105 object result((boost::python::handle<>(PyRun_String(
"tempService.postProcessEvent()",
107 main_namespace.ptr(),
108 main_namespace.ptr()))));
109 }
catch(error_already_set) {
117 desc.
add<std::string>(
"fileName");
void pythonToCppException(const std::string &iType)
T getParameter(std::string const &) const
void preProcessEvent(const edm::EventID &, const edm::Timestamp &)
void watchPostEndJob(PostEndJob::slot_type const &iSlot)
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void addDefault(ParameterSetDescription const &psetDescription)
boost::python::object service_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
PythonService(const edm::ParameterSet &, edm::ActivityRegistry &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void postProcessEvent(const edm::Event &, const edm::EventSetup &)
void watchPostBeginJob(PostBeginJob::slot_type const &iSlot)
convenience function for attaching to signal