ATLAS Offline Software
MyTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "Python.h"
6 
11 
12 using namespace AthPyEx;
13 
14 // interface ID
15 static const InterfaceID IID_MyTool("AthEx::MyTool", 1, 0);
16 
17 const InterfaceID& MyTool::interfaceID( )
18 { return IID_MyTool; }
19 
21 {
23 
24  // get RevProxy
26  // convert C++ obj to Python obj
27  PyObject *pyObj = proxy->toPyObj(obj);
28  // get Python code fragment
29  PyObject *pyFunc = PyObject_GetAttr(m_self,PyUnicode_FromString("py_execute"));
30  // execute Python code fragment
31  PyObject *tup = Py_BuildValue((char*)"(O)",pyObj);
32  PyObject *ret = PyObject_CallObject(pyFunc, tup);
33  // return value
34  StatusCode sc = StatusCode::FAILURE;
35  if (ret != NULL) {
36  if (PyObject_IsTrue(ret))
37  sc = StatusCode::SUCCESS;
38  Py_DECREF(ret);
39  }
40  // decrement reference counters
41  Py_DECREF(pyObj);
42  Py_DECREF(pyFunc);
43  Py_DECREF(tup);
44  // return
45  return sc;
46 }
47 
48 int MyTool::getA () const
49 {
50  return m_A;
51 }
52 
53 void MyTool::setA (const int a)
54 {
55  m_A = a;
56 }
AthPyEx::MyTool::m_A
int m_A
Definition: MyTool.h:58
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:407
AthPyEx::MyTool::getA
int getA() const
accessor
Definition: MyTool.cxx:48
AthPyEx
Definition: MyCutClass.h:13
PyReverseProxy.h
PyReverseProxy
A utility class to convert a C++ object to a PyObject.
Definition: PyReverseProxy.h:28
AthPyEx::MyTool::interfaceID
static const InterfaceID & interfaceID()
InterfaceID.
Definition: MyTool.cxx:17
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthPyEx::MyObj
Definition: MyObj.h:17
RootUtils::PyGILStateEnsure
Definition: PyAthenaGILStateEnsure.h:20
AthPyEx::MyTool::m_self
PyObject * m_self
Definition: MyTool.h:60
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MyObj.h
PyReverseProxy::getProxy
static PyReverseProxy * getProxy(const std::string &key)
factory method
Definition: PyReverseProxy.h:59
AthPyEx::MyTool::setA
void setA(int a)
Definition: MyTool.cxx:53
MyTool.h
AthPyEx::MyTool::execute
StatusCode execute(MyObj *obj)
Definition: MyTool.cxx:20
a
TList * a
Definition: liststreamerinfos.cxx:10
PyAthenaGILStateEnsure.h
python.PyAthena.obj
obj
Definition: PyAthena.py:132
PyObject
_object PyObject
Definition: IPyComponent.h:26