The Gaudi Framework  master (e3184c44)
CallbackStreamBuf.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 // ============================================================================
13 #include <Python.h> //included for the python API
14 // ============================================================================
15 #include <array>
16 #include <sstream> //included for stringbuf
17 // ============================================================================
18 #include <GaudiKernel/Kernel.h>
20 // ============================================================================
21 
22 namespace GaudiPython {
23  int GAUDI_API call_python_method( PyObject* self, const char* method, char* buf );
24 
25  class GAUDI_API CallbackStreamBuf : public std::stringbuf {
26  private:
27  class PyObject_t {
29 
30  public:
31  PyObject_t( PyObject* obj = nullptr ) : m_obj( obj ) {
32  if ( m_obj ) Py_INCREF( m_obj );
33  }
35  if ( m_obj ) Py_DECREF( m_obj );
36  }
37  PyObject* get() { return m_obj; }
38  };
40  std::array<char, 512> m_callbackBuff; // used for passing the flushed chars in the python callback
41 
42  public:
43  CallbackStreamBuf( PyObject* self );
44  int sync() override;
45  };
46 } // namespace GaudiPython
GaudiPython::CallbackStreamBuf::PyObject_t
Definition: CallbackStreamBuf.h:27
GaudiPython::CallbackStreamBuf::m_self
PyObject_t m_self
Definition: CallbackStreamBuf.h:39
GaudiPython::CallbackStreamBuf::PyObject_t::m_obj
PyObject * m_obj
Definition: CallbackStreamBuf.h:28
GaudiPython::CallbackStreamBuf::PyObject_t::PyObject_t
PyObject_t(PyObject *obj=nullptr)
Definition: CallbackStreamBuf.h:31
GaudiPython::CallbackStreamBuf
Definition: CallbackStreamBuf.h:25
GaudiPython.h
SmartRefVectorImpl::PyObject
_object PyObject
Definition: SmartRefVector.h:19
GaudiPython::CallbackStreamBuf::m_callbackBuff
std::array< char, 512 > m_callbackBuff
Definition: CallbackStreamBuf.h:40
GaudiPython::CallbackStreamBuf::PyObject_t::~PyObject_t
~PyObject_t()
Definition: CallbackStreamBuf.h:34
GaudiPython::CallbackStreamBuf::PyObject_t::get
PyObject * get()
Definition: CallbackStreamBuf.h:37
Kernel.h
GaudiPython
Namespace for all classes interfacing Gaudi to Python.
Definition: Algorithm.h:29
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
GaudiPython::call_python_method
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition: Algorithm.cpp:48