Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-14 09:08:06

0001 // Author: Enric Tejedor CERN  08/2019
0002 // Original PyROOT code by Wim Lavrijsen, LBL
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TPython
0013 #define ROOT_TPython
0014 
0015 // ROOT
0016 #include "TObject.h"
0017 
0018 #include <any>
0019 #include <cstdint>
0020 
0021 // Python
0022 struct _object;
0023 typedef _object PyObject;
0024 
0025 namespace ROOT {
0026 namespace Internal {
0027 
0028 // Internal helper for PyROOT to swap with an object is at a specific address.
0029 template<class T>
0030 inline void SwapWithObjAtAddr(T &a, std::intptr_t b) { std::swap(a, *reinterpret_cast<T*>(b)); }
0031 
0032 }
0033 }
0034 
0035 // Access to the python interpreter and API onto PyROOT.
0036 class TPython {
0037 
0038 private:
0039    static Bool_t Initialize();
0040 
0041 public:
0042    // import a python module, making its classes available
0043    static Bool_t Import(const char *name);
0044 
0045    // load a python script as if it were a macro
0046    static void LoadMacro(const char *name);
0047 
0048    // execute a python stand-alone script, with argv CLI arguments
0049    static void ExecScript(const char *name, int argc = 0, const char **argv = nullptr);
0050 
0051    // execute a python statement (e.g. "import ROOT" )
0052    static Bool_t Exec(const char *cmd, std::any *result = nullptr, std::string const& resultName="_anyresult");
0053 
0054    // bind a ROOT object with, at the python side, the name "label"
0055    static Bool_t Bind(TObject *object, const char *label);
0056 
0057    // enter an interactive python session (exit with ^D)
0058    static void Prompt();
0059 
0060    // type verifiers for CPPInstance
0061    static Bool_t CPPInstance_Check(PyObject *pyobject);
0062    static Bool_t CPPInstance_CheckExact(PyObject *pyobject);
0063 
0064    // type verifiers for CPPOverload
0065    static Bool_t CPPOverload_Check(PyObject *pyobject);
0066    static Bool_t CPPOverload_CheckExact(PyObject *pyobject);
0067 
0068    // CPPInstance to void* conversion
0069    static void *CPPInstance_AsVoidPtr(PyObject *pyobject);
0070 
0071    // void* to CPPInstance conversion, returns a new reference
0072    static PyObject *CPPInstance_FromVoidPtr(void *addr, const char *classname, Bool_t python_owns = kFALSE);
0073 
0074    virtual ~TPython() {}
0075    ClassDef(TPython, 0) // Access to the python interpreter
0076 };
0077 
0078 #endif