ATLAS Offline Software
Loading...
Searching...
No Matches
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
12using namespace AthPyEx;
13
14// interface ID
15static const InterfaceID IID_MyTool("AthEx::MyTool", 1, 0);
16
17const InterfaceID& MyTool::interfaceID( )
18{ return IID_MyTool; }
19
20StatusCode MyTool::execute(MyObj *obj)
21{
23
24 // get RevProxy
25 PyReverseProxy * proxy = PyReverseProxy::getProxy("MyObj_Proxy");
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
48int MyTool::getA () const
49{
50 return m_A;
51}
52
53void MyTool::setA (const int a)
54{
55 m_A = a;
56}
_object PyObject
static Double_t a
static Double_t sc
static const InterfaceID IID_MyTool("AthEx::MyTool", 1, 0)
int getA() const
accessor
Definition MyTool.cxx:48
StatusCode execute(MyObj *obj)
Definition MyTool.cxx:20
PyObject * m_self
Definition MyTool.h:60
static const InterfaceID & interfaceID()
InterfaceID.
Definition MyTool.cxx:17
void setA(int a)
Definition MyTool.cxx:53
A utility class to convert a C++ object to a PyObject.
static PyReverseProxy * getProxy(const std::string &key)
factory method