# Reading vectors from a tree

**URL:** <https://root-forum.cern.ch/t/reading-vectors-from-a-tree/44801>\
**Category:** General Chat\
**Created:** [May 10, 2021, 6:49pm UTC](https://root-forum.cern.ch/t/reading-vectors-from-a-tree/44801 "2021-05-10T18:49:12Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 11, 2021, 9:58am UTC](https://root-forum.cern.ch/t/reading-vectors-from-a-tree/44801/5 "2021-05-11T09:58:24Z")

</div>

Please note that [TTree::GetVal](https://root.cern/doc/master/classTTree.html#a3ad3433f279c1b6f54083e40b8fcc717) retrieves the results of the most recent [TTree::Draw](https://root.cern/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45) and nothing else.

Something like this should work:

```cpp
vector<double> *Station = 0;
t->SetBranchAddress("Station", &Station);
Long64_t n = t->GetEntries();
for (Long64_t i = 0; i < n; i++) {
  t->GetEntry(i);
  ULong_t nsig = Station->size(); // MUST be done for every tree entry
  double *sig = Station->data(); // MUST be done for every tree entry
  for (ULong_t j = 0; j < nsig; j++) {
    std::cout << i << " : " << j << " : " << sig[j] << std::endl;
  }
}
t->ResetBranchAddresses(); // disconnect from local variables
delete Station; // cleanup

```

---

_[View the full topic](https://root-forum.cern.ch/t/reading-vectors-from-a-tree/44801)._
