13#include "../../cppyy/CPyCppyy/src/CPyCppyy.h"
14#include "../../cppyy/CPyCppyy/src/CPPInstance.h"
15#include "../../cppyy/CPyCppyy/src/ProxyWrappers.h"
16#include "../../cppyy/CPyCppyy/src/Utility.h"
20#ifdef CPYCPPYY_VERSION_HEX
21#include "../../cppyy/CPyCppyy/src/Dimensions.h"
57 branch = tree->GetBranch((std::string(
name) +
'.').c_str());
65 if (branch && !leaf) {
97 if (klass && !tree->GetLeaf(
name) && !(leaves->
GetSize() && (leaves->
First() == leaves->
Last())))
110#ifdef CPYCPPYY_VERSION_HEX
147 const char *name_possibly_alias = PyUnicode_AsUTF8(pyname);
148 if (!name_possibly_alias)
155 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
160 const char *
name = tree->GetAlias(name_possibly_alias);
162 name = name_possibly_alias;
170 if (proxy !=
nullptr)
180 if (wrapper !=
nullptr)
185 PyErr_Format(PyExc_AttributeError,
"\'%s\' object has no attribute \'%s\'", tree->IsA()->GetName(),
name);
199 PyObject *pyclass = PyTuple_GetItem(args, 0);
221 PyObject *treeObj =
nullptr, *
name =
nullptr, *address =
nullptr;
223 int argc = PyTuple_GET_SIZE(args);
226 auto argParseStr =
"OUO:SetBranchAddress";
227 if (argc == 3 && PyArg_ParseTuple(args, argParseStr, &treeObj, &
name, &address)) {
232 PyErr_SetString(PyExc_TypeError,
233 "TTree::SetBranchAddress must be called with a TTree instance as first argument");
237 auto branchName = PyUnicode_AsUTF8(
name);
238 auto branch = tree->GetBranch(branchName);
240 PyErr_SetString(PyExc_TypeError,
"TTree::SetBranchAddress must be called with a valid branch name");
253 buf = (
void *)&(((
CPPInstance *)address)->GetObjectRaw());
257 if (buf !=
nullptr) {
258 auto res = tree->SetBranchAddress(PyUnicode_AsUTF8(
name), buf);
259 return PyInt_FromLong(res);
275 PyObject *
name =
nullptr, *address =
nullptr, *leaflist =
nullptr, *bufsize =
nullptr;
277 if (PyArg_ParseTuple(args,
"OO!OO!|O!:Branch",
279 &PyUnicode_Type, &
name,
281 &PyUnicode_Type, &leaflist,
282 &PyInt_Type, &bufsize)) {
286 PyErr_SetString(PyExc_TypeError,
"TTree::Branch must be called with a TTree instance as first argument");
299 branch = tree->Branch(PyUnicode_AsUTF8(
name), buf, PyUnicode_AsUTF8(leaflist),
300 PyInt_AS_LONG(bufsize));
302 branch = tree->Branch(PyUnicode_AsUTF8(
name), buf, PyUnicode_AsUTF8(leaflist));
323 PyObject *
name =
nullptr, *clName =
nullptr, *address =
nullptr, *bufsize =
nullptr, *splitlevel =
nullptr;
325 auto bIsMatch =
false;
326 if (PyArg_ParseTuple(args,
"OO!O!O|O!O!:Branch",
328 &PyUnicode_Type, &
name,
329 &PyUnicode_Type, &clName,
331 &PyInt_Type, &bufsize,
332 &PyInt_Type, &splitlevel)) {
336 if (PyArg_ParseTuple(args,
"OO!O|O!O!",
338 &PyUnicode_Type, &
name,
340 &PyInt_Type, &bufsize,
341 &PyInt_Type, &splitlevel)) {
351 PyErr_SetString(PyExc_TypeError,
"TTree::Branch must be called with a TTree instance as first argument");
355 std::string klName = clName ? PyUnicode_AsUTF8(clName) :
"";
365 klName = GetTClass(address)->GetName();
372 if (buf && !klName.empty()) {
375 branch = tree->Branch(PyUnicode_AsUTF8(
name), klName.c_str(), buf);
376 }
else if (argc == 5) {
377 branch = tree->Branch(PyUnicode_AsUTF8(
name), klName.c_str(), buf, PyInt_AS_LONG(bufsize));
378 }
else if (argc == 6) {
379 branch = tree->Branch(PyUnicode_AsUTF8(
name), klName.c_str(), buf, PyInt_AS_LONG(bufsize),
380 PyInt_AS_LONG(splitlevel));
412 int argc = PyTuple_GET_SIZE(args);
416 if (branch != Py_None)
420 if (branch != Py_None)
std::ios_base::fmtflags fFlags
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
static TBranch * SearchForBranch(TTree *tree, const char *name)
static PyObject * BindBranchToProxy(TTree *tree, const char *name, TBranch *branch)
PyObject * TryBranchLeafListOverload(int argc, PyObject *args)
Try to match the arguments of TTree::Branch to the following overload:
PyObject * TryBranchPtrToPtrOverloads(int argc, PyObject *args)
Try to match the arguments of TTree::Branch to one of the following overloads:
static TLeaf * SearchForLeaf(TTree *tree, const char *name, TBranch *branch)
PyObject * GetAttr(PyObject *self, PyObject *pyname)
static PyObject * WrapLeaf(TLeaf *leaf)
virtual PyObject * FromMemory(void *address)
A Branch for the case of an object.
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
virtual TClass * GetTargetClass()
char * GetObject() const
Return a pointer to our object.
A TTree is a list of TBranches.
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
virtual char * GetAddress() const
TClass * IsA() const override
TObjArray * GetListOfLeaves()
TClass instances represent classes, structs and namespaces in the ROOT type system.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual void * GetValuePointer() const
virtual const char * GetTypeName() const
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
TClass * IsA() const override
virtual Int_t GetNdata() const
TBranch * GetBranch() const
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
const char * GetName() const override
Returns name of object.
TObject * Last() const override
Return the object in the last filled slot. Returns 0 if no entries.
TObject * At(Int_t idx) const override
TObject * First() const override
Return the object in the first slot.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
TObjArray * GetElements() const override
A TTree represents a columnar dataset.
Py_ssize_t GetBuffer(PyObject *pyobject, char tc, int size, void *&buf, bool check=true)
bool AddToClass(PyObject *pyclass, const char *label, PyCFunction cfunc, int flags=METH_VARARGS)
CPYCPPYY_EXTERN bool Instance_Check(PyObject *pyobject)
CPYCPPYY_EXTERN PyObject * Instance_FromVoidPtr(void *addr, const std::string &classname, bool python_owns=false)
bool CPPInstance_Check(T *object)
CPYCPPYY_EXTERN Converter * CreateConverter(const std::string &name, cdims_t=0)
PyObject * BindCppObject(Cppyy::TCppObject_t object, Cppyy::TCppType_t klass, const unsigned flags=0)
CPYCPPYY_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
CPYCPPYY_EXTERN void DestroyConverter(Converter *p)
RPY_EXPORTED std::string GetScopedFinalName(TCppType_t type)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
PyObject * SetBranchAddressPyz(PyObject *self, PyObject *args)
Add pythonization for TTree::SetBranchAddress.
PyObject * BranchPyz(PyObject *self, PyObject *args)
Add pythonization for TTree::Branch.
PyObject * AddBranchAttrSyntax(PyObject *self, PyObject *args)
Allow branches to be accessed as attributes of a tree.