# Snapshot fails to update TTree if multithreading enabled

**URL:** <https://root-forum.cern.ch/t/snapshot-fails-to-update-ttree-if-multithreading-enabled/37961>\
**Category:** ROOT\
**Tags:** bug, rdataframe\
**Created:** [February 13, 2020, 7:04pm UTC](https://root-forum.cern.ch/t/snapshot-fails-to-update-ttree-if-multithreading-enabled/37961 "2020-02-13T19:04:02Z")\
**Posts on this page:** 4\
**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:** [February 13, 2020, 7:04pm UTC](https://root-forum.cern.ch/t/snapshot-fails-to-update-ttree-if-multithreading-enabled/37961/1 "2020-02-13T19:04:02Z")

</div>

If `ImplicitMT` is enabled, `Snapshot` cannot update a `TTree` at all unless the new dataframe contains the same branch names and types as the old one, in addition to any new ones. In addition, if the data frame does include the same names and types, it appends to the `TTree` instead of overwriting it. None of these are the case if multithreading is not enabled. Reproducer follows.

* * *

```python
In [1]: import ROOT

In [4]: ROOT.ROOT.EnableImplicitMT()

In [5]: df = ROOT.RDataFrame(10).Define('e', 'rdfentry_')

In [6]: df.Snapshot('t', 'test.root')
Out[6]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fecfa110150>

In [7]: snapopts = ROOT.RDF.RSnapshotOptions()

In [8]: snapopts.fMode = 'UPDATE'

```

Now, if I try to update `t` with a data frame with different column names:

```python
In [10]: df2 = ROOT.RDataFrame(10).Define('two', '2')

In [11]: df2.Snapshot('t', 'test.root', '', snapopts)
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Warning in <TTree::CopyEntries>: One of the export top level branches (e) is not present in the import TTree.
Out[11]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fecfc5bc4c0>

```

If I try to update `t` with the same columns but different types:

```python
In [10]: df3 = ROOT.RDataFrame(10).Define('e', '1000')

In [11]: df3.Snapshot('t', 'test.root', '', snapopts)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Warning in <TTree::CopyEntries>: The export leaf and the import leaf (e.e) do not have the data type (Int_t vs ULong64_t)
Out[11]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x61d2d80>

```

If I only **add** columns, no warnings are raised, but I end up with additional entries instead of overwritten ones:

```python
In [11]: df4 = df.Define('two', '2')

In [12]: snap = df4.Snapshot('t', 'test.root', '', snapopts)

In [13]: snap.Count().GetValue() # should equal 10
Out[13]: 20L

```

All of the above work without problems if multithreading is not enabled.

* * *

_ROOT Version:_ master  
_Platform:_ macOS  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![oshadura](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oshadura/32/14460_2.png) [@oshadura](https://root-forum.cern.ch/u/oshadura)\
**Post date:** [February 14, 2020, 8:44am UTC](https://root-forum.cern.ch/t/snapshot-fails-to-update-ttree-if-multithreading-enabled/37961/2 "2020-02-14T08:44:36Z")

</div>

Thanks a lot for reporting! Did you open Jira ticket already?  
@eguiraud @swunsch can you take a look please?

Oksana

---

<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:** [February 14, 2020, 12:36pm UTC](https://root-forum.cern.ch/t/snapshot-fails-to-update-ttree-if-multithreading-enabled/37961/3 "2020-02-14T12:36:42Z")

</div>

Created JIRA ticket [here](https://sft.its.cern.ch/jira/plugins/servlet/mobile#issue/ROOT-10573). Sorry for the delay.

---

<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:** [February 28, 2020, 12:41pm UTC](https://root-forum.cern.ch/t/snapshot-fails-to-update-ttree-if-multithreading-enabled/37961/4 "2020-02-28T12:41:06Z")

</div>

Closed on February 28, 2020, 12:41pm UTC

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