# Error writing trees with Snapshot and ImplicitMT

**URL:** <https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965>\
**Category:** ROOT\
**Tags:** bug, rdataframe\
**Created:** [November 26, 2019, 4:27pm UTC](https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965 "2019-11-26T16:27:45Z")\
**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:** [November 26, 2019, 4:27pm UTC](https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965/1 "2019-11-26T16:27:46Z")

</div>

If I try to create a `Snapshot` with `ImplicitMT` enabled using a tree name that includes a directory, I get the error

```nohighlight
Error in <ROOT::Experimental::TBufferMergerFile::mkdir>: An object with name testdir exists already

```

multiple times, implying it attempts to create the directory multiple times.

I’m not sure why this is, as I thought each thread called `mkdir` on its own file (see [here](https://root.cern.ch/doc/master/ActionHelpers_8hxx_source.html#l01296)), but I went ahead and created a [pull request](https://github.com/root-project/root/pull/4649) that solves this problem by allowing `mkdir` to return an existing directory instead of raising an error.

Details below.

* * *

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

* * *

Before my fix:

* * *

I can make a `Snapshot` just fine without multithreading:

```python
In [1]: import ROOT

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

In [3]: df.Snapshot('testdir/testtree', 'test.root')
Out[3]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7ffac5fcda00>

```

or:

```python
In [1]: import ROOT

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

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

In [4]: df.Snapshot('testdir/testtree', 'test.root')
Out[4]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7f99317b2cf0>

```

But if I enable multithreading, I get errors:

```python
In [1]: import ROOT

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

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

In [4]: df.Snapshot('testdir/testtree', 'test.root')
Error in <ROOT::Experimental::TBufferMergerFile::mkdir>: An object with name testdir exists already
Error in <ROOT::Experimental::TBufferMergerFile::mkdir>: An object with name testdir exists already
Error in <ROOT::Experimental::TBufferMergerFile::mkdir>: An object with name testdir exists already
Error in <ROOT::Experimental::TBufferMergerFile::mkdir>: An object with name testdir exists already
Out[4]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fdfee302690>

```

* * *

after my fix:

* * *

It still works fine without multithreading:

```python
In [1]: import ROOT

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

In [3]: df.Snapshot('testdir/testtree', 'test.root')
Out[3]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fcdc5e8b380>

```

or

```python
In [1]: import ROOT

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

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

In [4]: df.Snapshot('testdir/testtree', 'test.root')
Out[4]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fe6ba492640>

```

and still raises no errors if I have multithreading enabled:

```python
In [1]: import ROOT

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

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

In [4]: df.Snapshot('testdir/testtree', 'test.root')
Out[4]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7ffe6a3e7f50>

```

---

<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:** [December 9, 2019, 11:42am UTC](https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965/2 "2019-12-09T11:42:57Z")

</div>

Thanks to @pcanal the PR was merged and this is fixed.

---

<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:** [December 9, 2019, 2:04pm UTC](https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965/3 "2019-12-09T14:04:11Z")

</div>

Indeed, thanks much to the ROOT team for your prompt response.

---

<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:** [December 23, 2019, 2:04pm UTC](https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965/4 "2019-12-23T14:04:12Z")

</div>

Closed on December 23, 2019, 2:04pm UTC

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