# Copy std::vector from one TTree to another

**URL:** <https://root-forum.cern.ch/t/copy-std-vector-from-one-ttree-to-another/15255>\
**Category:** ROOT\
**Created:** [November 16, 2012, 8:23pm UTC](https://root-forum.cern.ch/t/copy-std-vector-from-one-ttree-to-another/15255 "2012-11-16T20:23:34Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![jfcaron](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/7c8e57/32.png) [@jfcaron](https://root-forum.cern.ch/u/jfcaron)\
**Post date:** [November 16, 2012, 8:23pm UTC](https://root-forum.cern.ch/t/copy-std-vector-from-one-ttree-to-another/15255/1 "2012-11-16T20:23:34Z")

</div>

Hello PyROOT experts. I have an input TFile with a TTree in it that has a few branches containing std::vector\<Int\_t\>. In analyzing the input, I produce an output TFile which has a new TTree, and I wish to have this TTree contain copies of the std::vectors from the input file. I don’t think I can just use the “Friendship” feature, because I am reducing the size of the trees, i.e. for one entry in the output TTree, I want copies of the std::vector branches from 40 (fixed) entries of the input TTree.

I know of a dumb way to do this, by creating 40 explicit branches in the output TTree using ROOT.std.vector(“Int\_t”)(), then for each input entry, loop over the elements of the std::vector and push\_back into the std::vector branch of the output tree. Doing it element-wise this way seems like a bad idea. The ROOT.std.vector doesn’t have a Copy or Clone method, so I don’t know how to copy the whole vector without using a python loop. There must be a way, or a way to link the 40 entries of the input tree into separate branches of the output tree. I also know I can make a vector\<vector\<Int\_t\>\> on the python side, so I could make a 40-element vector with copies of the original vectors as the elements, but again I don’t know how to do this without resorting to an element-by-element copy in python.

I guess in the end I don’t really care if the output branches are std::vectors or some other kind of container like python array.arrays.

Thanks for any help,  
Jean-François

---

_[View the full topic](https://root-forum.cern.ch/t/copy-std-vector-from-one-ttree-to-another/15255)._
