|
Gaudi Framework, version v22r4 |
| Home | Generated: Fri Sep 2 2011 |
This service handles scripting implemented using Python. More...
#include <GaudiPython/PythonScriptingSvc.h>


Public Member Functions | |
| PythonScriptingSvc (const std::string &name, ISvcLocator *svc) | |
| Standard Constructor. | |
| virtual StatusCode | initialize () |
| Initialize the service. [IService::initialize()]. | |
| virtual StatusCode | finalize () |
| Finalize the service. [IService::finalize()]. | |
| virtual StatusCode | run () |
| Run the service by taking full control. [IRunable::run()]. | |
Protected Member Functions | |
| virtual | ~PythonScriptingSvc () |
| Destructor. | |
Private Attributes | |
| std::string | m_startupScript |
| Startup script. | |
This service handles scripting implemented using Python.
Definition at line 16 of file PythonScriptingSvc.h.
| PythonScriptingSvc::PythonScriptingSvc | ( | const std::string & | name, |
| ISvcLocator * | svc | ||
| ) |
Standard Constructor.
Definition at line 27 of file PythonScriptingSvc.cpp.
: base_class(name, svc) { // Declare the startup script Property declareProperty( "StartupScript", m_startupScript = "" ); }
| PythonScriptingSvc::~PythonScriptingSvc | ( | ) | [protected, virtual] |
| StatusCode PythonScriptingSvc::finalize | ( | void | ) | [virtual] |
Finalize the service. [IService::finalize()].
Reimplemented from Service.
Definition at line 101 of file PythonScriptingSvc.cpp.
{
// Finalize this specific service
StatusCode sc = Service::finalize();
if ( sc.isFailure() ) {
return sc;
}
// Shutdown the Python interpreter
Py_Finalize();
return StatusCode::SUCCESS;
}
| StatusCode PythonScriptingSvc::initialize | ( | void | ) | [virtual] |
Initialize the service. [IService::initialize()].
Reimplemented from Service.
Definition at line 39 of file PythonScriptingSvc.cpp.
{
// initialize the Service Base class
StatusCode sc = Service::initialize();
if ( sc.isFailure() ) return sc;
MsgStream log( msgSvc(), name() );
// Setup startup script. If none is explicitly specified, then
// use the ApplicationMgr JobOptionsPath property as long as
// the JobOptionsType property is set to "NONE".
if( m_startupScript == "" ) {
SmartIF<IProperty> prpMgr(serviceLocator());
if ( prpMgr.isValid() ) {
StringProperty tmp;
tmp.assign(prpMgr->getProperty("JobOptionsType"));
if ( tmp.value( ) == "NONE" ) {
tmp.assign(prpMgr->getProperty("JobOptionsPath"));
m_startupScript = tmp;
}
}
}
char* progName[] = { const_cast<char*>("GaudiPython") };
// Initialize the Python interpreter. Required.
Py_Initialize();
// Set argv for Tkinter (needs program name)
PySys_SetArgv( 1, progName );
// Get the Python version
std::string fullversion = Py_GetVersion();
std::string version( fullversion, 0, fullversion.find_first_of(' '));
std::string vers(version, 0, version.find_first_of('.',version.find_first_of('.')+1));
log << MSG::INFO << "Python version: [" << vers << "]" << endmsg;
#if defined(linux)
// This is hack to make global the python symbols
// which are needed by the other python modules
// (eg. readline, math, etc,) libraries.
std::string libname = "libpython" + vers + ".so";
dlopen(libname.c_str(), RTLD_GLOBAL | RTLD_LAZY);
#endif
// Startup commands
PyRun_SimpleString( "from gaudimodule import *" );
PyRun_SimpleString( "g = AppMgr()" );
// backward compatibility with SIPython
PyRun_SimpleString( "theApp = g" );
PyRun_SimpleString( "def Service(n): return g.service(n)" );
PyRun_SimpleString( "def Algorithm(n): return g.algorithm(n)" );
PyRun_SimpleString( "def Property(n): return g.service(n)" );
// For command-line completion (unix only)
#if !defined( _WIN32 )
PyRun_SimpleString( "import rlcompleter");
PyRun_SimpleString( "rlcompleter.readline.parse_and_bind('tab: complete')");
#endif
return StatusCode::SUCCESS;
}
| StatusCode PythonScriptingSvc::run | ( | ) | [virtual] |
Run the service by taking full control. [IRunable::run()].
Implements IRunable.
Definition at line 116 of file PythonScriptingSvc.cpp.
{
MsgStream log( msgSvc(), name() );
if ( m_startupScript != "" ) {
std::ifstream file(m_startupScript.c_str());
std::stringstream stream;
if( file ) {
char ch;
while( file.get(ch) ) stream.put(ch);
PyRun_SimpleString( const_cast<char*>(stream.str().c_str()) );
file.close();
}
else {
log << MSG::WARNING << "Python startup file " << m_startupScript << " not found" << endmsg;
}
}
PyRun_InteractiveLoop(stdin, "\0");
return StatusCode::SUCCESS;
}
Startup script.
Definition at line 36 of file PythonScriptingSvc.h.