CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
pythonFileToConfigure.cc
Go to the documentation of this file.
1 /*
2  * pythonToConfigure.cpp
3  * CMSSW
4  *
5  * Created by Chris Jones on 10/3/06.
6  *
7  */
8 
12 
13 
15 {
16  std::string returnValue;
17  std::string initCommand("import FWCore.ParameterSet.Config as cms\n"
18  "fileDict = dict()\n"
19  "execfile('");
20  initCommand += iPythonFileName+"',fileDict)";
21 
22  Py_InitializeEx(0);
23  using namespace boost::python;
24 
25  object main_module((
26  boost::python::handle<PyObject>(borrowed(PyImport_AddModule(const_cast<char *>("__main__"))))));
27  object main_namespace = main_module.attr("__dict__");
28  try {
29  try {
30  object result((boost::python::handle<>(PyRun_String(initCommand.c_str(),
31  Py_file_input,
32  main_namespace.ptr(),
33  main_namespace.ptr()))));
34  } catch(error_already_set) {
35  edm::pythonToCppException("Configuration");
36  }
37  try {
38  std::string command("cms.findProcess(fileDict).dumpConfig()");
39  object result((handle<>(PyRun_String(command.c_str(),
40  Py_eval_input,
41  main_namespace.ptr(),
42  main_namespace.ptr()))));
43  returnValue= extract<std::string>(result);
44 
45  }catch( error_already_set ) {
46  edm::pythonToCppException("Configuration");
47  }
48  }catch(...) {
49  Py_Finalize();
50  throw;
51  }
52  Py_Finalize();
53  return returnValue;
54 }
void pythonToCppException(const std::string &iType)
Definition: PythonWrapper.cc:6
tuple result
Definition: mps_fire.py:84
string command
Definition: mps_check.py:26
std::string pythonFileToConfigure(const std::string &iPythonFileName)