CMS 3D CMS Logo

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::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 16 of file PyBind11ProcessDesc.h.

Constructor & Destructor Documentation

◆ PyBind11ProcessDesc() [1/3]

PyBind11ProcessDesc::PyBind11ProcessDesc ( )

Definition at line 12 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 14 of file PyBind11ProcessDesc.cc.

16  pybind11::initialize_interpreter();
18  prepareToRead();
19  read(config);
20 }

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

◆ PyBind11ProcessDesc() [3/3]

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

Definition at line 22 of file PyBind11ProcessDesc.cc.

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], NULL), &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 }

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

◆ ~PyBind11ProcessDesc()

PyBind11ProcessDesc::~PyBind11ProcessDesc ( )

Definition at line 53 of file PyBind11ProcessDesc.cc.

53  {
54  if (theOwnsInterpreter) {
56  pybind11::finalize_interpreter();
57  }
58 }

References resolutioncreator_cfi::object, theMainModule, and theOwnsInterpreter.

Member Function Documentation

◆ dump()

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

Definition at line 96 of file PyBind11ProcessDesc.cc.

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

References Python11ParameterSet::dump(), and theProcessPSet.

Referenced by PYBIND11_MODULE().

◆ newPSet()

Python11ParameterSet PyBind11ProcessDesc::newPSet ( ) const
inline

Definition at line 32 of file PyBind11ProcessDesc.h.

32 { return Python11ParameterSet(); }

Referenced by PYBIND11_MODULE().

◆ parameterSet()

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

Definition at line 92 of file PyBind11ProcessDesc.cc.

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

References Python11ParameterSet::pset(), and theProcessPSet.

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

◆ prepareToRead()

void PyBind11ProcessDesc::prepareToRead ( )
private

Definition at line 60 of file PyBind11ProcessDesc.cc.

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

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

Referenced by PyBind11ProcessDesc().

◆ processDesc()

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

Definition at line 103 of file PyBind11ProcessDesc.cc.

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

References parameterSet().

Referenced by main().

◆ pset()

Python11ParameterSet& PyBind11ProcessDesc::pset ( )
inline

Definition at line 34 of file PyBind11ProcessDesc.h.

34 { return theProcessPSet; }

References theProcessPSet.

Referenced by PYBIND11_MODULE().

◆ read()

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

Definition at line 67 of file PyBind11ProcessDesc.cc.

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 }

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

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

◆ readFile()

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

Definition at line 80 of file PyBind11ProcessDesc.cc.

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

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

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

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

Referenced by read().

Member Data Documentation

◆ theMainModule

pybind11::object PyBind11ProcessDesc::theMainModule
private

Definition at line 52 of file PyBind11ProcessDesc.h.

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

◆ theOwnsInterpreter

bool PyBind11ProcessDesc::theOwnsInterpreter
private

Definition at line 53 of file PyBind11ProcessDesc.h.

Referenced by ~PyBind11ProcessDesc().

◆ theProcessPSet

Python11ParameterSet PyBind11ProcessDesc::theProcessPSet
private

Definition at line 51 of file PyBind11ProcessDesc.h.

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

edm::python::initializePyBind11Module
void initializePyBind11Module()
Definition: initializePyBind11Module.cc:14
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
PyBind11ProcessDesc::read
void read(std::string const &config)
Definition: PyBind11ProcessDesc.cc:67
edm::pythonToCppException
void pythonToCppException(const std::string &iType, const std::string &error)
Definition: PyBind11Wrapper.cc:6
dir2webdir.argc
argc
Definition: dir2webdir.py:39
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
Python11ParameterSet
Definition: Python11ParameterSet.h:19
mps_check.command
list command
Definition: mps_check.py:25
config
Definition: config.py:1
Python11ParameterSet::pset
edm::ParameterSet & pset()
Definition: Python11ParameterSet.h:111
Python11ParameterSet::dump
std::string dump() const
Definition: Python11ParameterSet.h:115
PyBind11ProcessDesc::theProcessPSet
Python11ParameterSet theProcessPSet
Definition: PyBind11ProcessDesc.h:51
PyBind11ProcessDesc::prepareToRead
void prepareToRead()
Definition: PyBind11ProcessDesc.cc:60
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PyBind11ProcessDesc::theOwnsInterpreter
bool theOwnsInterpreter
Definition: PyBind11ProcessDesc.h:53
PyBind11ProcessDesc::readFile
void readFile(std::string const &fileName)
Definition: PyBind11ProcessDesc.cc:80
PyBind11ProcessDesc::parameterSet
std::unique_ptr< edm::ParameterSet > parameterSet() const
Definition: PyBind11ProcessDesc.cc:92
PyBind11ProcessDesc::readString
void readString(std::string const &pyConfig)
Definition: PyBind11ProcessDesc.cc:86
NULL
#define NULL
Definition: scimark2.h:8
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
PyBind11ProcessDesc::theMainModule
pybind11::object theMainModule
Definition: PyBind11ProcessDesc.h:52
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
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37