# Error in \<TRint::HandleTermInput()\>: std::out\_of\_range caught: vector::\_M\_range\_check: \_\_n (which is 0) \>= this-\>size() (which is 0)

**URL:** <https://root-forum.cern.ch/t/error-in-trint-handleterminput-std-out-of-range-caught-vector-m-range-check-n-which-is-0-this-size-which-is-0/27909>\
**Category:** ROOT\
**Created:** [February 13, 2018, 12:54am UTC](https://root-forum.cern.ch/t/error-in-trint-handleterminput-std-out-of-range-caught-vector-m-range-check-n-which-is-0-this-size-which-is-0/27909 "2018-02-13T00:54:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![avinay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@avinay](https://root-forum.cern.ch/u/avinay)\
**Post date:** [February 13, 2018, 12:54am UTC](https://root-forum.cern.ch/t/error-in-trint-handleterminput-std-out-of-range-caught-vector-m-range-check-n-which-is-0-this-size-which-is-0/27909/1 "2018-02-13T00:54:08Z")

</div>

Hi Experts

I had been using this macro to dump information from root files into a TTree. Suddenly when I increased the number of branches, I get this error:

```auto
Error in <TRint::HandleTermInput()>: std::out_of_range caught: vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)

```

I have never seen this error before and my guess is that I need to allocate memory or increase the size of my vector, but I don’t know how to do that.

I have attached the root macro.  
I’d appreciate any help. Please let me know if you need any more info.

Thanks!  
[demo\_ReadEvent.C](https://root-forum.cern.ch/uploads/default/original/2X/d/d96e19ba62c8783d24056993b6fa4343ce6dc277.C) (10.9 KB)

---

<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:** [February 13, 2018, 7:47am UTC](https://root-forum.cern.ch/t/error-in-trint-handleterminput-std-out-of-range-caught-vector-m-range-check-n-which-is-0-this-size-which-is-0/27909/2 "2018-02-13T07:47:24Z")

</div>

In your macro, you unconditionally access pointers without prior checking that they are not null (e.g. in `mctrack_vec(*mctrack_handle)` you do not check “mctrack\_handle”).  
You also unconditionally access vector elements without prior checking that its size is big enough (e.g. in `a.at(0).X()` in you do not check that `a.size() > 0`).  
You can easily “reproduce” your error:

```auto
root [0] std::vector<double> v;
root [1] std::cout << v.size() << std::endl;
root [2] std::cout << v.at(0) << std::endl;

```

---

<div class="post-metadata">

**Author:** ![avinay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/a698b9/32.png) [@avinay](https://root-forum.cern.ch/u/avinay)\
**Post date:** [February 13, 2018, 3:46pm UTC](https://root-forum.cern.ch/t/error-in-trint-handleterminput-std-out-of-range-caught-vector-m-range-check-n-which-is-0-this-size-which-is-0/27909/3 "2018-02-13T15:46:02Z")

</div>

Thank you @Wile_E_Coyote. Indeed for many cases I found that a.size()==0 which causes this error. Now I simply used an IF condition to skip over a.size()==0 events.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [February 27, 2018, 3:46pm UTC](https://root-forum.cern.ch/t/error-in-trint-handleterminput-std-out-of-range-caught-vector-m-range-check-n-which-is-0-this-size-which-is-0/27909/4 "2018-02-27T15:46:07Z")

</div>

Closed on February 27, 2018, 3:46pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
