ATLAS Offline Software
PhysicsAnalysis
PyAnalysis
PyAnalysisExamples
src
MyTool.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "Python.h"
6
7
#include "
PyAnalysisExamples/MyTool.h
"
8
#include "
PyAnalysisExamples/MyObj.h
"
9
#include "
PyKernel/PyReverseProxy.h
"
10
#include "
RootUtils/PyAthenaGILStateEnsure.h
"
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
20
StatusCode
MyTool::execute
(
MyObj
*
obj
)
21
{
22
RootUtils::PyGILStateEnsure
gil;
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
#if PY_MAJOR_VERSION < 3
30
PyObject
*pyFunc = PyObject_GetAttr(
m_self
,PyString_FromString(
"py_execute"
));
31
#else
32
PyObject
*pyFunc = PyObject_GetAttr(
m_self
,PyUnicode_FromString(
"py_execute"
));
33
#endif
34
// execute Python code fragment
35
PyObject
*tup = Py_BuildValue((
char
*)
"(O)"
,pyObj);
36
PyObject
*ret = PyObject_CallObject(pyFunc, tup);
37
// return value
38
StatusCode
sc
= StatusCode::FAILURE;
39
if
(ret != NULL) {
40
if
(PyObject_IsTrue(ret))
41
sc
= StatusCode::SUCCESS;
42
Py_DECREF(ret);
43
}
44
// decrement reference counters
45
Py_DECREF(pyObj);
46
Py_DECREF(pyFunc);
47
Py_DECREF(tup);
48
// return
49
return
sc
;
50
}
51
52
int
MyTool::getA
()
const
53
{
54
return
m_A
;
55
}
56
57
void
MyTool::setA
(
const
int
a
)
58
{
59
m_A
=
a
;
60
}
AthPyEx::MyTool::m_A
int m_A
Definition:
MyTool.h:58
StateLessPT_NewConfig.proxy
proxy
Definition:
StateLessPT_NewConfig.py:392
AthPyEx::MyTool::getA
int getA() const
accessor
Definition:
MyTool.cxx:52
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:57
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
Generated on Sun Dec 22 2024 21:15:35 for ATLAS Offline Software by
1.8.18