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