DD4hep
1.30.0
Detector Description Toolkit for High Energy Physics
DDG4
src
python
Geant4PythonCall.cpp
Go to the documentation of this file.
1
//==========================================================================
2
// AIDA Detector description implementation
3
//--------------------------------------------------------------------------
4
// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5
// All rights reserved.
6
//
7
// For the licensing terms see $DD4hepINSTALL/LICENSE.
8
// For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9
//
10
// \author Markus Frank
11
// \date 2015-11-03
12
//
13
//==========================================================================
14
15
// Framework include files
16
#include <
DDG4/Python/Geant4PythonCall.h
>
17
#include <
DDG4/Python/DDPython.h
>
18
#include <TPyReturn.h>
19
20
using namespace
dd4hep::sim
;
21
23
Geant4PythonCall::Geant4PythonCall
()
24
: m_callable(0), m_arguments(0)
25
{
26
DDPython::instance
();
27
}
28
29
Geant4PythonCall::~Geant4PythonCall
() {
30
DDPython::GILState
state(0);
31
DDPython::releaseObject
(
m_callable
);
32
DDPython::releaseObject
(
m_arguments
);
33
}
34
36
void
Geant4PythonCall::set
(PyObject* callable, PyObject* arguments) {
37
DDPython::GILState
state(0);
38
DDPython::assignObject
(
m_callable
,callable);
39
DDPython::assignObject
(
m_arguments
,arguments);
40
}
41
43
void
Geant4PythonCall::set
(PyObject* callable) {
44
DDPython::GILState
state(0);
45
DDPython::assignObject
(
m_callable
,callable);
46
DDPython::assignObject
(
m_arguments
,0);
47
}
48
49
namespace
dd4hep
{
namespace
sim {
50
52
template
<
typename
RETURN> RETURN
Geant4PythonCall::execute
()
const
{
53
DDPython::GILState
state(0);
54
TPyReturn ret(
DDPython::instance
().callC(m_callable, m_arguments));
55
return
(RETURN)ret;
56
}
57
59
template
<
typename
RETURN> RETURN
Geant4PythonCall::execute
(PyObject* method)
const
{
60
DDPython::GILState
state(0);
61
TPyReturn ret(
DDPython::instance
().callC(method,0));
62
return
(RETURN)ret;
63
}
64
66
template
<
typename
RETURN> RETURN
Geant4PythonCall::execute
(PyObject* method, PyObject* args)
const
{
67
DDPython::GILState
state(0);
68
TPyReturn ret(
DDPython::instance
().callC(method,args));
69
return
(RETURN)ret;
70
}
71
#define INSTANTIATE(X) \
72
template X Geant4PythonCall::execute<X>() const; \
73
template X Geant4PythonCall::execute<X>(PyObject* method) const; \
74
template X Geant4PythonCall::execute<X>(PyObject* method, PyObject* args) const
75
76
INSTANTIATE
(
char
);
77
INSTANTIATE
(
short
);
78
INSTANTIATE
(
int
);
79
INSTANTIATE
(
long
);
80
INSTANTIATE
(
unsigned
short
);
81
INSTANTIATE
(
unsigned
int
);
82
INSTANTIATE
(
unsigned
long
);
83
INSTANTIATE
(
float
);
84
INSTANTIATE
(
double
);
85
INSTANTIATE
(
char
*);
86
INSTANTIATE
(
const
char
*);
87
INSTANTIATE
(PyObject*);
88
INSTANTIATE
(
void
*);
89
}}
dd4hep::sim::Geant4PythonCall::Geant4PythonCall
Geant4PythonCall()
Standard constructor.
Definition:
Geant4PythonCall.cpp:23
dd4hep::sim::INSTANTIATE
INSTANTIATE(char)
dd4hep::DDPython::assignObject
static void assignObject(PyObject *&obj, PyObject *new_obj)
Release python object.
Definition:
DDPython.cpp:296
dd4hep::DDPython::releaseObject
static void releaseObject(PyObject *&obj)
Release python object.
Definition:
DDPython.cpp:288
dd4hep::sim::Geant4PythonCall::set
void set(PyObject *callable, PyObject *args)
Set the callback structures for callbacks with arguments.
Definition:
Geant4PythonCall.cpp:36
dd4hep::sim::Geant4PythonCall::execute
RETURN execute() const
Execute command in the python interpreter.
Definition:
Geant4PythonCall.cpp:52
DDPython.h
dd4hep::DDPython::GILState
Definition:
DDPython.h:42
dd4hep::sim
Namespace for the Geant4 based simulation part of the AIDA detector description toolkit.
Definition:
Geant4Output2EDM4hep.cpp:49
dd4hep::DDPython::instance
static DDPython instance()
Object instantiator.
Definition:
DDPython.cpp:190
dd4hep::sim::Geant4PythonCall::m_callable
PyObject * m_callable
Python callable reference.
Definition:
Geant4PythonCall.h:34
dd4hep
Namespace for the AIDA detector description toolkit.
Definition:
AlignmentsCalib.h:28
dd4hep::sim::Geant4PythonCall::m_arguments
PyObject * m_arguments
Python arguments object.
Definition:
Geant4PythonCall.h:36
Geant4PythonCall.h
dd4hep::sim::Geant4PythonCall::~Geant4PythonCall
virtual ~Geant4PythonCall()
Default destructor.
Definition:
Geant4PythonCall.cpp:29
Generated on Tue Dec 10 2024 18:30:10 for DD4hep by
1.8.18