CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MakeParameterSets.cc
Go to the documentation of this file.
4 
7 
8 
9 using namespace boost::python;
10 
11 static
12 void
13 makePSetsFromFile(const std::string& fileName, boost::python::object& mainNamespace)
14 {
15  std::string initCommand("from FWCore.ParameterSet.Types import makeCppPSet\n"
16  "execfile('");
17  initCommand += fileName + "')";
18 
19 
20  handle<>(PyRun_String(initCommand.c_str(),
21  Py_file_input,
22  mainNamespace.ptr(),
23  mainNamespace.ptr()));
24  std::string command("makeCppPSet(locals(), topPSet)");
25  handle<>(PyRun_String(command.c_str(),
26  Py_eval_input,
27  mainNamespace.ptr(),
28  mainNamespace.ptr()));
29 }
30 
31 static
32 void
33 makePSetsFromString(const std::string& module, boost::python::object& mainNamespace)
34 {
35  std::string command = module;
36  command += "\nfrom FWCore.ParameterSet.Types import makeCppPSet\nmakeCppPSet(locals(), topPSet)";
37  handle<>(PyRun_String(command.c_str(),
38  Py_file_input,
39  mainNamespace.ptr(),
40  mainNamespace.ptr()));
41 }
42 
43 namespace edm
44 {
45 
46  boost::shared_ptr<ProcessDesc>
47  readConfig(const std::string & config)
48  {
49  PythonProcessDesc pythonProcessDesc(config);
50  return pythonProcessDesc.processDesc();
51  }
52 
53  boost::shared_ptr<edm::ProcessDesc>
54  readConfig(const std::string & config, int argc, char * argv[])
55  {
56  PythonProcessDesc pythonProcessDesc(config, argc, argv);
57  return pythonProcessDesc.processDesc();
58  }
59 
60 
61  void
62  makeParameterSets(std::string const& configtext,
63  boost::shared_ptr<ParameterSet>& main,
64  boost::shared_ptr<std::vector<ParameterSet> >& serviceparams)
65  {
66  PythonProcessDesc pythonProcessDesc(configtext);
67  boost::shared_ptr<edm::ProcessDesc> processDesc = pythonProcessDesc.processDesc();
68  main = processDesc->getProcessPSet();
69  serviceparams = processDesc->getServicesPSets();
70  }
71 
72  boost::shared_ptr<ParameterSet>
73  readPSetsFrom(const std::string& module) {
75 
76  boost::python::object mainModule = object(handle<>(borrowed(PyImport_AddModule(const_cast<char *>("__main__")))));
77 
78  boost::python::object mainNamespace = mainModule.attr("__dict__");
79  PythonParameterSet theProcessPSet;
80  mainNamespace["topPSet"] = ptr(&theProcessPSet);
81 
82  try {
83  // if it ends with py, it's a file
84  if(module.substr(module.size()-3) == ".py")
85  {
86  makePSetsFromFile(module,mainNamespace);
87  }
88  else
89  {
90  makePSetsFromString(module,mainNamespace);
91  }
92  }
93  catch( error_already_set ) {
94  edm::pythonToCppException("Configuration");
95  Py_Finalize();
96  }
97  boost::shared_ptr<ParameterSet> returnValue(new ParameterSet);
98  theProcessPSet.pset().swap(*returnValue);
99  return returnValue;
100 
101  }
102 
103 } // namespace edm
int module() const
Definition: HLTadd.h:12
static void makePSetsFromFile(const std::string &fileName, boost::python::object &mainNamespace)
static void makePSetsFromString(const std::string &module, boost::python::object &mainNamespace)
void pythonToCppException(const std::string &iType)
Definition: PythonWrapper.cc:6
def main
— Main —############################
boost::shared_ptr< ParameterSet > readPSetsFrom(const std::string &fileOrString)
void swap(ParameterSet &other)
edm::ParameterSet & pset()
boost::shared_ptr< edm::ProcessDesc > processDesc()
void makeParameterSets(std::string const &configtext, boost::shared_ptr< ParameterSet > &main, boost::shared_ptr< std::vector< ParameterSet > > &serviceparams)
essentially the same as the previous method
list object
Definition: dbtoconf.py:77
tuple config
Definition: cmsDriver.py:17
void initializeModule()
boost::shared_ptr< edm::ProcessDesc > readConfig(const std::string &config)
Definition: vlib.h:209