CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
PyBind11ProcessDesc Class Reference

#include <PyBind11ProcessDesc.h>

Public Member Functions

std::string dump () const
 
Python11ParameterSet newPSet () const
 
std::unique_ptr
< edm::ParameterSet
parameterSet () const
 
std::unique_ptr< edm::ProcessDescprocessDesc () const
 
Python11ParameterSetpset ()
 
 PyBind11ProcessDesc ()
 
 PyBind11ProcessDesc (std::string const &config)
 
 PyBind11ProcessDesc (std::string const &config, int argc, char *argv[])
 
 ~PyBind11ProcessDesc ()
 

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

pybind11::object theMainModule
 
bool theOwnsInterpreter
 
Python11ParameterSet theProcessPSet
 

Detailed Description

Definition at line 16 of file PyBind11ProcessDesc.h.

Constructor & Destructor Documentation

PyBind11ProcessDesc::PyBind11ProcessDesc ( )

Definition at line 12 of file PyBind11ProcessDesc.cc.

Python11ParameterSet theProcessPSet
pybind11::object theMainModule
PyBind11ProcessDesc::PyBind11ProcessDesc ( 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 14 of file PyBind11ProcessDesc.cc.

References edm::python::initializePyBind11Module(), prepareToRead(), and read().

16  pybind11::initialize_interpreter();
18  prepareToRead();
19  read(config);
20 }
Python11ParameterSet theProcessPSet
pybind11::object theMainModule
void read(std::string const &config)
tuple config
parse the configuration file
PyBind11ProcessDesc::PyBind11ProcessDesc ( std::string const &  config,
int  argc,
char *  argv[] 
)

Definition at line 22 of file PyBind11ProcessDesc.cc.

References dir2webdir::argc, cmsStageWithFailover::argv, mps_fire::i, edm::python::initializePyBind11Module(), prepareToRead(), and read().

23  : theProcessPSet(),
24  theMainModule(),
25  theOwnsInterpreter(true)
26 
27 {
28  pybind11::initialize_interpreter();
30  prepareToRead();
31  {
32 #if PY_MAJOR_VERSION >= 3
33  typedef std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> WArgUPtr;
34  std::vector<WArgUPtr> v_argv;
35  std::vector<wchar_t*> vp_argv;
36  v_argv.reserve(argc);
37  vp_argv.reserve(argc);
38  for (int i = 0; i < argc; i++) {
39  v_argv.emplace_back(Py_DecodeLocale(argv[i], nullptr), &PyMem_RawFree);
40  vp_argv.emplace_back(v_argv.back().get());
41  }
42 
43  wchar_t** argvt = vp_argv.data();
44 #else
45  char** argvt = argv;
46 #endif
47 
48  PySys_SetArgv(argc, argvt);
49  }
50  read(config);
51 }
Python11ParameterSet theProcessPSet
pybind11::object theMainModule
void read(std::string const &config)
tuple argc
Definition: dir2webdir.py:39
tuple config
parse the configuration file
PyBind11ProcessDesc::~PyBind11ProcessDesc ( )

Definition at line 53 of file PyBind11ProcessDesc.cc.

References theMainModule, and theOwnsInterpreter.

53  {
54  if (theOwnsInterpreter) {
55  theMainModule = pybind11::object();
56  pybind11::finalize_interpreter();
57  }
58 }
pybind11::object theMainModule

Member Function Documentation

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

Definition at line 96 of file PyBind11ProcessDesc.cc.

References Python11ParameterSet::dump(), and theProcessPSet.

Referenced by PYBIND11_MODULE().

96  {
97  std::ostringstream os;
98  os << theProcessPSet.dump();
99  return os.str();
100 }
std::string dump() const
Python11ParameterSet theProcessPSet
Python11ParameterSet PyBind11ProcessDesc::newPSet ( ) const
inline

Definition at line 32 of file PyBind11ProcessDesc.h.

Referenced by PYBIND11_MODULE().

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

Definition at line 92 of file PyBind11ProcessDesc.cc.

References Python11ParameterSet::pset(), and theProcessPSet.

Referenced by edm::getPSetFromConfig(), edm::cmspybind11::makeParameterSets(), processDesc(), and edm::cmspybind11::readConfig().

92  {
93  return std::make_unique<edm::ParameterSet>(theProcessPSet.pset());
94 }
Python11ParameterSet theProcessPSet
edm::ParameterSet & pset()
void PyBind11ProcessDesc::prepareToRead ( )
private

Definition at line 60 of file PyBind11ProcessDesc.cc.

References cond::persistency::import(), theMainModule, and theProcessPSet.

Referenced by PyBind11ProcessDesc().

60  {
61  // pybind11::scoped_interpreter guard{};
63  theMainModule.attr("processDesc") = this;
64  theMainModule.attr("processPSet") = &theProcessPSet;
65 }
Python11ParameterSet theProcessPSet
pybind11::object theMainModule
cond::Hash import(Session &source, const cond::Hash &sourcePayloadId, const std::string &inputTypeName, const void *inputPtr, Session &destination)
Definition: CondDBImport.cc:39
std::unique_ptr< edm::ProcessDesc > PyBind11ProcessDesc::processDesc ( ) const

Definition at line 103 of file PyBind11ProcessDesc.cc.

References parameterSet().

Referenced by main().

103  {
104  return std::make_unique<edm::ProcessDesc>(parameterSet());
105 }
std::unique_ptr< edm::ParameterSet > parameterSet() const
Python11ParameterSet& PyBind11ProcessDesc::pset ( )
inline

Definition at line 34 of file PyBind11ProcessDesc.h.

References theProcessPSet.

Referenced by PYBIND11_MODULE().

34 { return theProcessPSet; }
Python11ParameterSet theProcessPSet
void PyBind11ProcessDesc::read ( std::string const &  config)
private

Definition at line 67 of file PyBind11ProcessDesc.cc.

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

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

67  {
68  try {
69  // if it ends with py, it's a file
70  if (config.substr(config.size() - 3) == ".py") {
72  } else {
74  }
75  } catch (pybind11::error_already_set const& e) {
76  edm::pythonToCppException("Configuration", e.what());
77  }
78 }
void pythonToCppException(const std::string &iType, const std::string &error)
void readFile(std::string const &fileName)
void readString(std::string const &pyConfig)
tuple config
parse the configuration file
void PyBind11ProcessDesc::readFile ( std::string const &  fileName)
private

Definition at line 80 of file PyBind11ProcessDesc.cc.

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

Referenced by read().

80  {
81  pybind11::eval_file(fileName);
82  std::string command("process.fillProcessDesc(processPSet)");
83  pybind11::exec(command);
84 }
list command
Definition: mps_check.py:25
void PyBind11ProcessDesc::readString ( std::string const &  pyConfig)
private

Definition at line 86 of file PyBind11ProcessDesc.cc.

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

Referenced by read().

86  {
87  std::string command = pyConfig;
88  command += "\nprocess.fillProcessDesc(processPSet)";
89  pybind11::exec(command.c_str());
90 }
list command
Definition: mps_check.py:25

Member Data Documentation

pybind11::object PyBind11ProcessDesc::theMainModule
private

Definition at line 52 of file PyBind11ProcessDesc.h.

Referenced by prepareToRead(), and ~PyBind11ProcessDesc().

bool PyBind11ProcessDesc::theOwnsInterpreter
private

Definition at line 53 of file PyBind11ProcessDesc.h.

Referenced by ~PyBind11ProcessDesc().

Python11ParameterSet PyBind11ProcessDesc::theProcessPSet
private

Definition at line 51 of file PyBind11ProcessDesc.h.

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