#include <FWCore/Python/src/PythonService.h>
Public Member Functions | |
void | postBeginJob () |
void | postEndJob () |
void | postProcessEvent (const edm::Event &, const edm::EventSetup &) |
void | preProcessEvent (const edm::EventID &, const edm::Timestamp &) |
PythonService (const edm::ParameterSet &, edm::ActivityRegistry &) | |
~PythonService () | |
Private Attributes | |
std::string | command_ |
std::string | fileName_ |
PythonManagerHandle | handle_ |
boost::python::object | service_ |
Usage: <usage>
Definition at line 32 of file PythonService.h.
PythonService::PythonService | ( | const edm::ParameterSet & | iConfig, | |
edm::ActivityRegistry & | iRegistry | |||
) |
Definition at line 25 of file PythonService.cc.
References command_, GenMuonPlsPt100GeV_cfg::cout, lat::endl(), Exception, aod_PYTHIA_cfg::fileName, edm::ParameterSet::getParameter(), postBeginJob(), postEndJob(), postProcessEvent(), HLT_VtxMuL3::result, service_, edm::ActivityRegistry::watchPostBeginJob(), edm::ActivityRegistry::watchPostEndJob(), and edm::ActivityRegistry::watchPostProcessEvent().
00025 : 00026 handle_(PythonManager::handle()) 00027 { 00028 00029 std::cout << "Start preparing PythonService" << std::endl; 00030 const std::string fileName = iConfig.getParameter<std::string>("fileName"); 00031 00032 using namespace boost::python; 00033 00034 command_ = "from "+fileName + " import *\n"; 00035 object main_module(( boost::python::handle<>(borrowed(PyImport_AddModule("__main__"))) )); 00036 object main_namespace = main_module.attr("__dict__"); 00037 try { 00038 object result((boost::python::handle<>(PyRun_String(command_.c_str(), 00039 Py_file_input, 00040 main_namespace.ptr(), 00041 main_namespace.ptr())))); 00042 service_ = main_namespace["service"]; 00043 } catch( ... ) { 00044 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'."; 00045 } 00046 00047 // connect methods and signals 00048 // later on here will be a check what python methods are present 00049 // for now we expect postBeginJob, postEndJob and postProcessEvent 00050 00051 iRegistry.watchPostBeginJob(this,&PythonService::postBeginJob); 00052 iRegistry.watchPostEndJob(this,&PythonService::postEndJob); 00053 iRegistry.watchPostProcessEvent(this,&PythonService::postProcessEvent); 00054 }
PythonService::~PythonService | ( | ) |
void PythonService::postBeginJob | ( | ) |
Definition at line 67 of file PythonService.cc.
References pythonToCppException(), HLT_VtxMuL3::result, and service_.
Referenced by PythonService().
00068 { 00069 using namespace boost::python; 00070 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule("__main__"))))); 00071 object main_namespace = main_module.attr("__dict__"); 00072 main_namespace["tempService"] = service_; 00073 00074 try { 00075 object result((boost::python::handle<>(PyRun_String("tempService.postBeginJob()", 00076 Py_eval_input, 00077 main_namespace.ptr(), 00078 main_namespace.ptr())))); 00079 }catch( error_already_set ) { 00080 pythonToCppException("RuntimeError"); 00081 } 00082 }
void PythonService::postEndJob | ( | ) |
Definition at line 85 of file PythonService.cc.
References pythonToCppException(), HLT_VtxMuL3::result, and service_.
Referenced by PythonService().
00086 { 00087 using namespace boost::python; 00088 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule("__main__"))))); 00089 object main_namespace = main_module.attr("__dict__"); 00090 main_namespace["tempService"] = service_; 00091 00092 try { 00093 object result((boost::python::handle<>(PyRun_String("tempService.postEndJob()", 00094 Py_eval_input, 00095 main_namespace.ptr(), 00096 main_namespace.ptr())))); 00097 }catch( error_already_set ) { 00098 pythonToCppException("RuntimeError"); 00099 } 00100 }
void PythonService::postProcessEvent | ( | const edm::Event & | , | |
const edm::EventSetup & | ||||
) |
Definition at line 109 of file PythonService.cc.
References pythonToCppException(), HLT_VtxMuL3::result, and service_.
Referenced by PythonService().
00110 { 00111 using namespace boost::python; 00112 object main_module((boost::python::handle<>(borrowed(PyImport_AddModule("__main__"))))); 00113 object main_namespace = main_module.attr("__dict__"); 00114 main_namespace["tempService"] = service_; 00115 00116 try { 00117 object result((boost::python::handle<>(PyRun_String("tempService.postProcessEvent()", 00118 Py_eval_input, 00119 main_namespace.ptr(), 00120 main_namespace.ptr())))); 00121 }catch( error_already_set ) { 00122 pythonToCppException("RuntimeError"); 00123 } 00124 00125 }
void PythonService::preProcessEvent | ( | const edm::EventID & | iID, | |
const edm::Timestamp & | iTime | |||
) |
std::string PythonService::command_ [private] |
std::string PythonService::fileName_ [private] |
Definition at line 44 of file PythonService.h.
PythonManagerHandle PythonService::handle_ [private] |
Definition at line 42 of file PythonService.h.
boost::python::object PythonService::service_ [private] |
Definition at line 43 of file PythonService.h.
Referenced by postBeginJob(), postEndJob(), postProcessEvent(), and PythonService().