CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
PythonProcessDesc Class Reference

#include <PythonProcessDesc.h>

Public Member Functions

std::string dump () const
 
PythonParameterSet newPSet () const
 
std::unique_ptr< edm::ParameterSetparameterSet () const
 
std::shared_ptr< edm::ProcessDescprocessDesc () const
 
PythonParameterSetpset ()
 
 PythonProcessDesc ()
 
 PythonProcessDesc (std::string const &config)
 
 PythonProcessDesc (std::string const &config, int argc, char *argv[])
 

Private Member Functions

void prepareToRead ()
 
void read (std::string const &config)
 
void readFile (std::string const &fileName)
 
void readString (std::string const &pyConfig)
 

Private Attributes

boost::python::object theMainModule
 
boost::python::object theMainNamespace
 
PythonParameterSet theProcessPSet
 

Detailed Description

Definition at line 17 of file PythonProcessDesc.h.

Constructor & Destructor Documentation

PythonProcessDesc::PythonProcessDesc ( )

Definition at line 11 of file PythonProcessDesc.cc.

11  :
13  theMainModule(),
15 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
boost::python::object theMainNamespace
PythonProcessDesc::PythonProcessDesc ( std::string const &  config)

This constructor will parse the given file or string and create two objects in python-land: a PythonProcessDesc named 'processDesc' a PythonParameterSet named 'processPSet' It decides whether it's a file or string by seeing if it ends in '.py'

Definition at line 17 of file PythonProcessDesc.cc.

References prepareToRead(), and read().

17  :
19  theMainModule(),
21  prepareToRead();
22  read(config);
23  Py_Finalize();
24 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
Definition: config.py:1
void read(std::string const &config)
boost::python::object theMainNamespace
PythonProcessDesc::PythonProcessDesc ( std::string const &  config,
int  argc,
char *  argv[] 
)

Definition at line 26 of file PythonProcessDesc.cc.

References prepareToRead(), and read().

26  :
28  theMainModule(),
30  prepareToRead();
31  PySys_SetArgv(argc, argv);
32  read(config);
33  Py_Finalize();
34 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
Definition: config.py:1
void read(std::string const &config)
boost::python::object theMainNamespace

Member Function Documentation

std::string PythonProcessDesc::dump ( void  ) const

Definition at line 90 of file PythonProcessDesc.cc.

References PythonParameterSet::dump(), and theProcessPSet.

Referenced by BOOST_PYTHON_MODULE().

90  {
91  std::ostringstream os;
92  os << theProcessPSet.dump();
93  return os.str();
94 }
std::string dump() const
PythonParameterSet theProcessPSet
PythonParameterSet PythonProcessDesc::newPSet ( ) const
inline

Definition at line 31 of file PythonProcessDesc.h.

Referenced by BOOST_PYTHON_MODULE().

std::unique_ptr< edm::ParameterSet > PythonProcessDesc::parameterSet ( ) const

Definition at line 86 of file PythonProcessDesc.cc.

References PythonParameterSet::pset(), and theProcessPSet.

Referenced by edm::getPSetFromConfig(), edm::boost_python::makeParameterSets(), processDesc(), edm::boost_python::readConfig(), and edm::test::TestProcessor::TestProcessor().

86  {
87  return std::make_unique<edm::ParameterSet>(theProcessPSet.pset());
88 }
PythonParameterSet theProcessPSet
edm::ParameterSet & pset()
void PythonProcessDesc::prepareToRead ( )
private

Definition at line 36 of file PythonProcessDesc.cc.

References edm::python::initializeModule(), resolutioncreator_cfi::object, theMainModule, theMainNamespace, and theProcessPSet.

Referenced by PythonProcessDesc().

36  {
38 
39  theMainModule = object(handle<>(borrowed(PyImport_AddModule(const_cast<char*>("__main__")))));
40 
41  theMainNamespace = theMainModule.attr("__dict__");
42  theMainNamespace["processDesc"] = ptr(this);
43  theMainNamespace["processPSet"] = ptr(&theProcessPSet);
44 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
boost::python::object theMainNamespace
void initializeModule()
std::shared_ptr< edm::ProcessDesc > PythonProcessDesc::processDesc ( ) const

Definition at line 97 of file PythonProcessDesc.cc.

References parameterSet().

Referenced by main().

97  {
98  return std::make_shared<edm::ProcessDesc>(parameterSet());
99 }
std::unique_ptr< edm::ParameterSet > parameterSet() const
PythonParameterSet& PythonProcessDesc::pset ( )
inline
void PythonProcessDesc::read ( std::string const &  config)
private

Definition at line 46 of file PythonProcessDesc.cc.

References edm::pythonToCppException(), readFile(), and readString().

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), and PythonProcessDesc().

46  {
47  try {
48  // if it ends with py, it's a file
49  if(config.substr(config.size()-3) == ".py") {
51  } else {
53  }
54  }
55  catch(error_already_set const&) {
56  edm::pythonToCppException("Configuration");
57  Py_Finalize();
58  }
59 }
void pythonToCppException(const std::string &iType)
Definition: PythonWrapper.cc:6
Definition: config.py:1
void readFile(std::string const &fileName)
void readString(std::string const &pyConfig)
void PythonProcessDesc::readFile ( std::string const &  fileName)
private

Definition at line 61 of file PythonProcessDesc.cc.

References mps_check::command, AlCaHLTBitMon_QueryRunRegistry::string, and theMainNamespace.

Referenced by read().

61  {
62  std::string initCommand("import FWCore.ParameterSet.Config as cms\n"
63  "execfile('");
64  initCommand += fileName + "')";
65 
66  handle<>(PyRun_String(initCommand.c_str(),
67  Py_file_input,
68  theMainNamespace.ptr(),
69  theMainNamespace.ptr()));
70  std::string command("process.fillProcessDesc(processPSet)");
71  handle<>(PyRun_String(command.c_str(),
72  Py_eval_input,
73  theMainNamespace.ptr(),
74  theMainNamespace.ptr()));
75 }
boost::python::object theMainNamespace
list command
Definition: mps_check.py:24
void PythonProcessDesc::readString ( std::string const &  pyConfig)
private

Definition at line 77 of file PythonProcessDesc.cc.

References mps_check::command, AlCaHLTBitMon_QueryRunRegistry::string, and theMainNamespace.

Referenced by read().

77  {
78  std::string command = pyConfig;
79  command += "\nprocess.fillProcessDesc(processPSet)";
80  handle<>(PyRun_String(command.c_str(),
81  Py_file_input,
82  theMainNamespace.ptr(),
83  theMainNamespace.ptr()));
84 }
boost::python::object theMainNamespace
list command
Definition: mps_check.py:24

Member Data Documentation

boost::python::object PythonProcessDesc::theMainModule
private

Definition at line 51 of file PythonProcessDesc.h.

Referenced by prepareToRead().

boost::python::object PythonProcessDesc::theMainNamespace
private

Definition at line 52 of file PythonProcessDesc.h.

Referenced by prepareToRead(), readFile(), and readString().

PythonParameterSet PythonProcessDesc::theProcessPSet
private

Definition at line 50 of file PythonProcessDesc.h.

Referenced by dump(), parameterSet(), and prepareToRead().