ATLAS Offline Software
Loading...
Searching...
No Matches
PyAthena::Tool Class Reference

#include <PyAthenaTool.h>

Inheritance diagram for PyAthena::Tool:
Collaboration diagram for PyAthena::Tool:

Public Member Functions

 Tool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~Tool ()
 Destructor:
virtual StatusCode initialize () override
virtual StatusCode sysInitialize () override
virtual StatusCode finalize () override
virtual const char * typeName () const override
 return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part
virtual PyObjectself () override
 return associated python object.

Protected Member Functions

virtual bool setPyAttr (PyObject *pyobj) override
 attach the C++ component to its python cousin

Protected Attributes

PyObjectm_self
 Pointer to self (from the python world)

Private Member Functions

 Tool ()=delete
 Default constructor:

Detailed Description

Definition at line 30 of file PyAthenaTool.h.

Constructor & Destructor Documentation

◆ Tool() [1/2]

Tool::Tool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor with parameters:

Definition at line 36 of file PyAthenaTool.cxx.

38 :
39 base_class( type, name, parent ),
40 m_self ( nullptr )
41{
42 //
43 // Property declaration
44 //
45 //declareProperty( "Property", m_nProperty );
46
47}
PyObject * m_self
Pointer to self (from the python world)

◆ ~Tool()

Tool::~Tool ( )
virtual

Destructor:

Definition at line 51 of file PyAthenaTool.cxx.

52{
53 ATH_MSG_DEBUG("Calling destructor");
54 if ( m_self ) {
55 RootUtils::PyGILStateEnsure ensure;
56 Py_DECREF( m_self );
57 m_self = nullptr;
58 }
59}
#define ATH_MSG_DEBUG(x)

◆ Tool() [2/2]

PyAthena::Tool::Tool ( )
privatedelete

Default constructor:

Member Function Documentation

◆ finalize()

StatusCode Tool::finalize ( )
overridevirtual

Definition at line 69 of file PyAthenaTool.cxx.

70{
71 ATH_MSG_INFO("Finalizing " << name() << "...");
72 return PyAthena::callPyMethod( m_self, "sysFinalize" );
73}
#define ATH_MSG_INFO(x)

◆ initialize()

StatusCode Tool::initialize ( )
overridevirtual

Definition at line 63 of file PyAthenaTool.cxx.

64{
65 ATH_MSG_INFO("Initializing " << name() << "...");
66 return PyAthena::callPyMethod( m_self, "sysInitialize" );
67}

◆ self()

virtual PyObject * PyAthena::Tool::self ( )
inlineoverridevirtual

return associated python object.

BORROWED reference.

Definition at line 64 of file PyAthenaTool.h.

64{ return m_self; }

◆ setPyAttr()

bool Tool::setPyAttr ( PyObject * pyobj)
overrideprotectedvirtual

attach the C++ component to its python cousin

Definition at line 108 of file PyAthenaTool.cxx.

109{
110 // now we tell the PyObject which C++ object it is the cousin of.
111 RootUtils::PyGILStateEnsure ensure;
112 PyObject* pyobj = TPython::CPPInstance_FromVoidPtr
113 ( (void*)this, this->typeName() );
114 if ( !pyobj ) {
115 PyErr_Clear();
116 // try PyAthena::Tool
117 pyobj = TPython::CPPInstance_FromVoidPtr ((void*)this, "PyAthena::Tool");
119 ("could not dyncast component [" << name() << "] to a python "
120 << "object of type [" << this->typeName() << "] (probably a missing "
121 << "dictionary)" << endmsg
122 << "fallback to [PyAthena::Tool]...");
123 }
124 if ( !pyobj ) {
125 PyErr_Clear();
126 ATH_MSG_WARNING("Could not dyncast component ["
127 << name() << "] to a pyobject of type ["
128 << this->typeName() << "] (missing reflex dict ?)");
129 } else {
130 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", pyobj) ) {
131 PyErr_Clear();
133 ("Could not attach C++ handle [" << name() << "] to its python "
134 << "cousin !");
135 if ( -1 == PyObject_SetAttrString(o, "_cppHandle", Py_None) ) {
136 PyErr_Clear();
138 ("could not attach a dummy C++ handle [" << name() << "] to its "
139 << "python cousin !");
140 }
141 } else {
142 return true;
143 }
144 }
145 return false;
146}
#define endmsg
#define ATH_MSG_WARNING(x)
_object PyObject
virtual const char * typeName() const override
return the std::type_info name of the underlying py-component This is used by concrete implementation...

◆ sysInitialize()

StatusCode Tool::sysInitialize ( )
overridevirtual

Definition at line 76 of file PyAthenaTool.cxx.

77{
78 ServiceHandle<IPyComponentMgr> pyMgr
79 ( "PyAthena::PyComponentMgr/PyComponentMgr",
80 name() );
81 if ( !pyMgr.retrieve().isSuccess() ) {
82 ATH_MSG_ERROR("Could not retrieve service [" << pyMgr.typeAndName() << "] !!");
83 return StatusCode::FAILURE;
84 }
85
86 // first retrieve our python object cousin...
87 m_self = pyMgr->pyObject( this );
88
89 if ( m_self == Py_None ) {
90 ATH_MSG_ERROR("Wrapped PyObject is NONE !");
91 return StatusCode::FAILURE;
92 }
93
94 // re-route to usual sysInit...
96}
#define ATH_MSG_ERROR(x)
virtual StatusCode sysInitialize() override

◆ typeName()

const char * Tool::typeName ( ) const
overridevirtual

return the std::type_info name of the underlying py-component This is used by concrete implementations to connect a python component to its C++ counter-part

Definition at line 100 of file PyAthenaTool.cxx.

101{
102 static const std::string tname = System::typeinfoName(typeid(*this));
103 return tname.c_str();
104}

Member Data Documentation

◆ m_self

PyObject* PyAthena::Tool::m_self
protected

Pointer to self (from the python world)

Definition at line 80 of file PyAthenaTool.h.


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