All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PythonScriptingSvc Class Reference

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

#include <GaudiPython/PythonScriptingSvc.h>

Inheritance diagram for PythonScriptingSvc:
Collaboration diagram for PythonScriptingSvc:

Public Member Functions

 PythonScriptingSvc (const std::string &name, ISvcLocator *svc)
 Standard Constructor. More...
 
virtual StatusCode initialize ()
 Initialize the service. [IService::initialize()]. More...
 
virtual StatusCode finalize ()
 Finalize the service. [IService::finalize()]. More...
 
virtual StatusCode run ()
 Run the service by taking full control. [IRunable::run()]. More...
 
- Public Member Functions inherited from extends1< Service, IRunable >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends1 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends1 ()
 Default constructor. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual ~extends1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector
< Property * > & 
getProperties () const
 Get list of properties. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
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. More...
 
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. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- 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. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces3< IService, IProperty, IStateful >
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IService
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
- Public Member Functions inherited from INamedInterface
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IProperty
 DeclareInterfaceID (IProperty, 2, 0)
 InterfaceID. More...
 
- Public Member Functions inherited from IStateful
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
- Public Member Functions inherited from extend_interfaces1< IRunable >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IRunable
 DeclareInterfaceID (IRunable, 2, 0)
 InterfaceID. More...
 

Protected Member Functions

virtual ~PythonScriptingSvc ()
 Destructor. More...
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 

Private Attributes

std::string m_startupScript
 Startup script. More...
 

Additional Inherited Members

- Public Types inherited from extends1< Service, IRunable >
typedef extends1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1
< IRunable
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from Service
typedef
Gaudi::PluginService::Factory
< IService *, const
std::string &, ISvcLocator * > 
Factory
 
- Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging base_class
 
- Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class. More...
 
typedef extend_interfaces3
< IService, IProperty,
IStateful
extend_interfaces_base
 Typedef to the base of this class. More...
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces3< IService, IProperty, IStateful >
typedef mpl::fold< typename
IService::iid::iids::type,
typename mpl::fold< typename
IProperty::iid::iids::type,
typename
IStateful::iid::iids::type,
mpl::insert< mpl::_1, mpl::_2 >
>::type, mpl::insert< mpl::_1,
mpl::_2 > >::type 
ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IInterface
enum  Status { SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR }
 Return status. More...
 
typedef Gaudi::InterfaceId
< IInterface, 0, 0 > 
iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Public Types inherited from extend_interfaces1< IRunable >
typedef IRunable::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level. More...
 
Gaudi::StateMachine::State m_state
 Service state. More...
 
Gaudi::StateMachine::State m_targetState
 Service state. More...
 
- Protected Attributes inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
SmartIF< IMessageSvcm_msgsvc
 Pointer to the message service;. More...
 
std::auto_ptr< MsgStreamm_msgStream
 The predefined message stream. More...
 
bool m_streamWithService
 Flag to create a new MsgStream if it was created without the message service. More...
 

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.

25 : base_class(name, svc) {
26  // Declare the startup script Property
27  declareProperty( "StartupScript", m_startupScript = "" );
28 }
extends1 base_class
Typedef to this class.
Definition: extends.h:12
std::string m_startupScript
Startup script.
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:211
PythonScriptingSvc::~PythonScriptingSvc ( )
protectedvirtual

Destructor.

Definition at line 31 of file PythonScriptingSvc.cpp.

31 { }

Member Function Documentation

StatusCode PythonScriptingSvc::finalize ( )
virtual

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

Reimplemented from Service.

Definition at line 97 of file PythonScriptingSvc.cpp.

99 {
100  // Finalize this specific service
102  if ( sc.isFailure() ) {
103  return sc;
104  }
105 
106  // Shutdown the Python interpreter
107  Py_Finalize();
108  return StatusCode::SUCCESS;
109 }
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:199
StatusCode PythonScriptingSvc::initialize ( )
virtual

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

Reimplemented from Service.

Definition at line 35 of file PythonScriptingSvc.cpp.

37 {
38  // initialize the Service Base class
40  if ( sc.isFailure() ) return sc;
41 
42  MsgStream log( msgSvc(), name() );
43 
44  // Setup startup script. If none is explicitly specified, then
45  // use the ApplicationMgr JobOptionsPath property as long as
46  // the JobOptionsType property is set to "NONE".
47  if( m_startupScript == "" ) {
49  if ( prpMgr.isValid() ) {
50  StringProperty tmp;
51  tmp.assign(prpMgr->getProperty("JobOptionsType"));
52  if ( tmp.value( ) == "NONE" ) {
53  tmp.assign(prpMgr->getProperty("JobOptionsPath"));
54  m_startupScript = tmp;
55  }
56  }
57  }
58 
59  char* progName[] = { const_cast<char*>("GaudiPython") };
60 
61  // Initialize the Python interpreter. Required.
62  Py_Initialize();
63  // Set argv for Tkinter (needs program name)
64  PySys_SetArgv( 1, progName );
65  // Get the Python version
66  std::string fullversion = Py_GetVersion();
67  std::string version( fullversion, 0, fullversion.find_first_of(' '));
68  std::string vers(version, 0, version.find_first_of('.',version.find_first_of('.')+1));
69  log << MSG::INFO << "Python version: [" << vers << "]" << endmsg;
70 
71 #if defined(__linux)
72  // This is hack to make global the python symbols
73  // which are needed by the other python modules
74  // (eg. readline, math, etc,) libraries.
75  std::string libname = "libpython" + vers + ".so";
76  dlopen(libname.c_str(), RTLD_GLOBAL | RTLD_LAZY);
77 #endif
78 
79 
80  // Startup commands
81  PyRun_SimpleString( "from gaudimodule import *" );
82  PyRun_SimpleString( "g = AppMgr()" );
83  // backward compatibility with SIPython
84  PyRun_SimpleString( "theApp = g" );
85  PyRun_SimpleString( "def Service(n): return g.service(n)" );
86  PyRun_SimpleString( "def Algorithm(n): return g.algorithm(n)" );
87  PyRun_SimpleString( "def Property(n): return g.service(n)" );
88  // For command-line completion (unix only)
89 #if !defined( _WIN32 )
90  PyRun_SimpleString( "import rlcompleter");
91  PyRun_SimpleString( "rlcompleter.readline.parse_and_bind('tab: complete')");
92 #endif
93  return StatusCode::SUCCESS;
94 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
std::string m_startupScript
Startup script.
const TYPE & value() const
explicit conversion
Definition: Property.h:355
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
virtual bool assign(const Property &source)
get the value from another property
Definition: Property.h:283
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:74
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336
StatusCode PythonScriptingSvc::run ( )
virtual

Run the service by taking full control. [IRunable::run()].

Implements IRunable.

Definition at line 112 of file PythonScriptingSvc.cpp.

114 {
115  MsgStream log( msgSvc(), name() );
116  if ( m_startupScript != "" ) {
117  std::ifstream file(m_startupScript.c_str());
118  std::stringstream stream;
119  if( file ) {
120  char ch;
121  while( file.get(ch) ) stream.put(ch);
122  PyRun_SimpleString( const_cast<char*>(stream.str().c_str()) );
123  file.close();
124  }
125  else {
126  log << MSG::WARNING << "Python startup file " << m_startupScript << " not found" << endmsg;
127  }
128  }
129  PyRun_InteractiveLoop(stdin, "\0");
130  return StatusCode::SUCCESS;
131 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
std::string m_startupScript
Startup script.
list file
Definition: ana.py:160
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

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: