ROOT closes no warning or error given

Hi,

I am using ROOT 6.04/02 on a mac running OSX 10.9.5 and my code causes ROOT to exit without warning or errors printed out. I have narrowed it down to generating an array of a struct. The failure depends on where I create the array. If the array is generated outside of a function (line 7) or from the command line there is no issue and I can access the individual struct entries normally (ie tofile2[0], tofile2[1], …). However, when I attempt to execute runme1() ROOT exits to the mac terminal without warning or error. Any idea what I am doing wrong generating this array inside the function? Any insight would be greatly appreciated.

//Start sample code
#define CAEN 8
struct hist_file1{
char* pcolumnname;
int bin[CAEN*4096];
};
hist_file1 tofile2[290];

int runme1(int test = -100){
hist_file1 tofile[290];
return test;
}

int runme2(int test = -100){
return test;
}
//End

Best,
Francisco

Hi Francisco,

this looks like a stack smash. The total size of allocations you do on the stack seems too big of OSx (40968290 integers) - you cannot call runme1 even when the code is compiled.
You can fix it like this:

//Start sample code
#include <array>

constexpr unsigned int CAEN = 8;
constexpr unsigned int NCHANNELS = CAEN*4096;

struct hist_file1{
char* pcolumnname;
std::array<unsigned int,NCHANNELS> bin;
};
hist_file1 tofile2[290];

int runme1(int test = -100){
hist_file1 tofile[290];
return test;
}

int runme2(int test = -100){
return test;
}

int main(){

return runme1();

}

//End

You seem to want histograms where the bins are the channels of some device: if this is correct, you could use the TH1I class to represent histograms with integer bin content.

Cheers,
Danilo

Hi Danilo,

Thank you for your insight, you are correct about the histogram and adjusted my code to produce N - TH1I histograms as you pointed out and is working as desired. However, I have another struct that I am using for time, bin, and coincidence/anticoincidence tagging for which your solution would work wonderfully I just want to understand what I am doing first.

Having readup on the stack that does appear to be the source of the issue. I don’t understand why your solution clears the problem though. It appears as if you are simply changing the type of assignment from int to an array. But it has more to do with the location of the memory allocation away from the stack to elsewhere, is that correct? If so, where is it now?

Best,
Francisco