The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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
22namespace 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 {
28 PyObject* m_obj;
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
#define GAUDI_API
Definition Kernel.h:49
int sync() override
reimplementation of stringbuf::sync()
std::array< char, 512 > m_callbackBuff
CallbackStreamBuf(PyObject *self)
CallbackStreamBuf constructor.
GaudiPython.h GaudiPython/GaudiPython.h.
Definition Algorithm.h:29
GAUDI_API StatusCode call_python_method(PyObject *self, const char *method)
call the python method
Definition Algorithm.cpp:48