# Segmentation violation when using snapshot to save tree

**URL:** <https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593>\
**Category:** Newbie\
**Tags:** rdataframe\
**Created:** [October 4, 2023, 3:34am UTC](https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593 "2023-10-04T03:34:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmaneyro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mmaneyro/32/34214_2.png) [@mmaneyro](https://root-forum.cern.ch/u/mmaneyro)\
**Post date:** [October 4, 2023, 3:34am UTC](https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593/1 "2023-10-04T03:34:30Z")

</div>

Hi,  
I am trying to use RDataFrame to manipulate TTrees opened from file, and save the result to file using snapshot. My attempts lead to segmentation violation crashes. I tried a simplified code where the tree is simply opened and saved again, and that is still the result. What’s going wrong?  
Thanks

\_ROOT Version: 6.28/00  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

[snapshot\_test.C](https://root-forum.cern.ch/uploads/short-url/p41Et5uUiLH75dqeBfaCcnm7SuE.C) (7.4 KB)

---

<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:** [October 4, 2023, 4:36am UTC](https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593/2 "2023-10-04T04:36:34Z")

</div>

Hi,

Thanks for posting. To reproduce the crash and help further, we would need the input file.  
Nevertheless, I had a look to your macro. It’s nice code, however I think it could be greatly slimmed down: with RDataFrame there is no need to explicitly manipulate branches, leafs and column types 🙂  
For example, if it is not possible for you to post somehow the input file, could you try if this minimal macro works for you?

```cpp
auto df = ROOT::RDataFrame("LHEF", "pp_2j_LO_H_T_35GeV.root");
df.Snapshot("myTree", "myFile.root");

```

If that works, it means in between those two lines, you can add _all_ the manipulations you need for carrying out the task you are up to - no need for other code, RDataFrame removes all the boilerplate.

I hope this helps.  
Cheers,

D

---

<div class="post-metadata">

**Author:** ![mmaneyro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mmaneyro/32/34214_2.png) [@mmaneyro](https://root-forum.cern.ch/u/mmaneyro)\
**Post date:** [October 4, 2023, 1:46pm UTC](https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593/3 "2023-10-04T13:46:06Z")

</div>

Thanks for the reply.  
The minimal macro does not work for me.  
This is the error message:

```auto
Error in <TTree::Bronch>: TClonesArray with no dictionary defined in branch: Event
RDataFrame::Run: event loop was interrupted
Error in <TRint::HandleTermInput()>: std::logic_error caught: Trying to insert a null branch address.

```

The input file is too large to upload. It was generated from an .lhe file using the ExRootAnalysis tool available for this purpose.

---

<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:** [October 4, 2023, 2:31pm UTC](https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593/4 "2023-10-04T14:31:39Z")

</div>

Hi,

You should make sure to load the library which contains the dictionaries which allow you to read the “Event” objects in the file. Incidentally, without dictionaries, it is not possible even to write to disk a specific C++ structure.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![mmaneyro](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mmaneyro/32/34214_2.png) [@mmaneyro](https://root-forum.cern.ch/u/mmaneyro)\
**Post date:** [October 4, 2023, 2:47pm UTC](https://root-forum.cern.ch/t/segmentation-violation-when-using-snapshot-to-save-tree/56593/5 "2023-10-04T14:47:20Z")

</div>

That solves the problem for the minimal macro. I’d already tried it before for the macro I posted and somehow it didn’t help, but I suppose I can modify my macros to be more inline with the minimal.  
Thanks
