CMS 3D CMS Logo

MakeParameterSets.cc
Go to the documentation of this file.
3 
7 
8 using namespace boost::python;
9 
10 static
11 void
13  std::string initCommand("from FWCore.ParameterSet.Types import makeCppPSet\n"
14  "execfile('");
15  initCommand += fileName + "')";
16 
17  handle<>(PyRun_String(initCommand.c_str(),
18  Py_file_input,
19  mainNamespace.ptr(),
20  mainNamespace.ptr()));
21  std::string command("makeCppPSet(locals(), topPSet)");
22  handle<>(PyRun_String(command.c_str(),
23  Py_eval_input,
24  mainNamespace.ptr(),
25  mainNamespace.ptr()));
26 }
27 
28 static
29 void
31  std::string command = module;
32  command += "\nfrom FWCore.ParameterSet.Types import makeCppPSet\nmakeCppPSet(locals(), topPSet)";
33  handle<>(PyRun_String(command.c_str(),
34  Py_file_input,
35  mainNamespace.ptr(),
36  mainNamespace.ptr()));
37 }
38 
39 namespace edm {
40  namespace boost_python {
41 
42  std::unique_ptr<edm::ParameterSet>
44  PythonProcessDesc pythonProcessDesc(config);
45  return pythonProcessDesc.parameterSet();
46  }
47 
48  std::unique_ptr<edm::ParameterSet>
49  readConfig(std::string const& config, int argc, char* argv[]) {
50  PythonProcessDesc pythonProcessDesc(config, argc, argv);
51  return pythonProcessDesc.parameterSet();
52  }
53 
54  void
55  makeParameterSets(std::string const& configtext,
56  std::unique_ptr<edm::ParameterSet>& main) {
57  PythonProcessDesc pythonProcessDesc(configtext);
58  main = pythonProcessDesc.parameterSet();
59  }
60 
61  std::unique_ptr<edm::ParameterSet>
64 
65  boost::python::object mainModule = object(handle<>(borrowed(PyImport_AddModule(const_cast<char*>("__main__")))));
66 
67  boost::python::object mainNamespace = mainModule.attr("__dict__");
68  PythonParameterSet theProcessPSet;
69  mainNamespace["topPSet"] = ptr(&theProcessPSet);
70 
71  try {
72  // if it ends with py, it's a file
73  if(module.substr(module.size()-3) == ".py") {
74  makePSetsFromFile(module,mainNamespace);
75  } else {
76  makePSetsFromString(module,mainNamespace);
77  }
78  }
79  catch( error_already_set const& ) {
80  pythonToCppException("Configuration");
81  Py_Finalize();
82  }
83  return std::make_unique<edm::ParameterSet>(ParameterSet(theProcessPSet.pset()));
84  }
85  } // namespace boost_python
86 } // namespace edm
std::unique_ptr< edm::ParameterSet > parameterSet() const
static void makePSetsFromString(std::string const &module, boost::python::object &mainNamespace)
void pythonToCppException(const std::string &iType)
Definition: PythonWrapper.cc:6
Definition: config.py:1
std::unique_ptr< edm::ParameterSet > readConfig(std::string const &config, int argc, char *argv[])
same, but with arguments
std::unique_ptr< edm::ParameterSet > readPSetsFrom(std::string const &fileOrString)
edm::ParameterSet & pset()
list command
Definition: mps_check.py:24
HLT enums.
Definition: main.py:1
void initializeModule()
void makeParameterSets(std::string const &configtext, std::unique_ptr< ParameterSet > &main)
essentially the same as the previous method
Definition: vlib.h:208
static void makePSetsFromFile(std::string const &fileName, boost::python::object &mainNamespace)