# RDataFrame with Friend Tree crashes when multithreading enabled

**URL:** <https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003>\
**Category:** ROOT\
**Tags:** bug, rdataframe\
**Created:** [May 10, 2019, 5:47pm UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003 "2019-05-10T17:47:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [May 10, 2019, 5:47pm UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003/1 "2019-05-10T17:47:46Z")

</div>

`RDataFrame` crashes when making a histogram if it has a friend and multithreading is enabled _before declaring the `RDataFrame`_.

Reproduce:

```python
import ROOT
f = ROOT.TFile.Open('f.root')
t = f.Get('tree')
t.AddFriend('otree', 'ff.root')

ROOT.ROOT.EnableImplicitMT()
df = ROOT.RDataFrame(t)
h = df.Histo1D('branch_in_t')
h.Sumw2()

```

result:

```auto
 ***Break*** segmentation violation
...
---------------------------------------------------------------------------
SystemError Traceback (most recent call last)
<ipython-input-6-6684c9e62ba9> in <module>()
----> 1 h1.Sumw2()

SystemError: TH1D& ROOT::RDF::RResultPtr<TH1D>::operator*() =>
    problem in C++; program state has been reset

```

* * *

_ROOT Version:_ 6.17/01  
_Platform:_ macOS  
_Compiler:_ Not Provided

* * *

PS: Examples that do not crash:  
No multithreading:

```python
import ROOT
f = ROOT.TFile.Open('f.root')
t = f.Get('tree')
t.AddFriend('otree', 'ff.root')

df = ROOT.RDataFrame(t)
h = df.Histo1D('branch_in_t')
h.Sumw2()

```

Multithreading _after_ `RDataFrame` declaration:

```python
import ROOT
f = ROOT.TFile.Open('f.root')
t = f.Get('tree')
t.AddFriend('otree', 'ff.root')

df = ROOT.RDataFrame(t)
ROOT.ROOT.EnableImplicitMT()
h = df.Histo1D('branch_in_t')
h.Sumw2()

```

No friend:

```python
import ROOT
f = ROOT.TFile.Open('f.root')
t = f.Get('tree')

ROOT.ROOT.EnableImplicitMT()
df = ROOT.RDataFrame(t)
h = df.Histo1D('branch_in_t')
h.Sumw2()
```

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 11, 2019, 8:30am UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003/2 "2019-05-11T08:30:34Z")

</div>

Hi,

thanks for filing this one. It’s on our [bug tracker](https://sft.its.cern.ch/jira/browse/ROOT-9559).  
Would it be possible to add there or here the two files which trigger the crash for completeness?

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [May 11, 2019, 1:00pm UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003/3 "2019-05-11T13:00:22Z")

</div>

Hi,

I cannot reproduce this. Here the example in Python (I tried in C++ too without being able to crash the macro or the compiled program):

```auto
import ROOT
f = ROOT.TFile.Open('test_tdfandfriends.root')
t = f.Get('t')
t.AddFriend('t2', 'test_tdfandfriends2.root')

ROOT.ROOT.EnableImplicitMT()
df = ROOT.RDataFrame(t)
h = df.Histo1D('x')
h.Sumw2()
print(h.GetMean())

```

(input files can be found here [https://cernbox.cern.ch/index.php/s/xO4VdXX0MIHy3kc](https://cernbox.cern.ch/index.php/s/xO4VdXX0MIHy3kc))

Can you help me out providing more details? Meanwhile the jira issue is closed. We can re-open it anytime.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [May 13, 2019, 12:47pm UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003/4 "2019-05-13T12:47:25Z")

</div>

I’ve checked using your files, and indeed, they work just fine. There are a couple differences, such as my files being larger and storing multiple trees in subdirectories. I have sent you a private message with a link to the files I am using on CERNbox.

---

<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:** [May 27, 2019, 12:47pm UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003/5 "2019-05-27T12:47:28Z")

</div>

Closed on May 27, 2019, 12:47pm UTC

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

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [September 9, 2020, 5:27pm UTC](https://root-forum.cern.ch/t/rdataframe-with-friend-tree-crashes-when-multithreading-enabled/34003/6 "2020-09-09T17:27:07Z")

</div>

In case someone stumbles upon this topic. I can’t check the files anymore but I believe this was [https://sft.its.cern.ch/jira/browse/ROOT-10152](https://sft.its.cern.ch/jira/browse/ROOT-10152) (“Cannot analyze friend trees in subdirectories with MT”) which is now fixed in master (the fix will be available in v6.22/04 and v6.24).
