# TMVA::MethodBDT throws St9bad\_alloc while reading trees

**URL:** <https://root-forum.cern.ch/t/tmva-methodbdt-throws-st9bad-alloc-while-reading-trees/13699>\
**Category:** TMVA\
**Created:** [January 31, 2012, 11:22am UTC](https://root-forum.cern.ch/t/tmva-methodbdt-throws-st9bad-alloc-while-reading-trees/13699 "2012-01-31T11:22:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdalton](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@mdalton](https://root-forum.cern.ch/u/mdalton)\
**Post date:** [January 31, 2012, 11:22am UTC](https://root-forum.cern.ch/t/tmva-methodbdt-throws-st9bad-alloc-while-reading-trees/13699/1 "2012-01-31T11:22:33Z")

</div>

Hi Everyone,

I get a St9bad\_alloc when I am reading the 4th tree (out of 200) from a txt weights file. The error comes from:

TMVA::MethodBDT::ReadWeightsFromStream( istream& istr )  
defined in  
tmva/src/MethodBDT.cxx

The trees were trained using root 5.16 and I am using root 5.28, but that shouldn’t be a problem, since other people on other systems have had no problems with this.

digging even deeper, the St9bad\_alloc crash comes from the line:

```
 currentNode = CreateNode(); // create a new node to be read next

```

in tmva/src/BinaryTree.cxx

The function is defined in:  
tmva/src/G\_\_TMVA2.cxx  
G\_\_memfunc\_setup(“CreateNode”,986,G\_\_G\_\_TMVA2\_243\_0\_4, 85,  
G\_\_get\_linked\_tagnum(&G\_\_G\_\_TMVA2LN\_TMVAcLcLNode), -1, 0, 0, 1, 1, 8,  
"", (char\*)NULL, (void  
\*) NULL, 3);

auto-generated by:  
core/utils/src/rootcint\_tmp

I don’t understand what this memfunc\_setup is or what the problem could be.

I’m using Red Hat 4.1.2. I don’t think I’m running out of memory, the weights file is only 18MB and it crashes already on the 4th out of 200 trees. Any thoughts?

Thanks,

Matt

---

<div class="post-metadata">

**Author:** ![mdalton](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@mdalton](https://root-forum.cern.ch/u/mdalton)\
**Post date:** [February 1, 2012, 2:52pm UTC](https://root-forum.cern.ch/t/tmva-methodbdt-throws-st9bad-alloc-while-reading-trees/13699/2 "2012-02-01T14:52:46Z")

</div>

I found the problem myself.  
In TMVA::DecisionTreeNode.cxx it reads in the records one at a time, including one variable called “ULong\_t lseq”. The training files were created on a machine which has 8 bytes for ULongs, but my machine uses has sizeof(ULong\_t) = 4. It’s a local variable (to the function) and is not stored anywhere so I changed it to a long long and recompiled, now it works fine.

I don’t know if I should submit a bug report over this, since it’s apparently a machine/compiler dependent thing.

Cheers,

Matt

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 3, 2012, 4:04pm UTC](https://root-forum.cern.ch/t/tmva-methodbdt-throws-st9bad-alloc-while-reading-trees/13699/3 "2012-02-03T16:04:59Z")

</div>

Hi Matt,

[quote]“ULong\_t lseq”. The training files were created on a machine which has 8 bytes for ULongs, but my machine uses has sizeof(ULong\_t) = 4. [/quote]This likely resulted in a (fatal) loss of data. Your solution is the right one (i.e. make sure no data is lost).

Cheers,  
Philippe.
