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

PyBind11InterpreterSentry theInterpreter
 
Python11ParameterSet theProcessPSet
 

Detailed Description

Definition at line 26 of file PyBind11ProcessDesc.h.

Constructor & Destructor Documentation

◆ PyBind11ProcessDesc() [1/3]

PyBind11ProcessDesc::PyBind11ProcessDesc ( )

Definition at line 26 of file PyBind11ProcessDesc.cc.

26 : theProcessPSet(), theInterpreter(false) {}
Python11ParameterSet theProcessPSet
PyBind11InterpreterSentry theInterpreter

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

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

28  : theProcessPSet(), theInterpreter(true) {
30  prepareToRead();
31  read(config);
32 }
Python11ParameterSet theProcessPSet
Definition: config.py:1
PyBind11InterpreterSentry theInterpreter
void read(std::string const &config)

◆ PyBind11ProcessDesc() [3/3]

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

Definition at line 34 of file PyBind11ProcessDesc.cc.

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

35  : theProcessPSet(),
36  theInterpreter(true)
37 
38 {
40  prepareToRead();
41  {
42 #if PY_MAJOR_VERSION >= 3
43  typedef std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> WArgUPtr;
44  std::vector<WArgUPtr> v_argv;
45  std::vector<wchar_t*> vp_argv;
46  v_argv.reserve(argc);
47  vp_argv.reserve(argc);
48  for (int i = 0; i < argc; i++) {
49  v_argv.emplace_back(Py_DecodeLocale(argv[i], nullptr), &PyMem_RawFree);
50  vp_argv.emplace_back(v_argv.back().get());
51  }
52 
53  wchar_t** argvt = vp_argv.data();
54 #else
55  char** argvt = argv;
56 #endif
57 
58  PySys_SetArgv(argc, argvt);
59  }
60  read(config);
61 }
Python11ParameterSet theProcessPSet
Definition: config.py:1
PyBind11InterpreterSentry theInterpreter
void read(std::string const &config)

◆ ~PyBind11ProcessDesc()

PyBind11ProcessDesc::~PyBind11ProcessDesc ( )
default

Member Function Documentation

◆ dump()

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

Definition at line 101 of file PyBind11ProcessDesc.cc.

References Python11ParameterSet::dump(), and theProcessPSet.

Referenced by PYBIND11_MODULE().

101  {
102  std::ostringstream os;
103  os << theProcessPSet.dump();
104  return os.str();
105 }
Python11ParameterSet theProcessPSet
std::string dump() const

◆ newPSet()

Python11ParameterSet PyBind11ProcessDesc::newPSet ( ) const
inline

Definition at line 42 of file PyBind11ProcessDesc.h.

Referenced by PYBIND11_MODULE().

◆ parameterSet()

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

Definition at line 97 of file PyBind11ProcessDesc.cc.

References Python11ParameterSet::pset(), and theProcessPSet.

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

97  {
98  return std::make_unique<edm::ParameterSet>(theProcessPSet.pset());
99 }
Python11ParameterSet theProcessPSet
edm::ParameterSet & pset()

◆ prepareToRead()

void PyBind11ProcessDesc::prepareToRead ( )
private

Definition at line 65 of file PyBind11ProcessDesc.cc.

References cond::persistency::import(), PyBind11InterpreterSentry::mainModule, theInterpreter, and theProcessPSet.

Referenced by PyBind11ProcessDesc().

65  {
66  // pybind11::scoped_interpreter guard{};
68  theInterpreter.mainModule.attr("processDesc") = this;
69  theInterpreter.mainModule.attr("processPSet") = &theProcessPSet;
70 }
Python11ParameterSet theProcessPSet
PyBind11InterpreterSentry theInterpreter
cond::Hash import(Session &source, const cond::Hash &sourcePayloadId, const std::string &inputTypeName, const void *inputPtr, Session &destination)
Definition: CondDBImport.cc:39

◆ processDesc()

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

Definition at line 108 of file PyBind11ProcessDesc.cc.

References parameterSet().

Referenced by main().

108  {
109  return std::make_unique<edm::ProcessDesc>(parameterSet());
110 }
std::unique_ptr< edm::ParameterSet > parameterSet() const

◆ pset()

Python11ParameterSet& PyBind11ProcessDesc::pset ( )
inline

Definition at line 44 of file PyBind11ProcessDesc.h.

References theProcessPSet.

Referenced by PYBIND11_MODULE().

44 { return theProcessPSet; }
Python11ParameterSet theProcessPSet

◆ read()

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

Definition at line 72 of file PyBind11ProcessDesc.cc.

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

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

72  {
73  try {
74  // if it ends with py, it's a file
75  if (config.substr(config.size() - 3) == ".py") {
77  } else {
79  }
80  } catch (pybind11::error_already_set const& e) {
81  edm::pythonToCppException("Configuration", e.what());
82  }
83 }
void pythonToCppException(const std::string &iType, const std::string &error)
Definition: config.py:1
void readFile(std::string const &fileName)
void readString(std::string const &pyConfig)

◆ readFile()

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

Definition at line 85 of file PyBind11ProcessDesc.cc.

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

Referenced by read().

85  {
86  pybind11::eval_file(fileName);
87  std::string command("process.fillProcessDesc(processPSet)");
88  pybind11::exec(command);
89 }
list command
Definition: mps_check.py:25

◆ readString()

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

Definition at line 91 of file PyBind11ProcessDesc.cc.

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

Referenced by read().

91  {
92  std::string command = pyConfig;
93  command += "\nprocess.fillProcessDesc(processPSet)";
94  pybind11::exec(command.c_str());
95 }
list command
Definition: mps_check.py:25

Member Data Documentation

◆ theInterpreter

PyBind11InterpreterSentry PyBind11ProcessDesc::theInterpreter
private

Definition at line 62 of file PyBind11ProcessDesc.h.

Referenced by prepareToRead().

◆ theProcessPSet

Python11ParameterSet PyBind11ProcessDesc::theProcessPSet
private

Definition at line 61 of file PyBind11ProcessDesc.h.

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