Re: Strange errors with TTrees and TMultiLayerPerceptrons

From: Christian Holm Christensen <>
Date: Thu, 17 Feb 2005 15:37:24 +0100

Hi Dennis,

On Thu, 2005-02-17 at 14:03 +0100, Dennis Schieferdecker wrote:
> Hello!
> I've been working with the TMultiLayerPerceptron class from ROOT and
> have encoutnered some strange behaviours that none of my collegues and I
> could understand:
> I filled a ROOT tree in a function, returned it to the main program and
> then gave it as parameter to another function where I want to run the
> MLP over it. Here the program crashes with a stack violation even though
> the tree is still prior to starting the MLP in that function. When I put
> the MLP code in the same function that fills the tree, everything works
> fine.

My gut feeling is that it's because your local variables

        Double_t c1, c2, c3, c4, val;

in `readData' are exactly that - local. That means, that after exiting the function, they don't exist anymore. However, when you do

	TMultiLayerPerceptron *mlp = 
	  new TMultiLayerPerceptron("c1,c2,c3,c4:8:val",Train,"Entry$%2", "Entry$/2");
        mlp->Train(100, "text, graph, update=1");

you indirectly call `TTree::GetEntry' (or the like), which tries to read data into the variables `c1, c2, c3, c4, val', as you have set the branch addresses to point to these variables. However, the are no longer on the stack, so the runtime environment cannot pop them from there.

Indeed, if you move definition of `c1, c2, c3, c4, val' into the global scope (before readData), you get no errors. Now, the variables are available on the stack for the whole duration of the execution of your program.

However, a better solution is probably to send the message `ResetBranchAddresses' to your TTree object just before exiting the function `readData'. That also works. In this case, the branches are no longer associated with the local variables after completion of that function.

I hope that solves it for you.


 ___  |  Christian Holm Christensen 
  |_| |  -------------------------------------------------------------
    | |  Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|           DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|            Denmark                    Office: (+45) 353  25 404
 ____|   Email:               Web:
 | |
Received on Thu Feb 17 2005 - 15:37:27 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET