Macro to Add Array to TTree branch crashes

Hello,

I have been using the following macro to try and create the array “Edeps” and then write it to a tree branch called “Edeps” on a new TTree called newtree:

void TreeMake(){

Double_t Edeps[2457248];

TFile* outfile = new TFile(“Test-Tree.root”, “NEW”);
TTree *newtree = new TTree(“newtree”, “Testing”);
newtree->Branch(“Edeps”,Edeps, “Edeps[2457248]/D”);

Int_t marker=0;
Double_t values[384]={876, 1361, 1453, 1508, 1511, 1596, 1636, 1691, 1648, 1705, 1741, 1804, 1939, 1906, 2019, 1924, 1966, 2126, 2105, 2073, 2108, 2093, 2209, 2177, 2233, 2174, 2187, 2251, 2299, 2374, 2453, 2445, 2496, 2515, 2462, 2469, 2465, 2483, 2490, 2554, 2556, 2581, 2666, 2709, 2653, 2670, 2737, 2709, 2709, 2705, 2778, 2640, 2778, 2824, 2670, 2764, 2740, 2714, 2695, 2705, 2680, 2797, 2685, 2775, 2826, 2687, 2613, 2722, 2722, 2726, 2758, 2712, 2752, 2768, 2764, 2733, 2878, 2729, 2815, 2806, 2957, 3051, 2808, 2881, 3023, 2979, 2983, 3131, 3073, 3215, 3331, 3249, 3485, 3395, 3637, 3652, 3652, 3797, 3976, 4007, 4079, 4208, 4300, 4457, 4535, 4661, 4786, 4963, 4966, 5018, 5201, 5416, 5329, 5578, 5567, 5846, 5885, 5952, 6123, 6221, 6407, 6572, 6631, 6674, 6885, 6855, 7256, 7343, 7180, 7493, 7690, 7583, 7979, 7978, 8167, 8384, 8600, 8525, 8635, 8763, 8996, 8854, 9251, 9456, 9252, 9480, 9704, 9809, 10065, 10286, 10434, 10709, 10413, 10795, 10722, 10861, 10855, 11016, 10806, 11195, 12843, 10829, 10861, 11036, 10790, 10901, 10641, 10954, 10441, 10544, 10815, 10545, 10407, 10421, 10623, 10432, 10173, 10108, 10072, 9803, 10086, 10078, 9679, 9863, 9545, 9413, 9484, 9375, 9353, 9345, 9348, 9057, 8964, 8977, 8787, 8890, 8752, 8604, 8662, 8621, 8393, 8468, 8384, 8323, 8169, 8206, 7966, 7673, 7482, 7300, 7106, 7255, 7198, 6932, 6971, 6897, 6778, 6857, 6797, 6669, 6699, 6637, 6523, 8786, 6496, 6493, 6485, 6491, 6289, 6475, 6225, 6134, 6164, 6012, 6095, 5952, 6012, 6108, 5974, 5852, 5995, 5918, 5852, 5852, 5837, 5857, 5818, 5804, 5676, 5746, 5570, 5633, 5820, 5763, 5645, 5618, 5687, 5476, 5644, 5632, 5562, 5543, 5507, 5433, 5543, 5478, 5520, 5487, 5420, 5565, 5420, 5393, 5397, 5352, 5327, 5227, 44765, 4786, 4787, 4924, 4959, 4920, 4924, 4763, 4742, 4661, 4808, 4806, 4872, 4834, 4769, 4786, 4755, 4737, 4663, 4737, 4654, 4666, 4626, 4544, 4548, 4531, 109516, 3582, 3612, 3588, 3536, 3555, 3553, 3496, 3471, 3332, 3407, 3433, 3412, 3444, 3378, 3281, 3412, 3494, 3473, 3391, 3363, 3401, 3364, 3403, 3353, 3344, 3387, 3338, 3342, 3365, 3218, 3288, 3260, 3378, 3299, 3355, 3333, 3240, 3216, 3217, 3248, 3269, 3282, 3249, 3076, 3102, 3022, 2994, 3000, 3025, 2949, 2906, 2789, 2093, 356089, 371, 362, 383, 344, 383, 370, 392, 384, 320, 390, 347, 378, 376, 397, 391, 349, 344, 331, 333, 342, 324, 333, 302, 312, 339, 304, 52284};

for (Int_t j=0;j<384;++j) {

for (Int_t i=0;i<values[marker];++i) {
  Edeps[i]=marker;
}
  marker+=1;

}
newtree->Fill();
newtree->Write();
}

This is compiling fine but when I run the function root is crashing with no error message.
Could someone please point out what could be the cause of the crash?

Just FYI:

First problem is the size of the array. Reducing it stops ROOT from exiting without providing a message. ROOT is exiting with return code 11 (ROOT 6.10.04).

void test() {
   Double_t Edeps[2457248];
   
   TFile* outfile = new TFile("Test-Tree.root", "NEW");
   TTree *newtree = new TTree("newtree", "Testing");
   newtree->Branch("Edeps",Edeps, "Edeps[2457248]/D"); //exits here

   outfile->Close();
   std::cout << "Completed successfully!\n";
}

This looks like a question for @pcanal.

Yes the array is >18 MB. I had a feeling it was a memory issue, but had not yet observed the behavior where ROOT simply quits.

The problem is

Double_t Edeps[2457248];

which is too big for the usually stack settings. For example on my machine it is set to only 8MB:

ulimit -a
...
stack size              (kbytes, -s) 8192
...

Cheers,
Philippe.

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