| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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

This service handles scripting implemented using Python. More...

`#include <GaudiPython/PythonScriptingSvc.h>`

Inheritance diagram for PythonScriptingSvc:
[legend]
Collaboration diagram for PythonScriptingSvc:
[legend]

## 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()].
Public Member Functions inherited from extends1< Service, IRunable >
| extends1 (A1 a1, A2 a2, A3 a3)
| Templated constructor with 3 arguments.
| extends1 (A1 a1, A2 a2)
| Templated constructor with 2 arguments.
| extends1 (A1 a1)
| Templated constructor with 1 argument.
| extends1 ()
| Default constructor.
virtual void * | i_cast (const InterfaceID &tid) const
| Implementation of IInterface::i_cast.
virtual StatusCode | queryInterface (const InterfaceID &ti, void **pp)
| Implementation of IInterface::queryInterface.
virtual std::vector< std::string > | getInterfaceNames () const
| Implementation of IInterface::getInterfaceNames.
virtual | ~extends1 ()
| Virtual destructor.
Public Member Functions inherited from Service
virtual unsigned long | release ()
| Release Interface instance.
virtual const std::string & | name () const
| Retrieve name of the service.
virtual StatusCode | configure ()
virtual StatusCode | start ()
virtual StatusCode | stop ()
virtual StatusCode | terminate ()
virtual Gaudi::StateMachine::State | FSMState () const
virtual Gaudi::StateMachine::State | targetFSMState () const
virtual StatusCode | reinitialize ()
virtual StatusCode | restart ()
virtual StatusCode | sysInitialize ()
| Initialize Service.
virtual StatusCode | sysStart ()
| Initialize Service.
virtual StatusCode | sysStop ()
| Initialize Service.
virtual StatusCode | sysFinalize ()
| Finalize Service.
virtual StatusCode | sysReinitialize ()
| Re-initialize the Service.
virtual StatusCode | sysRestart ()
| Re-initialize the Service.
virtual StatusCode | setProperty (const Property &p)
virtual StatusCode | setProperty (const std::string &s)
virtual StatusCode | setProperty (const std::string &n, const std::string &v)
virtual StatusCode | getProperty (Property *p) const
virtual const Property & | getProperty (const std::string &name) const
virtual StatusCode | getProperty (const std::string &n, std::string &v) const
virtual const std::vector < Property * > & | getProperties () const
template<class TYPE >
StatusCode | setProperty (const std::string &name, const TYPE &value)
| set the property form the value
| Service (const std::string &name, ISvcLocator *svcloc)
| Standard Constructor.
SmartIF< ISvcLocator > & | serviceLocator () const
| Retrieve pointer to service locator.
StatusCode | setProperties ()
| Method for setting declared properties to the values specified for the job.
template<class T >
StatusCode | service (const std::string &name, const T *&psvc, bool createIf=true) const
| Access a service by name, creating it if it doesn't already exist.
template<class T >
StatusCode | service (const std::string &name, T *&psvc, bool createIf=true) const
template<class T >
StatusCode | service (const std::string &svcType, const std::string &svcName, T *&psvc) const
| Access a service by name and type, creating it if it doesn't already exist.
template<class T >
Property * | declareProperty (const std::string &name, T &property, const std::string &doc="none") const
| Declare the named property.
Property * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
| Declare remote named properties.
SmartIF< IAuditorSvc > & | auditorSvc () const
| The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
| CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
| Templated constructor with 3 arguments.
| CommonMessaging (const A1 &a1, const A2 &a2)
| Templated constructor with 2 arguments.
| CommonMessaging (const A1 &a1)
| Templated constructor with 1 argument.
| CommonMessaging ()
| Default constructor.
virtual | ~CommonMessaging ()
| Virtual destructor.
SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service.
MsgStream & | msgStream () const
| Return an uninitialized MsgStream.
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts.
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL)
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR)
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING)
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO)
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG)
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO)
MSG::Level | msgLevel () const
| get the output level from the embedded MsgStream
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream
Public Member Functions inherited from extend_interfaces1< IRunable >
virtual | ~extend_interfaces1 ()
| Virtual destructor.
Public Member Functions inherited from IRunable
| DeclareInterfaceID (IRunable, 2, 0)
| InterfaceID.
Public Member Functions inherited from IInterface
virtual unsigned long | addRef ()=0
| Increment the reference count of Interface instance.
virtual unsigned long | release ()=0
| Release Interface instance.
virtual unsigned long | refCount () const =0
| Current reference count.
virtual | ~IInterface ()
| Virtual destructor.

## Protected Member Functions
virtual | ~PythonScriptingSvc ()
| Destructor.

## Private Attributes
std::string | m_startupScript
| Startup script.

## Additional Inherited Members
Public Types inherited from extends1< Service, IRunable >
typedef extends1 | base_class
| Typedef to this class.
typedef extend_interfaces1 < IRunable > | extend_interfaces_base
| Typedef to the base of this class.
typedef extend_interfaces_base::ext_iids | interfaces
| MPL set of all the implemented interfaces.
Static Public Member Functions inherited from IInterface
static const InterfaceID & | interfaceID ()
| Return an instance of InterfaceID identifying the interface.
Protected Attributes inherited from Service
IntegerProperty | m_outputLevel
| Service output level.
Gaudi::StateMachine::State | m_state
| Service state.
Gaudi::StateMachine::State | m_targetState
| Service state.

## Detailed Description

This service handles scripting implemented using Python.

Author
  Pere Mato
  David Quarrie

Date
  2001

Definition at line 16 of file PythonScriptingSvc.h.

## Constructor & Destructor Documentation

PythonScriptingSvc::PythonScriptingSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc
| ) |  |

Standard Constructor.

Definition at line 23 of file PythonScriptingSvc.cpp.

: base_class(name, svc) {
// Declare the startup script Property
declareProperty( "StartupScript", m_startupScript = "" );
}

PythonScriptingSvc::~PythonScriptingSvc | ( |  | ) |
| protected virtual

Destructor.

Definition at line 31 of file PythonScriptingSvc.cpp.

{ }

## Member Function Documentation

StatusCode PythonScriptingSvc::finalize | ( |  | ) |
| virtual

Finalize the service. [IService::finalize()].

Reimplemented from Service.

Definition at line 97 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 | ( |  | ) |
| virtual

Initialize the service. [IService::initialize()].

Reimplemented from Service.

Definition at line 35 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 112 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;
}

## Member Data Documentation

std::string PythonScriptingSvc::m_startupScript
| private

Startup script.

Definition at line 36 of file PythonScriptingSvc.h.

The documentation for this class was generated from the following files:

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiPython/src/Services/PythonScriptingSvc.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v25r0/GaudiPython/src/Services/PythonScriptingSvc.cpp