# Extract entries with vector type branches

**URL:** <https://root-forum.cern.ch/t/extract-entries-with-vector-type-branches/15565>\
**Category:** ROOT\
**Created:** [January 30, 2013, 3:52pm UTC](https://root-forum.cern.ch/t/extract-entries-with-vector-type-branches/15565 "2013-01-30T15:52:02Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![llvll0hsen](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@llvll0hsen](https://root-forum.cern.ch/u/llvll0hsen)\
**Post date:** [January 31, 2013, 10:01am UTC](https://root-forum.cern.ch/t/extract-entries-with-vector-type-branches/15565/3 "2013-01-31T10:01:21Z")

</div>

Thanks for you reply

> [@wlav](#):
>
> not sure how you expect to get a vector with the last snippet of code

by just using result=tree.mybranch I get the data from my branch and np.array(result) I get the numpy array. other stuff are just changing the format of the array.

> [@](#):
>
> , but in answer of where to look for slowness in the first code, there are two places. One, is the creation of vectors if the branches are accessed as “data members” of the tree (an object is created on each “data member” lookup) and creating a single std::vector that is handed to SetBranchAddress() is the solution there.

I tried to used SetBranchAddress as it’s used in this thread ,second post ([Locate like command](https://root-forum.cern.ch/t/locate-like-command/65/1)) but it doesnt return the vector , just a single value !

The second issue is that the copying to the numpy array if done through the python interface, has a lot of overhead for each entry call: the iteration (in order to be generic) goes through the begin()/end() iteration thus has calls for each lookup, rather than simply accessing the memory directly as can be done for a vector when the size of its elements is known.

> [@](#):
>
> I don’t have further ideas for improvement (other than using a C++ helper and the numpy C-API to pass an address directly, instead of individual elements) within the context of CPython.

Can you provide me with an example to see how should I do that?

With PyPy/cppyy, and in particularly Cling, it’s different matter: with a real compiler in the back, a helper can be generated for the std::vector at hand.

Thanks

---

_[View the full topic](https://root-forum.cern.ch/t/extract-entries-with-vector-type-branches/15565)._
