CMS 3D CMS Logo

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

#include <PythonProcessDesc.h>

Public Member Functions

void addService (PythonParameterSet &pset)
 
std::string dump () const
 
PythonParameterSet newPSet () const
 
boost::shared_ptr
< edm::ProcessDesc
processDesc ()
 
 PythonProcessDesc ()
 
 PythonProcessDesc (std::string const &config)
 
 PythonProcessDesc (std::string const &config, int argc, char *argv[])
 

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

boost::python::object theMainModule
 
boost::python::object theMainNamespace
 
PythonParameterSet theProcessPSet
 
std::vector< PythonParameterSettheServices
 

Detailed Description

Definition at line 16 of file PythonProcessDesc.h.

Constructor & Destructor Documentation

PythonProcessDesc::PythonProcessDesc ( )

Definition at line 11 of file PythonProcessDesc.cc.

12 : theProcessPSet(),
13  theServices(),
14  theMainModule(),
16 {
17 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
boost::python::object theMainNamespace
std::vector< PythonParameterSet > theServices
PythonProcessDesc::PythonProcessDesc ( 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 20 of file PythonProcessDesc.cc.

References prepareToRead(), and read().

21 : theProcessPSet(),
22  theServices(),
23  theMainModule(),
25 {
26  prepareToRead();
27  read(config);
28  Py_Finalize();
29 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
void read(std::string const &config)
boost::python::object theMainNamespace
std::vector< PythonParameterSet > theServices
tuple config
Definition: cmsDriver.py:17
PythonProcessDesc::PythonProcessDesc ( std::string const &  config,
int  argc,
char *  argv[] 
)

Definition at line 31 of file PythonProcessDesc.cc.

References prepareToRead(), and read().

32 : theProcessPSet(),
33  theServices(),
34  theMainModule(),
36 {
37  prepareToRead();
38  PySys_SetArgv(argc, argv);
39  read(config);
40  Py_Finalize();
41 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
void read(std::string const &config)
boost::python::object theMainNamespace
std::vector< PythonParameterSet > theServices
tuple config
Definition: cmsDriver.py:17

Member Function Documentation

void PythonProcessDesc::addService ( PythonParameterSet pset)
inline

Definition at line 31 of file PythonProcessDesc.h.

References theServices.

Referenced by BOOST_PYTHON_MODULE().

31 {theServices.push_back(pset);}
std::vector< PythonParameterSet > theServices
std::string PythonProcessDesc::dump ( void  ) const

Definition at line 117 of file PythonProcessDesc.cc.

References PythonParameterSet::dump(), theProcessPSet, and theServices.

Referenced by BOOST_PYTHON_MODULE().

118 {
119  std::ostringstream os;
120  os << theProcessPSet.dump();
121  BOOST_FOREACH(PythonParameterSet service, theServices)
122  {
123  os << service.dump();
124  }
125  return os.str();
126 }
std::string dump() const
PythonParameterSet theProcessPSet
std::vector< PythonParameterSet > theServices
PythonParameterSet PythonProcessDesc::newPSet ( ) const
inline

Definition at line 33 of file PythonProcessDesc.h.

Referenced by BOOST_PYTHON_MODULE().

void PythonProcessDesc::prepareToRead ( )
private

Definition at line 44 of file PythonProcessDesc.cc.

References edm::python::initializeModule(), dbtoconf::object, theMainModule, theMainNamespace, and theProcessPSet.

Referenced by PythonProcessDesc().

45 {
47 
48  theMainModule = object(handle<>(borrowed(PyImport_AddModule(const_cast<char *>("__main__")))));
49 
50  theMainNamespace = theMainModule.attr("__dict__");
51  theMainNamespace["processDesc"] = ptr(this);
52  theMainNamespace["processPSet"] = ptr(&theProcessPSet);
53 }
boost::python::object theMainModule
PythonParameterSet theProcessPSet
boost::python::object theMainNamespace
list object
Definition: dbtoconf.py:77
void initializeModule()
boost::shared_ptr< edm::ProcessDesc > PythonProcessDesc::processDesc ( )

Definition at line 106 of file PythonProcessDesc.cc.

References PythonParameterSet::pset(), query::result, theProcessPSet, and theServices.

Referenced by edm::EventProcessor::EventProcessor(), evf::FWEPWrapper::init(), main(), edm::makeParameterSets(), stor::parseStreamConfiguration(), and edm::readConfig().

107 {
108  boost::shared_ptr<edm::ProcessDesc> result(new edm::ProcessDesc(theProcessPSet.pset()));
109  BOOST_FOREACH(PythonParameterSet service, theServices)
110  {
111  result->addService(service.pset());
112  }
113  return result;
114 }
PythonParameterSet theProcessPSet
tuple result
Definition: query.py:137
edm::ParameterSet & pset()
std::vector< PythonParameterSet > theServices
void PythonProcessDesc::read ( std::string const &  config)
private

Definition at line 56 of file PythonProcessDesc.cc.

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

Referenced by PythonProcessDesc().

57 {
58  try {
59  // if it ends with py, it's a file
60  if(config.substr(config.size()-3) == ".py")
61  {
63  }
64  else
65  {
67  }
68  }
69  catch( error_already_set ) {
70  edm::pythonToCppException("Configuration");
71  Py_Finalize();
72  }
73 }
void pythonToCppException(const std::string &iType)
Definition: PythonWrapper.cc:6
void readFile(std::string const &fileName)
tuple config
Definition: cmsDriver.py:17
void readString(std::string const &pyConfig)
void PythonProcessDesc::readFile ( std::string const &  fileName)
private

Definition at line 76 of file PythonProcessDesc.cc.

References edmPickEvents::command, and theMainNamespace.

Referenced by read().

77 {
78  std::string initCommand("import FWCore.ParameterSet.Config as cms\n"
79  "execfile('");
80  initCommand += fileName + "')";
81 
82 
83  handle<>(PyRun_String(initCommand.c_str(),
84  Py_file_input,
85  theMainNamespace.ptr(),
86  theMainNamespace.ptr()));
87  std::string command("process.fillProcessDesc(processDesc, processPSet)");
88  handle<>(PyRun_String(command.c_str(),
89  Py_eval_input,
90  theMainNamespace.ptr(),
91  theMainNamespace.ptr()));
92 }
boost::python::object theMainNamespace
void PythonProcessDesc::readString ( std::string const &  pyConfig)
private

Definition at line 95 of file PythonProcessDesc.cc.

References edmPickEvents::command, and theMainNamespace.

Referenced by read().

96 {
97  std::string command = pyConfig;
98  command += "\nprocess.fillProcessDesc(processDesc, processPSet)";
99  handle<>(PyRun_String(command.c_str(),
100  Py_file_input,
101  theMainNamespace.ptr(),
102  theMainNamespace.ptr()));
103 }
boost::python::object theMainNamespace

Member Data Documentation

boost::python::object PythonProcessDesc::theMainModule
private

Definition at line 48 of file PythonProcessDesc.h.

Referenced by prepareToRead().

boost::python::object PythonProcessDesc::theMainNamespace
private

Definition at line 49 of file PythonProcessDesc.h.

Referenced by prepareToRead(), readFile(), and readString().

PythonParameterSet PythonProcessDesc::theProcessPSet
private

Definition at line 46 of file PythonProcessDesc.h.

Referenced by dump(), prepareToRead(), and processDesc().

std::vector<PythonParameterSet> PythonProcessDesc::theServices
private

Definition at line 47 of file PythonProcessDesc.h.

Referenced by addService(), dump(), and processDesc().