#include <FWCore/ParameterSet/interface/PythonProcessDesc.h>
Public Member Functions | |
void | addService (PythonParameterSet &pset) |
std::string | dump () const |
PythonParameterSet | newPSet () const |
boost::shared_ptr < edm::ProcessDesc > | processDesc () |
PythonProcessDesc (std::string const &config, int argc, char *argv[]) | |
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'. | |
PythonProcessDesc () | |
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< PythonParameterSet > | theServices |
Static Private Attributes | |
static bool | initialized_ = false |
Definition at line 8 of file PythonProcessDesc.h.
PythonProcessDesc::PythonProcessDesc | ( | ) |
Definition at line 11 of file PythonProcessDesc.cc.
00012 : theProcessPSet(), 00013 theServices(), 00014 theMainModule(), 00015 theMainNamespace() 00016 { 00017 }
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().
00021 : theProcessPSet(), 00022 theServices(), 00023 theMainModule(), 00024 theMainNamespace() 00025 { 00026 prepareToRead(); 00027 read(config); 00028 Py_Finalize(); 00029 }
PythonProcessDesc::PythonProcessDesc | ( | std::string const & | config, | |
int | argc, | |||
char * | argv[] | |||
) |
Definition at line 31 of file PythonProcessDesc.cc.
References prepareToRead(), and read().
00032 : theProcessPSet(), 00033 theServices(), 00034 theMainModule(), 00035 theMainNamespace() 00036 { 00037 prepareToRead(); 00038 PySys_SetArgv(argc, argv); 00039 read(config); 00040 Py_Finalize(); 00041 }
void PythonProcessDesc::addService | ( | PythonParameterSet & | pset | ) | [inline] |
Definition at line 23 of file PythonProcessDesc.h.
References theServices.
Referenced by BOOST_PYTHON_MODULE().
00023 {theServices.push_back(pset);}
std::string PythonProcessDesc::dump | ( | void | ) | const |
Definition at line 123 of file PythonProcessDesc.cc.
References PythonParameterSet::dump(), parseConfig::service, theProcessPSet, and theServices.
Referenced by BOOST_PYTHON_MODULE().
00124 { 00125 std::ostringstream os; 00126 os << theProcessPSet.dump(); 00127 BOOST_FOREACH(PythonParameterSet service, theServices) 00128 { 00129 os << service.dump(); 00130 } 00131 return os.str(); 00132 }
PythonParameterSet PythonProcessDesc::newPSet | ( | ) | const [inline] |
Definition at line 25 of file PythonProcessDesc.h.
Referenced by BOOST_PYTHON_MODULE().
00025 {return PythonParameterSet();}
void PythonProcessDesc::prepareToRead | ( | ) | [private] |
Definition at line 44 of file PythonProcessDesc.cc.
References initialized_, dbtoconf::object, ptr, theMainModule, theMainNamespace, and theProcessPSet.
Referenced by PythonProcessDesc().
00045 { 00046 PyImport_AppendInittab( "libFWCoreParameterSet", &initlibFWCoreParameterSet ); 00047 Py_Initialize(); 00048 if(!initialized_) 00049 { 00050 PyImport_ImportModule("libFWCoreParameterSet"); 00051 initialized_ = true; 00052 } 00053 00054 theMainModule = object(handle<>(borrowed(PyImport_AddModule("__main__")))); 00055 00056 theMainNamespace = theMainModule.attr("__dict__"); 00057 theMainNamespace["processDesc"] = ptr(this); 00058 theMainNamespace["processPSet"] = ptr(&theProcessPSet); 00059 }
boost::shared_ptr< edm::ProcessDesc > PythonProcessDesc::processDesc | ( | ) |
Definition at line 112 of file PythonProcessDesc.cc.
References PythonParameterSet::pset(), HLT_VtxMuL3::result, parseConfig::service, theProcessPSet, and theServices.
Referenced by stor::StorageManager::configureAction(), evf::FUEventProcessor::initEventProcessor(), edm::makeParameterSets(), and edm::readConfig().
00113 { 00114 boost::shared_ptr<edm::ProcessDesc> result(new edm::ProcessDesc(theProcessPSet.pset())); 00115 BOOST_FOREACH(PythonParameterSet service, theServices) 00116 { 00117 result->addService(service.pset()); 00118 } 00119 return result; 00120 }
void PythonProcessDesc::read | ( | std::string const & | config | ) | [private] |
Definition at line 62 of file PythonProcessDesc.cc.
References edm::pythonToCppException(), readFile(), and readString().
Referenced by PythonProcessDesc().
00063 { 00064 try { 00065 // if it ends with py, it's a file 00066 if(config.substr(config.size()-3) == ".py") 00067 { 00068 readFile(config); 00069 } 00070 else 00071 { 00072 readString(config); 00073 } 00074 } 00075 catch( error_already_set ) { 00076 edm::pythonToCppException("Configuration"); 00077 Py_Finalize(); 00078 } 00079 }
void PythonProcessDesc::readFile | ( | std::string const & | fileName | ) | [private] |
Definition at line 82 of file PythonProcessDesc.cc.
References dbtoconf::command, and theMainNamespace.
Referenced by read().
00083 { 00084 std::string initCommand("import FWCore.ParameterSet.Config as cms\n" 00085 "execfile('"); 00086 initCommand += fileName + "')"; 00087 00088 00089 handle<>(PyRun_String(initCommand.c_str(), 00090 Py_file_input, 00091 theMainNamespace.ptr(), 00092 theMainNamespace.ptr())); 00093 std::string command("process.fillProcessDesc(processDesc, processPSet)"); 00094 handle<>(PyRun_String(command.c_str(), 00095 Py_eval_input, 00096 theMainNamespace.ptr(), 00097 theMainNamespace.ptr())); 00098 }
void PythonProcessDesc::readString | ( | std::string const & | pyConfig | ) | [private] |
Definition at line 101 of file PythonProcessDesc.cc.
References dbtoconf::command, and theMainNamespace.
Referenced by read().
00102 { 00103 std::string command = pyConfig; 00104 command += "\nprocess.fillProcessDesc(processDesc, processPSet)"; 00105 handle<>(PyRun_String(command.c_str(), 00106 Py_file_input, 00107 theMainNamespace.ptr(), 00108 theMainNamespace.ptr())); 00109 }
bool PythonProcessDesc::initialized_ = false [static, private] |
boost::python::object PythonProcessDesc::theMainModule [private] |
boost::python::object PythonProcessDesc::theMainNamespace [private] |
Definition at line 42 of file PythonProcessDesc.h.
Referenced by prepareToRead(), readFile(), and readString().
Definition at line 39 of file PythonProcessDesc.h.
Referenced by dump(), prepareToRead(), and processDesc().
std::vector<PythonParameterSet> PythonProcessDesc::theServices [private] |
Definition at line 40 of file PythonProcessDesc.h.
Referenced by addService(), dump(), and processDesc().