CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

PythonProcessDesc Class Reference

#include <PythonProcessDesc.h>

List of all members.

Public Member Functions

std::string dump () const
PythonParameterSet newPSet () const
boost::shared_ptr
< edm::ParameterSet
parameterSet ()
boost::shared_ptr
< edm::ProcessDesc
processDesc ()
 PythonProcessDesc (std::string const &config)
 PythonProcessDesc (std::string const &config, int argc, char *argv[])
 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

Detailed Description

Definition at line 17 of file PythonProcessDesc.h.


Constructor & Destructor Documentation

PythonProcessDesc::PythonProcessDesc ( )

Definition at line 11 of file PythonProcessDesc.cc.

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 17 of file PythonProcessDesc.cc.

References prepareToRead(), and read().

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

Definition at line 26 of file PythonProcessDesc.cc.

References prepareToRead(), and read().

                                                                                    :
   theProcessPSet(),
   theMainModule(),
   theMainNamespace() {
  prepareToRead();
  PySys_SetArgv(argc, argv);
  read(config);
  Py_Finalize();
}

Member Function Documentation

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

Definition at line 91 of file PythonProcessDesc.cc.

References PythonParameterSet::dump(), and theProcessPSet.

Referenced by BOOST_PYTHON_MODULE().

                                        {
  std::ostringstream os;
  os << theProcessPSet.dump();
  return os.str();
}
PythonParameterSet PythonProcessDesc::newPSet ( ) const [inline]

Definition at line 31 of file PythonProcessDesc.h.

Referenced by BOOST_PYTHON_MODULE().

{return PythonParameterSet();}
boost::shared_ptr< edm::ParameterSet > PythonProcessDesc::parameterSet ( )
void PythonProcessDesc::prepareToRead ( ) [private]

Definition at line 36 of file PythonProcessDesc.cc.

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

Referenced by PythonProcessDesc().

                                      {
  edm::python::initializeModule();

  theMainModule = object(handle<>(borrowed(PyImport_AddModule(const_cast<char*>("__main__")))));

  theMainNamespace = theMainModule.attr("__dict__");
  theMainNamespace["processDesc"] = ptr(this);
  theMainNamespace["processPSet"] = ptr(&theProcessPSet);
}
boost::shared_ptr< edm::ProcessDesc > PythonProcessDesc::processDesc ( )

Definition at line 98 of file PythonProcessDesc.cc.

References parameterSet(), and query::result.

Referenced by evf::FWEPWrapper::init(), main(), and stor::parseStreamConfiguration().

                                                               {
  boost::shared_ptr<edm::ProcessDesc> result(new edm::ProcessDesc(parameterSet()));
  return result;
}
void PythonProcessDesc::read ( std::string const &  config) [private]

Definition at line 46 of file PythonProcessDesc.cc.

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

Referenced by PythonProcessDesc().

                                                    {
  try {
    // if it ends with py, it's a file
    if(config.substr(config.size()-3) == ".py") {
      readFile(config);
    } else {
      readString(config);
    }
  }
  catch(error_already_set) {
     edm::pythonToCppException("Configuration");
     Py_Finalize();
  }
}
void PythonProcessDesc::readFile ( std::string const &  fileName) [private]

Definition at line 61 of file PythonProcessDesc.cc.

References edmPickEvents::command, and theMainNamespace.

Referenced by read().

                                                          {
  std::string initCommand("import FWCore.ParameterSet.Config as cms\n"
                          "execfile('");
  initCommand += fileName + "')";

  handle<>(PyRun_String(initCommand.c_str(),
                        Py_file_input,
                        theMainNamespace.ptr(),
                        theMainNamespace.ptr()));
  std::string command("process.fillProcessDesc(processPSet)");
  handle<>(PyRun_String(command.c_str(),
                        Py_eval_input,
                        theMainNamespace.ptr(),
                        theMainNamespace.ptr()));
}
void PythonProcessDesc::readString ( std::string const &  pyConfig) [private]

Definition at line 77 of file PythonProcessDesc.cc.

References edmPickEvents::command, and theMainNamespace.

Referenced by read().

                                                            {
  std::string command = pyConfig;
  command += "\nprocess.fillProcessDesc(processPSet)";
  handle<>(PyRun_String(command.c_str(),
                        Py_file_input,
                        theMainNamespace.ptr(),
                        theMainNamespace.ptr()));
}

Member Data Documentation

boost::python::object PythonProcessDesc::theMainModule [private]

Definition at line 49 of file PythonProcessDesc.h.

Referenced by prepareToRead().

boost::python::object PythonProcessDesc::theMainNamespace [private]

Definition at line 50 of file PythonProcessDesc.h.

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

Definition at line 48 of file PythonProcessDesc.h.

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