26#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
27#include <numpy/arrayobject.h>
45 if (python_version.
IsNull()) {
53 if (python_version[0] ==
'2' || python_version[0] ==
'3')
56 if (python_version[0] ==
'2')
58 else if (python_version[0] ==
'3')
71PyObject *PyMethodBase::fModuleBuiltin = NULL;
75PyObject *PyMethodBase::fModulePickle = NULL;
76PyObject *PyMethodBase::fPickleDumps = NULL;
77PyObject *PyMethodBase::fPickleLoads = NULL;
80PyObject *PyMethodBase::fGlobalNS = NULL;
86 :
MethodBase(jobName, methodType, methodTitle, dsi, theOption),
156 if (!pyIsInitialized) {
161 if (!pyIsInitialized) {
166 fMain = PyImport_AddModule(
"__main__");
180 #if PY_MAJOR_VERSION < 3
182 PyObject *bName = PyUnicode_FromString(
"__builtin__");
192 PyObject *bName = PyUnicode_FromString(
"builtins");
203 fEval = PyDict_GetItemString(mDict,
"eval");
204 fOpen = PyDict_GetItemString(mDict,
"open");
213 PyObject *pName = PyUnicode_FromString(
"pickle");
253 if (!Py_IsInitialized())
return kFALSE;
274 PyObject *file_arg = Py_BuildValue(
"(ss)", path.
Data(),
"wb");
281 Py_DECREF(model_arg);
282 Py_DECREF(model_data);
295 PyObject *file_arg = Py_BuildValue(
"(ss)", path.
Data(),
"rb");
306 Py_DECREF(model_arg);
347 std::cout<<
"\nPython error message:\n";
349 throw std::runtime_error(
"\nFailed to run python code: "+code);
360 PyObject* encodedString = PyUnicode_AsUTF8String(
string);
373 std::vector<size_t>tupleVec;
374 for(
Py_ssize_t tupleIter=0;tupleIter<PyTuple_Size(tupleObject);++tupleIter){
375 auto itemObj = PyTuple_GetItem(tupleObject,tupleIter);
376 if (itemObj == Py_None)
377 tupleVec.push_back(0);
379 tupleVec.push_back((
size_t)PyLong_AsLong(itemObj));
392 std::vector<size_t>listVec;
393 for(
Py_ssize_t listIter=0; listIter<PyList_Size(listObject);++listIter){
394 listVec.push_back((
size_t)PyLong_AsLong(PyList_GetItem(listObject,listIter)));
407 #if PY_MAJOR_VERSION >= 3
408 return PyDict_GetItemWithError(dict,PyUnicode_FromString(key));
410 if(!PyDict_Contains(dict, PyUnicode_FromString(key))){
411 throw std::runtime_error(std::string(
"Key ")+key+
" does not exist in the dictionary.");
413 return PyDict_GetItemString(dict, key);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
R__EXTERN TSystem * gSystem
Class that contains all the data information.
PyGILState_STATE m_GILState
Virtual base Class for all MVA method.
ostringstream derivative to redirect and format output
static std::vector< size_t > GetDataFromTuple(PyObject *tupleObject)
Utility function which retrieves and returns the values of the Tuple object as a vector of size_t.
static int PyIsInitialized()
Check Python interpreter initialization status.
static std::vector< size_t > GetDataFromList(PyObject *listObject)
Utility function which retrieves and returns the values of the List object as a vector of size_t.
static PyObject * fPickleDumps
PyObject * Eval(TString code)
Evaluate Python code.
static void PyInitialize()
Initialize Python interpreter.
static void Serialize(TString file, PyObject *classifier)
Serialize Python object.
static Int_t UnSerialize(TString file, PyObject **obj)
Unserialize Python object.
static const char * PyStringAsString(PyObject *string)
Returns const char* from Python string in PyObject.
static PyObject * fPickleLoads
static PyObject * fGlobalNS
static PyObject * fModulePickle
static PyObject * fModuleBuiltin
PyMethodBase(const TString &jobName, Types::EMVA methodType, const TString &methodTitle, DataSetInfo &dsi, const TString &theOption="")
static PyObject * GetValueFromDict(PyObject *dict, const char *key)
Utility function which checks if a given key is present in a Python dictionary object and returns the...
void PyRunString(TString code, TString errorMessage="Failed to run python code", int start=256)
Execute Python code from string.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual TString GetFromPipe(const char *command)
Execute command and return output in TString.
create variable transformations
TString Python_Executable()
Function to find current Python executable used by ROOT If Python2 is installed return "python" Inste...
MsgLogger & Endl(MsgLogger &ml)