00001 #include "FWCore/ParameterSet/interface/PythonParseTree.h" 00002 #include "FWCore/ParameterSet/interface/parse.h" 00003 #include "FWCore/ParameterSet/interface/PSetNode.h" 00004 #include "FWCore/ParameterSet/src/PythonWrapper.h" 00005 00006 00007 PythonParseTree::PythonParseTree(const std::string & filename) 00008 : theTree(edm::read_whole_file(filename)) 00009 { 00010 00011 theTree.process(); 00012 } 00013 00014 00015 boost::python::list 00016 PythonParseTree::modules() const 00017 { 00018 return edm::toPythonList<std::string>(theTree.modules()); 00019 } 00020 00021 00022 boost::python::list 00023 PythonParseTree::modulesOfType(const std::string & type) const 00024 { 00025 return edm::toPythonList<std::string>(theTree.modulesOfType(type)); 00026 } 00027 00028 00029 void PythonParseTree::process() 00030 { 00031 theTree.process(); 00032 } 00033 00034 00035 void PythonParseTree::replaceValue(const std::string & dotDelimitedNode, 00036 const std::string & value) 00037 { 00038 theTree.replace(dotDelimitedNode, value); 00039 } 00040 00041 00042 void PythonParseTree::replaceValues(const std::string & dotDelimitedNode, 00043 boost::python::list & values) 00044 { 00045 theTree.replace(dotDelimitedNode, edm::toVector<std::string>(values)); 00046 } 00047 00048 00049 void PythonParseTree::dump(const std::string & dotDelimitedNode) const 00050 { 00051 theTree.print(dotDelimitedNode); 00052 } 00053 00054 00055 std::string PythonParseTree::typeOf(const std::string & dotDelimitedNode) const 00056 { 00057 return theTree.typeOf(dotDelimitedNode); 00058 } 00059 00060 00061 std::string PythonParseTree::value(const std::string & dotDelimitedNode) const 00062 { 00063 return theTree.value(dotDelimitedNode); 00064 } 00065 00066 00067 boost::python::list PythonParseTree::values(const std::string & dotDelimitedNode) const 00068 { 00069 return edm::toPythonList<std::string>(theTree.values(dotDelimitedNode)); 00070 } 00071 00072 00073 boost::python::list PythonParseTree::children(const std::string & dotDelimitedNode) const 00074 { 00075 return edm::toPythonList<std::string>(theTree.children(dotDelimitedNode)); 00076 } 00077 00078 00079 std::string PythonParseTree::dumpTree() const 00080 { 00081 std::ostringstream ost; 00082 theTree.top()->print(ost, edm::pset::Node::COMPRESSED); 00083 return ost.str(); 00084 } 00085 00086 00087 void PythonParseTree::exceptionTranslator(const edm::Exception & e) 00088 { 00089 PyErr_SetString(PyExc_RuntimeError, e.what()); 00090 } 00091