# Snapshot complains when updating existing directory

**URL:** <https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935>\
**Category:** ROOT\
**Tags:** bug, rdataframe\
**Created:** [February 11, 2020, 4:51pm UTC](https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935 "2020-02-11T16:51:04Z")\
**Posts on this page:** 5\
**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 11, 2020, 4:51pm UTC](https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935/1 "2020-02-11T16:51:04Z")

</div>

If one tries to update a directory inside an existing file, `Snapshot` complains:  
`Error in <TFile::mkdir>: An object with name hi exists already`  
Reproducer below.

I have made a [pull request](https://github.com/root-project/root/pull/4964) that resolves the issue. Note that this is similar to [pull request 4649](https://github.com/root-project/root/pull/4649), related to [this post in the forum](https://root-forum.cern.ch/t/error-writing-trees-with-snapshot-and-implicitmt/36965).

* * *

Before fix:

```python
In [1]: import ROOT

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

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

In [4]: df2 = ROOT.RDataFrame(10).Define('e', 'rdfentry_ * 10')

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

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

In [7]: df2.Snapshot('hi/there', 'test.root', '', snapopts)
Error in <TFile::mkdir>: An object with name hi exists already
Out[7]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fc3a3df8150>

```

after fix:

```python
In [1]: import ROOT

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

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

In [4]: df2 = ROOT.RDataFrame(10).Define('e', 'rdfentry_ * 10')

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

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

In [7]: df2.Snapshot('hi/there', 'test.root', '', snapopts)
Out[7]: <ROOT.ROOT::RDF::RResultPtr<ROOT::RDF::RInterface<ROOT::Detail::RDF::RLoopManager,void> > object at 0x7fe189c4b410>

```

* * *

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

* * *

---

<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:** [February 12, 2020, 9:09am UTC](https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935/2 "2020-02-12T09:09:38Z")

</div>

Replied in the linked PR.

---

<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:** [February 12, 2020, 3:39pm UTC](https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935/3 "2020-02-12T15:39:47Z")

</div>

PR has been merged. Thanks a lot!

---

<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 12, 2020, 3:56pm UTC](https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935/4 "2020-02-12T15:56:51Z")

</div>

Thanks to the ROOT team for the 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:** [February 26, 2020, 4:07pm UTC](https://root-forum.cern.ch/t/snapshot-complains-when-updating-existing-directory/37935/5 "2020-02-26T16:07:16Z")

</div>

Closed on February 26, 2020, 4:07pm UTC

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