26#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
27#include <numpy/arrayobject.h>
45 if (python_version.
IsNull()) {
46 TMVA::gTools().
Log() << kFATAL <<
"Can't find a valid Python version used to build ROOT" <<
Endl;
53 if (python_version[0] ==
'2' || python_version[0] ==
'3')
56 if (python_version[0] ==
'2')
58 else if (python_version[0] ==
'3')
61 TMVA::gTools().
Log() << kFATAL <<
"Invalid Python version used to build ROOT : " << python_version <<
Endl;
86 :
MethodBase(jobName, methodType, methodTitle, dsi, theOption),
96 Log() << kFATAL <<
"Can't init local namespace" <<
Endl;
114 Log() << kFATAL <<
"Can't init local namespace" <<
Endl;
158 if (!pyIsInitialized) {
163 if (!pyIsInitialized) {
168 fMain = PyImport_AddModule(
"__main__");
170 Log << kFATAL <<
"Can't import __main__" <<
Endl;
177 Log << kFATAL <<
"Can't init global namespace" <<
Endl;
182 #if PY_MAJOR_VERSION < 3
184 PyObject *bName = PyUnicode_FromString(
"__builtin__");
189 Log << kFATAL <<
"Can't import __builtin__" <<
Endl;
194 PyObject *bName = PyUnicode_FromString(
"builtins");
198 Log << kFATAL <<
"Can't import builtins" <<
Endl;
205 fEval = PyDict_GetItemString(mDict,
"eval");
206 fOpen = PyDict_GetItemString(mDict,
"open");
215 PyObject *pName = PyUnicode_FromString(
"pickle");
220 Log << kFATAL <<
"Can't import pickle" <<
Endl;
255 if (!Py_IsInitialized())
return kFALSE;
276 PyObject *file_arg = Py_BuildValue(
"(ss)", path.
Data(),
"wb");
278 PyObject *model_arg = Py_BuildValue(
"(OO)", obj,file);
283 Py_DECREF(model_arg);
284 Py_DECREF(model_data);
297 PyObject *file_arg = Py_BuildValue(
"(ss)", path.
Data(),
"rb");
302 PyObject *model_arg = Py_BuildValue(
"(O)", file);
308 Py_DECREF(model_arg);
329 Log() << kWARNING <<
"Failed to run python code: " << code <<
Endl;
330 Log() << kWARNING <<
"Python error message:" <<
Endl;
332 Log() << kFATAL << errorMessage <<
Endl;
350 std::cout<<
"\nPython error message:\n";
352 throw std::runtime_error(
"\nFailed to run python code: "+code);
363 PyObject* encodedString = PyUnicode_AsUTF8String(
string);
376 std::vector<size_t>tupleVec;
377 for(
Py_ssize_t tupleIter=0;tupleIter<PyTuple_Size(tupleObject);++tupleIter){
378 auto itemObj = PyTuple_GetItem(tupleObject,tupleIter);
379 if (itemObj == Py_None)
380 tupleVec.push_back(0);
382 tupleVec.push_back((
size_t)PyLong_AsLong(itemObj));
395 std::vector<size_t>listVec;
396 for(
Py_ssize_t listIter=0; listIter<PyList_Size(listObject);++listIter){
397 listVec.push_back((
size_t)PyLong_AsLong(PyList_GetItem(listObject,listIter)));
411 return PyDict_GetItemWithError(dict, PyUnicode_FromString(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 "Python3" is installed,...
MsgLogger & Endl(MsgLogger &ml)