CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
cmspython3::PyBind11ProcessDesc Class Reference

#include <PyBind11ProcessDesc.h>

Public Member Functions

std::string dump () const
 
Python11ParameterSet newPSet () const
 
std::unique_ptr< edm::ParameterSetparameterSet () 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 18 of file PyBind11ProcessDesc.h.

Constructor & Destructor Documentation

◆ PyBind11ProcessDesc() [1/3]

PyBind11ProcessDesc::PyBind11ProcessDesc ( )

Definition at line 13 of file PyBind11ProcessDesc.cc.

◆ PyBind11ProcessDesc() [2/3]

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 15 of file PyBind11ProcessDesc.cc.

17  pybind11::initialize_interpreter();
19  prepareToRead();
20  read(config);
21  }

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

◆ PyBind11ProcessDesc() [3/3]

PyBind11ProcessDesc::PyBind11ProcessDesc ( std::string const &  config,
int  argc,
char *  argv[] 
)

Definition at line 23 of file PyBind11ProcessDesc.cc.

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

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

◆ ~PyBind11ProcessDesc()

PyBind11ProcessDesc::~PyBind11ProcessDesc ( )

Definition at line 54 of file PyBind11ProcessDesc.cc.

54  {
55  if (theOwnsInterpreter) {
57  pybind11::finalize_interpreter();
58  }
59  }

References resolutioncreator_cfi::object, theMainModule, and theOwnsInterpreter.

Member Function Documentation

◆ dump()

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

Definition at line 97 of file PyBind11ProcessDesc.cc.

97  {
98  std::ostringstream os;
99  os << theProcessPSet.dump();
100  return os.str();
101  }

References cmspython3::Python11ParameterSet::dump(), and theProcessPSet.

Referenced by PYBIND11_MODULE().

◆ newPSet()

Python11ParameterSet cmspython3::PyBind11ProcessDesc::newPSet ( ) const
inline

Definition at line 34 of file PyBind11ProcessDesc.h.

34 { return Python11ParameterSet(); }

Referenced by PYBIND11_MODULE().

◆ parameterSet()

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

Definition at line 93 of file PyBind11ProcessDesc.cc.

93  {
94  return std::make_unique<edm::ParameterSet>(theProcessPSet.pset());
95  }

References cmspython3::Python11ParameterSet::pset(), and theProcessPSet.

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

◆ prepareToRead()

void PyBind11ProcessDesc::prepareToRead ( )
private

Definition at line 61 of file PyBind11ProcessDesc.cc.

61  {
62  // pybind11::scoped_interpreter guard{};
64  theMainModule.attr("processDesc") = this;
65  theMainModule.attr("processPSet") = &theProcessPSet;
66  }

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

Referenced by PyBind11ProcessDesc().

◆ processDesc()

std::unique_ptr< edm::ProcessDesc > PyBind11ProcessDesc::processDesc ( ) const

Definition at line 104 of file PyBind11ProcessDesc.cc.

104  {
105  return std::make_unique<edm::ProcessDesc>(parameterSet());
106  }

References parameterSet().

◆ pset()

Python11ParameterSet& cmspython3::PyBind11ProcessDesc::pset ( )
inline

Definition at line 36 of file PyBind11ProcessDesc.h.

36 { return theProcessPSet; }

References theProcessPSet.

Referenced by PYBIND11_MODULE().

◆ read()

void PyBind11ProcessDesc::read ( std::string const &  config)
private

Definition at line 68 of file PyBind11ProcessDesc.cc.

68  {
69  try {
70  // if it ends with py, it's a file
71  if (config.substr(config.size() - 3) == ".py") {
73  } else {
75  }
76  } catch (pybind11::error_already_set const& e) {
77  cmspython3::pythonToCppException("Configuration", e.what());
78  }
79  }

References MillePedeFileConverter_cfg::e, cmspython3::pythonToCppException(), readFile(), and readString().

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

◆ readFile()

void PyBind11ProcessDesc::readFile ( std::string const &  fileName)
private

Definition at line 81 of file PyBind11ProcessDesc.cc.

81  {
82  pybind11::eval_file(fileName);
83  std::string command("process.fillProcessDesc(processPSet)");
84  pybind11::exec(command);
85  }

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

Referenced by read().

◆ readString()

void PyBind11ProcessDesc::readString ( std::string const &  pyConfig)
private

Definition at line 87 of file PyBind11ProcessDesc.cc.

87  {
88  std::string command = pyConfig;
89  command += "\nprocess.fillProcessDesc(processPSet)";
90  pybind11::exec(command.c_str());
91  }

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

Referenced by read().

Member Data Documentation

◆ theMainModule

pybind11::object cmspython3::PyBind11ProcessDesc::theMainModule
private

Definition at line 54 of file PyBind11ProcessDesc.h.

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

◆ theOwnsInterpreter

bool cmspython3::PyBind11ProcessDesc::theOwnsInterpreter
private

Definition at line 55 of file PyBind11ProcessDesc.h.

Referenced by ~PyBind11ProcessDesc().

◆ theProcessPSet

Python11ParameterSet cmspython3::PyBind11ProcessDesc::theProcessPSet
private

Definition at line 53 of file PyBind11ProcessDesc.h.

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

cmsBatch.argv
argv
Definition: cmsBatch.py:279
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
mps_fire.i
i
Definition: mps_fire.py:428
cmspython3::PyBind11ProcessDesc::readString
void readString(std::string const &pyConfig)
Definition: PyBind11ProcessDesc.cc:87
dir2webdir.argc
argc
Definition: dir2webdir.py:39
cmspython3::PyBind11ProcessDesc::theOwnsInterpreter
bool theOwnsInterpreter
Definition: PyBind11ProcessDesc.h:55
cmspython3::PyBind11ProcessDesc::read
void read(std::string const &config)
Definition: PyBind11ProcessDesc.cc:68
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
Python11ParameterSet
Definition: Python11ParameterSet.h:19
mps_check.command
list command
Definition: mps_check.py:25
cmspython3::Python11ParameterSet::dump
std::string dump() const
Definition: Python11ParameterSet.h:116
cmspython3::PyBind11ProcessDesc::theProcessPSet
Python11ParameterSet theProcessPSet
Definition: PyBind11ProcessDesc.h:53
config
Definition: config.py:1
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cmspython3::PyBind11ProcessDesc::parameterSet
std::unique_ptr< edm::ParameterSet > parameterSet() const
Definition: PyBind11ProcessDesc.cc:93
edm::python3::initializePyBind11Module
void initializePyBind11Module()
Definition: initializePyBind11Module.cc:14
cmspython3::pythonToCppException
void pythonToCppException(const std::string &iType, const std::string &error)
Definition: PyBind11Wrapper.cc:6
cmspython3::PyBind11ProcessDesc::theMainModule
pybind11::object theMainModule
Definition: PyBind11ProcessDesc.h:54
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
cmspython3::PyBind11ProcessDesc::prepareToRead
void prepareToRead()
Definition: PyBind11ProcessDesc.cc:61
cond::persistency::import
cond::Hash import(Session &source, const cond::Hash &sourcePayloadId, const std::string &inputTypeName, const void *inputPtr, Session &destination)
Definition: CondDBImport.cc:39
cmspython3::PyBind11ProcessDesc::readFile
void readFile(std::string const &fileName)
Definition: PyBind11ProcessDesc.cc:81
cmspython3::Python11ParameterSet::pset
edm::ParameterSet & pset()
Definition: Python11ParameterSet.h:112
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37