# Snapshot method overriding specified root file

**URL:** <https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494>\
**Category:** Newbie\
**Created:** [December 11, 2023, 10:45am UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494 "2023-12-11T10:45:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amishgog](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amishgog/32/34940_2.png) [@amishgog](https://root-forum.cern.ch/u/amishgog)\
**Post date:** [December 11, 2023, 10:45am UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494/1 "2023-12-11T10:45:26Z")

</div>

So in the topic here: [Applying cuts to histogram without having a TTree branch](https://root-forum.cern.ch/t/applying-cuts-to-histogram-without-having-a-ttree-branch/57441)

I specified the solution as using the Snapshot method to add a branch to a tree in the root file. However I had one other tree in my root file which was lost. So I wanted to ask is there a way to avoid this? Thanks

_ROOT Version:_ 6.3.0 (PyROOT)

---

<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:** [December 11, 2023, 11:25am UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494/2 "2023-12-11T11:25:37Z")

</div>

Hi,

Apology for the trivial first answer: yes, if a different file name is chosen. Do I understand correctly the question?

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![amishgog](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amishgog/32/34940_2.png) [@amishgog](https://root-forum.cern.ch/u/amishgog)\
**Post date:** [December 11, 2023, 11:42am UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494/3 "2023-12-11T11:42:43Z")

</div>

Hi Danilo,

Thanks for the reply. Yeah that’s what I thought about first, having a different file name. But I wanted to look for a way to keep my original file and make changes to that.

---

<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:** [December 11, 2023, 12:14pm UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494/4 "2023-12-11T12:14:06Z")

</div>

I see. Then a good start is to use a [RSnapshotOptions](https://root.cern/doc/master/structROOT_1_1RDF_1_1RSnapshotOptions.html) instance passing it to the [Snapshot](https://root.cern/doc/master/classROOT_1_1RDF_1_1RInterface.html#ac5903d3acec8c52f13cbd405371f7fb7) method of RDataFrame (in particular have a look to `RSnapshotOptions::fMode`).

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![amishgog](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amishgog/32/34940_2.png) [@amishgog](https://root-forum.cern.ch/u/amishgog)\
**Post date:** [December 11, 2023, 1:04pm UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494/5 "2023-12-11T13:04:41Z")

</div>

Ok this worked I created a RSnapshotOptions instance, then did options.fMode = “UPDATE”

Thanks for the help Danilo

---

<div class="post-metadata">

**Author:** ![amishgog](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/amishgog/32/34940_2.png) [@amishgog](https://root-forum.cern.ch/u/amishgog)\
**Post date:** [December 11, 2023, 1:24pm UTC](https://root-forum.cern.ch/t/snapshot-method-overriding-specified-root-file/57494/6 "2023-12-11T13:24:43Z")

</div>

So something weird happened. The update method ran fine but when I ran my code a second time after some modifications all the data was gone. I think between the Define method and the Snapshot method I am doing something wrong. I have attached my code below

 ![Screenshot 2023-12-11 at 6.54.38 PM](https://root-forum.cern.ch/uploads/default/original/3X/e/c/ecca3686d5ac6eaee36d6b7941567aa5bcb367be.png)

So the second time I ran the code all the existing branches were gone like J\_psi\_1S and phi\_1020
