# Macro to Add Array to TTree branch crashes

**URL:** <https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047>\
**Category:** ROOT\
**Created:** [August 28, 2017, 2:58pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047 "2017-08-28T14:58:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgauthier](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@sgauthier](https://root-forum.cern.ch/u/sgauthier)\
**Post date:** [August 28, 2017, 2:58pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/1 "2017-08-28T14:58:32Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [August 28, 2017, 2:59pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/2 "2017-08-28T14:59:59Z")

</div>

Just FYI:

> [@Getting the same histograms after cuts](https://root-forum.cern.ch/t/getting-the-same-histograms-after-cuts/24719/2):
>
> Remark on the way to post code snippets: When you post pieces of code on the forum enclose it with ``` . That makes your post much more readable (I systematically edit your posts that way) . So do: ``` // this is a C++ piece of code. ``` And it will display as: // this is a C++ piece of code.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [August 28, 2017, 3:23pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/3 "2017-08-28T15:23:39Z")

</div>

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).

```auto
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.

---

<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:** [August 28, 2017, 3:37pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/4 "2017-08-28T15:37:17Z")

</div>

> [@No error when macro crashes](https://root-forum.cern.ch/t/no-error-when-macro-crashes/14931/2):
>
> Nothing in the “output”, that you show in your post, suggests that your macro “died” in any way. Try to add some “debug” lines, e.g.: std::cout \<\< "Before totalPE" \<\< std::endl \<\< std::flush; Double\_t totalPE[fiberNum][numOfVoxels]; std::cout \<\< "After totalPE" \<\< std::endl \<\< std::flush; There is just one possible problem in the line that you suspect. Your “Double\_t totalPE[768][161616];” is 24MB long. It is possible that this exceeds your stack size “limit”. Try: [bash]$ ulimit -S -a [ba…

> [@Upper limit of entries in one bin and in whole histogram](https://root-forum.cern.ch/t/upper-limit-of-entries-in-one-bin-and-in-whole-histogram/15475/2):
>
> [TH2F](http://root.cern.ch/root/html/TH2.html) bins are [“Float / Single precision floating-point numbers” (4 Bytes = 32 bits)](http://en.wikipedia.org/wiki/Single_precision)[TH2D](http://root.cern.ch/root/html/TH2.html) bins are [“Double precision floating-point numbers” (8 Bytes = 64 bits)](http://en.wikipedia.org/wiki/Double_precision) See also: [Wikipedia - Floating point](http://en.wikipedia.org/wiki/Floating_point) You don’t say how your program crashes, but … If I were you I would start to search for “memory leaks” in the procedure that fills histograms. Try to run your code using valgrind (and carefully study messages that appear in the beginning of the output): valgrind --tool=memcheck --leak-check=full […

> [@Issue 3D histogram](https://root-forum.cern.ch/t/issue-3d-histogram/16012/4):
>
> In general, the operating system imposes some “user limits”. Try: [bash]$ ulimit -S -a [bash]$ ulimit -H -a [tcsh]$ limit [tcsh]$ limit -h If any application, while running, exceeds any of these limits, it will be killed (note also, on a i686 32-bit system, the address space is 4 GB; no such problem on a x86\_64 64-bit system, as long as you have enough RAM plus “swap space” available).

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [August 28, 2017, 3:42pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/5 "2017-08-28T15:42:47Z")

</div>

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.

---

<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:** [August 28, 2017, 5:37pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/6 "2017-08-28T17:37:50Z")

</div>

The problem is

```auto
Double_t Edeps[2457248];

```

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

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

```

Cheers,  
Philippe.

---

<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:** [September 11, 2017, 5:37pm UTC](https://root-forum.cern.ch/t/macro-to-add-array-to-ttree-branch-crashes/26047/7 "2017-09-11T17:37:56Z")

</div>

Closed on September 11, 2017, 5:37pm UTC

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