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, bool isFile)
 
 PyBind11ProcessDesc (std::string const &config, bool isFile, const std::vector< std::string > &args)
 
 ~PyBind11ProcessDesc ()
 

Private Member Functions

void prepareToRead ()
 
void read (std::string const &config, bool isFile)
 
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,
bool  isFile 
)

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(), eostools::isFile(), prepareToRead(), and read().

29  : theProcessPSet(), theInterpreter(true) {
31  prepareToRead();
32  read(config, isFile);
33 }
Python11ParameterSet theProcessPSet
Definition: config.py:1
PyBind11InterpreterSentry theInterpreter
void read(std::string const &config, bool isFile)
def isFile(path)
Definition: eostools.py:274

◆ PyBind11ProcessDesc() [3/3]

PyBind11ProcessDesc::PyBind11ProcessDesc ( std::string const &  config,
bool  isFile,
const std::vector< std::string > &  args 
)

Definition at line 35 of file PyBind11ProcessDesc.cc.

References writedatasetfile::args, mps_fire::i, edm::python::initializePyBind11Module(), eostools::isFile(), prepareToRead(), and read().

36  : theProcessPSet(), theInterpreter(true) {
38  prepareToRead();
39  {
40  typedef std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> WArgUPtr;
41  std::vector<WArgUPtr> v_argv;
42  std::vector<wchar_t*> vp_argv;
43  v_argv.reserve(args.size());
44  vp_argv.reserve(args.size());
45  for (size_t i = 0; i < args.size(); i++) {
46  v_argv.emplace_back(Py_DecodeLocale(args[i].c_str(), nullptr), &PyMem_RawFree);
47  vp_argv.emplace_back(v_argv.back().get());
48  }
49 
50  wchar_t** argvt = vp_argv.data();
51 
52  PySys_SetArgv(args.size(), argvt);
53  }
54  read(config, isFile);
55 }
Python11ParameterSet theProcessPSet
Definition: config.py:1
PyBind11InterpreterSentry theInterpreter
void read(std::string const &config, bool isFile)
def isFile(path)
Definition: eostools.py:274

◆ ~PyBind11ProcessDesc()

PyBind11ProcessDesc::~PyBind11ProcessDesc ( )
default

Member Function Documentation

◆ dump()

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

Definition at line 93 of file PyBind11ProcessDesc.cc.

References Python11ParameterSet::dump(), l1tGTMenu_BTagSeeds_cff::os, and theProcessPSet.

Referenced by PYBIND11_MODULE().

93  {
94  std::ostringstream os;
95  os << theProcessPSet.dump();
96  return os.str();
97 }
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 89 of file PyBind11ProcessDesc.cc.

References Python11ParameterSet::pset(), and theProcessPSet.

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

89  {
90  return std::make_unique<edm::ParameterSet>(theProcessPSet.pset());
91 }
Python11ParameterSet theProcessPSet
edm::ParameterSet & pset()

◆ prepareToRead()

void PyBind11ProcessDesc::prepareToRead ( )
private

Definition at line 59 of file PyBind11ProcessDesc.cc.

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

Referenced by PyBind11ProcessDesc().

59  {
60  // pybind11::scoped_interpreter guard{};
62  theInterpreter.mainModule.attr("processDesc") = this;
63  theInterpreter.mainModule.attr("processPSet") = &theProcessPSet;
64 }
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 100 of file PyBind11ProcessDesc.cc.

References parameterSet().

Referenced by main().

100  {
101  return std::make_unique<edm::ProcessDesc>(parameterSet());
102 }
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,
bool  isFile 
)
private

Definition at line 66 of file PyBind11ProcessDesc.cc.

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

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

66  {
67  try {
68  if (isFile)
70  else
72  } catch (pybind11::error_already_set const& e) {
73  edm::pythonToCppException("Configuration", e.what());
74  }
75 }
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)
def isFile(path)
Definition: eostools.py:274

◆ readFile()

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

Definition at line 77 of file PyBind11ProcessDesc.cc.

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

Referenced by read().

77  {
78  pybind11::eval_file(fileName);
79  std::string command("process.fillProcessDesc(processPSet)");
80  pybind11::exec(command);
81 }
list command
Definition: mps_check.py:25

◆ readString()

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

Definition at line 83 of file PyBind11ProcessDesc.cc.

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

Referenced by read().

83  {
84  std::string command = pyConfig;
85  command += "\nprocess.fillProcessDesc(processPSet)";
86  pybind11::exec(command.c_str());
87 }
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().