74 if (branch && !leaf) {
109 return {
nullptr,
""};
126 std::vector<dim_t> dims;
127 std::stringstream ss{title};
131 getline(ss, substr,
'[');
132 getline(ss, substr,
']');
133 if (!substr.empty()) {
134 dims.push_back(std::stoi(substr));
147 std::vector<dim_t> dimsVec{leaf->
GetNdata()};
148 std::string title = leaf->
GetTitle();
150 if (std::count(title.begin(), title.end(),
'[') >= 2) {
192 PyArg_ParseTuple(args,
"OU:GetBranchAttr", &self, &pyname);
194 const char *name_possibly_alias = PyUnicode_AsUTF8AndSize(pyname,
nullptr);
195 if (!name_possibly_alias)
202 PyErr_SetString(PyExc_ReferenceError,
"attempt to access a null-pointer");
207 const char *
name = tree->GetAlias(name_possibly_alias);
209 name = name_possibly_alias;
216 const auto [finalAddressVoidPtr, finalTypeName] =
ResolveBranch(tree,
name, branch);
217 if (!finalTypeName.empty()) {
218 PyObject *outTuple = PyTuple_New(2);
219 PyTuple_SetItem(outTuple, 0, PyLong_FromLongLong((intptr_t)finalAddressVoidPtr));
220 PyTuple_SetItem(outTuple, 1, PyUnicode_FromString((finalTypeName +
"*").c_str()));
229 if (wrapper !=
nullptr) {
230 PyObject *outTuple = PyTuple_New(2);
231 PyTuple_SetItem(outTuple, 0, wrapper);
232 PyTuple_SetItem(outTuple, 1, PyUnicode_FromString(
""));
238 PyErr_Format(PyExc_AttributeError,
"\'%s\' object has no attribute \'%s\'", tree->IsA()->GetName(),
name);
250 PyObject *
name =
nullptr, *address =
nullptr, *leaflist =
nullptr, *bufsize =
nullptr;
252 if (PyArg_ParseTuple(args,
"OO!OO!|O!:Branch", &treeObj, &PyUnicode_Type, &
name, &address, &PyUnicode_Type,
253 &leaflist, &PyLong_Type, &bufsize)) {
257 PyErr_SetString(PyExc_TypeError,
"TTree::Branch must be called with a TTree instance as first argument");
269 const char *nameString = PyUnicode_AsUTF8AndSize(
name,
nullptr);
273 const char *leaflistString = PyUnicode_AsUTF8AndSize(leaflist,
nullptr);
274 if (!leaflistString) {
278 branch = tree->Branch(nameString, buf, leaflistString, PyLong_AsLong(bufsize));
280 branch = tree->Branch(nameString, buf, leaflistString);
301 PyObject *
name =
nullptr, *clName =
nullptr, *address =
nullptr, *bufsize =
nullptr, *splitlevel =
nullptr;
303 auto bIsMatch =
false;
304 if (PyArg_ParseTuple(args,
"OO!O!O|O!O!:Branch", &treeObj, &PyUnicode_Type, &
name, &PyUnicode_Type, &clName,
305 &address, &PyLong_Type, &bufsize, &PyLong_Type, &splitlevel)) {
309 if (PyArg_ParseTuple(args,
"OO!O|O!O!", &treeObj, &PyUnicode_Type, &
name, &address, &PyLong_Type, &bufsize,
310 &PyLong_Type, &splitlevel)) {
320 PyErr_SetString(PyExc_TypeError,
"TTree::Branch must be called with a TTree instance as first argument");
326 const char *clNameString = PyUnicode_AsUTF8AndSize(clName,
nullptr);
330 klName = clNameString;
341 klName = GetTClass(address)->GetName();
348 if (buf && !klName.empty()) {
350 const char *nameString =
nullptr;
351 if (argc == 4 || argc == 5 || argc == 6) {
352 nameString = PyUnicode_AsUTF8AndSize(
name,
nullptr);
358 branch = tree->Branch(nameString, klName.c_str(), buf);
359 }
else if (argc == 5) {
360 branch = tree->Branch(nameString, klName.c_str(), buf, PyLong_AsLong(bufsize));
361 }
else if (argc == 6) {
362 branch = tree->Branch(nameString, klName.c_str(), buf, PyLong_AsLong(bufsize),
363 PyLong_AsLong(splitlevel));
395 int argc = PyTuple_Size(args);
399 if (branch != Py_None)
403 if (branch != Py_None)
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
static TBranch * SearchForBranch(TTree *tree, const char *name)
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 std::pair< void *, std::string > ResolveBranch(TTree *tree, const char *name, TBranch *branch)
static TLeaf * SearchForLeaf(TTree *tree, const char *name, TBranch *branch)
static std::vector< dim_t > getMultiDims(std::string const &title)
Extracts static dimensions from the title of a TLeaf object.
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.
const char * GetTitle() const override
Returns title 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".
Describe one element (data member) to be Streamed.
TObjArray * GetElements() const override
A TTree represents a columnar dataset.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual TLeaf * GetLeaf(const char *branchname, const char *leafname)
Return pointer to the 1st Leaf named name in any Branch of this Tree or any branch in the list of fri...
CPYCPPYY_EXTERN bool Instance_Check(PyObject *pyobject)
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 std::string Instance_GetScopedFinalName(PyObject *pyobject)
CPYCPPYY_EXTERN void * Instance_AsVoidPtr(PyObject *pyobject)
CPYCPPYY_EXTERN void DestroyConverter(Converter *p)
RPY_EXPORTED TCppScope_t GetScope(const std::string &scope_name)
PyObject * BranchPyz(PyObject *self, PyObject *args)
Add pythonization for TTree::Branch.
void GetBuffer(PyObject *pyobject, void *&buf)
PyObject * GetBranchAttr(PyObject *self, PyObject *args)