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// ============================================================================
15// ============================================================================
16#include <algorithm>
17// ============================================================================
18
19// ============================================================================
21// ============================================================================
22int 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
41
42// ============================================================================
44// ============================================================================
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
55 // reseting in/out buffer pointers
56 setp( pbase(), pbase() );
57 setg( eback(), eback(), eback() );
58 return 0;
59}
int sync() override
reimplementation of stringbuf::sync()
std::array< char, 512 > m_callbackBuff
CallbackStreamBuf(PyObject *self)
CallbackStreamBuf constructor.
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition Algorithm.cpp:48