The Gaudi Framework
master (82fdf313)
Loading...
Searching...
No Matches
CallbackStreamBuf.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
// ============================================================================
12
#include <
GaudiPython/CallbackStreamBuf.h
>
// this one first, so Python.h is first
13
// ============================================================================
14
#include <
GaudiKernel/Bootstrap.h
>
15
// ============================================================================
16
#include <algorithm>
17
// ============================================================================
18
19
// ============================================================================
21
// ============================================================================
22
int
GaudiPython::call_python_method
( PyObject*
self
,
const
char
* method,
char
* buf ) {
23
if
( !
self
|| !method ) {
return
1; }
24
PyObject* r = PyObject_CallMethod(
self
,
const_cast<
char
*
>
( method ),
const_cast<
char
*
>
(
"s"
), buf );
25
if
( !r ) {
26
std::string err(
"Unsuccessful call to bound Python method"
);
27
err += method;
28
PyErr_SetString( PyExc_TypeError, err.c_str() );
29
PyErr_Print();
30
return
1;
31
}
32
Py_DECREF( r );
33
return
0;
34
}
35
36
// ============================================================================
38
// ============================================================================
39
// cppcheck-suppress uninitMemberVar; do not initialize large m_callbackBuff
40
GaudiPython::CallbackStreamBuf::CallbackStreamBuf
( PyObject*
self
) :
m_self
(
self
) {}
41
42
// ============================================================================
44
// ============================================================================
45
int
GaudiPython::CallbackStreamBuf::sync
() {
46
size_t
length;
47
char
* x;
48
for
( length = 0, x = pbase(); x < epptr(); ++x, ++length )
49
;
50
// getting in a null terminated buffer the characters
51
memcpy(
m_callbackBuff
.data(), pbase(), std::min( length,
m_callbackBuff
.size() ) );
52
m_callbackBuff
[std::min( length,
m_callbackBuff
.size() )] =
'\0'
;
53
// calling the python method
54
GaudiPython::call_python_method
(
m_self
.get(),
"_sync"
,
m_callbackBuff
.data() );
55
// reseting in/out buffer pointers
56
setp( pbase(), pbase() );
57
setg( eback(), eback(), eback() );
58
return
0;
59
}
Bootstrap.h
CallbackStreamBuf.h
GaudiPython::CallbackStreamBuf::sync
int sync() override
reimplementation of stringbuf::sync()
Definition
CallbackStreamBuf.cpp:45
GaudiPython::CallbackStreamBuf::m_self
PyObject_t m_self
Definition
CallbackStreamBuf.h:39
GaudiPython::CallbackStreamBuf::m_callbackBuff
std::array< char, 512 > m_callbackBuff
Definition
CallbackStreamBuf.h:40
GaudiPython::CallbackStreamBuf::CallbackStreamBuf
CallbackStreamBuf(PyObject *self)
CallbackStreamBuf constructor.
Definition
CallbackStreamBuf.cpp:40
GaudiPython.Pythonizations.self
self
Definition
Pythonizations.py:578
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition
Algorithm.cpp:48
GaudiPython
src
Lib
CallbackStreamBuf.cpp
Generated on Thu Oct 2 2025 15:31:12 for The Gaudi Framework by
1.13.1