# Merging TChain object with Merge method results in "\*\*\* Break \*\*\* segmentation fault"

**URL:** <https://root-forum.cern.ch/t/merging-tchain-object-with-merge-method-results-in-break-segmentation-fault/39018>\
**Category:** Newbie\
**Tags:** tree\
**Created:** [April 21, 2020, 4:55pm UTC](https://root-forum.cern.ch/t/merging-tchain-object-with-merge-method-results-in-break-segmentation-fault/39018 "2020-04-21T16:55:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Galdiano](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/galdiano/32/19626_2.png) [@Galdiano](https://root-forum.cern.ch/u/Galdiano)\
**Post date:** [April 21, 2020, 4:55pm UTC](https://root-forum.cern.ch/t/merging-tchain-object-with-merge-method-results-in-break-segmentation-fault/39018/1 "2020-04-21T16:55:39Z")

</div>

Hello there! I’m trying to merge two TTrees located in two root files. Through some research, I figure the following should work:

```auto
  TChain chain("reco");
  chain.Add("runs/run_1520.root");
  chain.Add("runs/run_1519.root");
  chain.Merge("test.root");

```

However, when running the code I obtain the following output:

```auto
***Break*** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f0b52d42687 in __GI___ waitpid (pid=3088, stat_loc=stat_loc
entry=0x7fffdd5b68e8, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1 0x00007f0b52cad067 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:149
#2 0x00007f0b53951823 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x556c17205b80) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/core/unix/src/TUnixSystem.cxx:2106
#3 TUnixSystem::StackTrace (this=0x556c17205b80) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/core/unix/src/TUnixSystem.cxx:2400
#4 0x00007f0b53954214 in TUnixSystem::DispatchSignals (this=0x556c17205b80, sig=kSigSegmentationViolation) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/core/unix/src/TUnixSystem.cxx:3631
#5 <signal handler called>
#6 0x00007f0b538ee0aa in TClass::StreamerTObject (pThis=0x556c17b42890, object=<optimized out>, b=...) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/core/meta/src/TClass.cxx:6534
#7 0x00007f0b512ec0ac in TClass::Streamer (onfile_class=0x0, b=..., obj=0x556c189cbb41, this=0x556c17b42890) at /home/mdbg/Desktop/CERN-Root/my_build/include/TClass.h:570
#8 TBufferFile::WriteObjectClass (this=0x556c18b75e40, actualObjectStart=0x556c189cbb41, actualClass=0x556c17b42890, cacheReuse=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferFile.cxx:2552
#9 0x00007f0b512f3335 in TBufferIO::WriteObjectAny (this=0x556c18b75e40, obj=0x556c189cbb40, ptrClass=0x556c18438110, cacheReuse=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferIO.cxx:519
#10 0x00007f0b512e67b9 in TBufferFile::WriteFastArray (this=0x556c18b75e40, start=<optimized out>, cl=0x556c18438110, n=<optimized out>, isPreAlloc=<optimized out>, streamer=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferFile.cxx:2296
#11 0x00007f0b5154e61f in TStreamerInfo::WriteBufferAux<char**> (this=0x556c183e7740, b=..., arr=
0x7fffdd5b9580: 0x7fffdd5b9578, compinfo=0x556c18a06328, first=first
entry=0, last=last
entry=1, narr=1, eoffset=0, arrayMode=0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TStreamerInfoWriteBuffer.cxx:441
#12 0x00007f0b513aae30 in TStreamerInfoActions::GenericWriteAction (buf=..., addr=<optimized out>, config=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TStreamerInfoActions.cxx:192
#13 0x00007f0b512e5fa4 in TStreamerInfoActions::TConfiguredAction::operator() (this=<optimized out>, this=<optimized out>, object=0x556c18a049a0, buffer=...) at /home/mdbg/Desktop/CERN-Root/my_build/include/TStreamerInfoActions.h:124
#14 TBufferFile::ApplySequence (this=0x556c18b75e40, sequence=..., obj=0x556c18a049a0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferFile.cxx:3564
#15 0x00007f0b45ffb187 in TBranch::FillImpl (this=this
entry=0x556c18a08d90, imtHelper=imtHelper
entry=0x0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TBranch.cxx:871
#16 0x00007f0b46008c3d in TBranchElement::FillImpl (this=0x556c18a08d90, imtHelper=0x0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TBranchElement.cxx:1243
#17 0x00007f0b4600896f in TBranchElement::FillImpl (this=0x556c18a07450, imtHelper=0x0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TBranchElement.cxx:1268
#18 0x00007f0b46072c18 in TTree::Fill (this=0x556c17e676b0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TTree.cxx:4448
#19 0x00007f0b460724bd in TTree::CopyEntries (this=0x556c17e676b0, tree=0x7fffdd5b9ad8, nentries=9223372036854775807, option=0x7f0b540f94f0 "") at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TTree.cxx:3517
#20 0x00007f0b46028afa in TChain::Merge (this=0x7fffdd5b9ad8, file=<optimized out>, basketsize=0, option=0x7f0b540f94f0 "") at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TChain.cxx:2050
#21 0x00007f0b540f84b1 in ?? ()
#22 0x000000635f32535f in ?? ()
#23 0x0000000000000041 in ?? ()
#24 0x2d746f6f725f646c in ?? ()
#25 0x0000000100000001 in ?? ()
#26 0x00007fffdd5b9ad8 in ?? ()
#27 0x6975622f746f6f52 in ?? ()
#28 0x646d2f656d6f682f in ?? ()
#29 0x00007f0b462b95f8 in vtable for TChain () from /home/mdbg/Desktop/CERN-Root/build_root-6.18.04/lib/libTree.so
#30 0x0200000000000000 in ?? ()
#31 0x00007f0b53c6c518 in vtable for TString () from /home/mdbg/Desktop/CERN-Root/build_root-6.18.04/lib/libCore.so
#32 0x0000006f63657208 in ?? ()
#33 0x0000000000000000 in ?? ()
===========================================================

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 0x00007f0b538ee0aa in TClass::StreamerTObject (pThis=0x556c17b42890, object=<optimized out>, b=...) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/core/meta/src/TClass.cxx:6534
#7 0x00007f0b512ec0ac in TClass::Streamer (onfile_class=0x0, b=..., obj=0x556c189cbb41, this=0x556c17b42890) at /home/mdbg/Desktop/CERN-Root/my_build/include/TClass.h:570
#8 TBufferFile::WriteObjectClass (this=0x556c18b75e40, actualObjectStart=0x556c189cbb41, actualClass=0x556c17b42890, cacheReuse=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferFile.cxx:2552
#9 0x00007f0b512f3335 in TBufferIO::WriteObjectAny (this=0x556c18b75e40, obj=0x556c189cbb40, ptrClass=0x556c18438110, cacheReuse=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferIO.cxx:519
#10 0x00007f0b512e67b9 in TBufferFile::WriteFastArray (this=0x556c18b75e40, start=<optimized out>, cl=0x556c18438110, n=<optimized out>, isPreAlloc=<optimized out>, streamer=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferFile.cxx:2296
#11 0x00007f0b5154e61f in TStreamerInfo::WriteBufferAux<char**> (this=0x556c183e7740, b=..., arr=
0x7fffdd5b9580: 0x7fffdd5b9578, compinfo=0x556c18a06328, first=first
entry=0, last=last
entry=1, narr=1, eoffset=0, arrayMode=0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TStreamerInfoWriteBuffer.cxx:441
#12 0x00007f0b513aae30 in TStreamerInfoActions::GenericWriteAction (buf=..., addr=<optimized out>, config=<optimized out>) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TStreamerInfoActions.cxx:192
#13 0x00007f0b512e5fa4 in TStreamerInfoActions::TConfiguredAction::operator() (this=<optimized out>, this=<optimized out>, object=0x556c18a049a0, buffer=...) at /home/mdbg/Desktop/CERN-Root/my_build/include/TStreamerInfoActions.h:124
#14 TBufferFile::ApplySequence (this=0x556c18b75e40, sequence=..., obj=0x556c18a049a0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/io/io/src/TBufferFile.cxx:3564
#15 0x00007f0b45ffb187 in TBranch::FillImpl (this=this
entry=0x556c18a08d90, imtHelper=imtHelper
entry=0x0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TBranch.cxx:871
#16 0x00007f0b46008c3d in TBranchElement::FillImpl (this=0x556c18a08d90, imtHelper=0x0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TBranchElement.cxx:1243
#17 0x00007f0b4600896f in TBranchElement::FillImpl (this=0x556c18a07450, imtHelper=0x0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TBranchElement.cxx:1268
#18 0x00007f0b46072c18 in TTree::Fill (this=0x556c17e676b0) at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TTree.cxx:4448
#19 0x00007f0b460724bd in TTree::CopyEntries (this=0x556c17e676b0, tree=0x7fffdd5b9ad8, nentries=9223372036854775807, option=0x7f0b540f94f0 "") at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TTree.cxx:3517
#20 0x00007f0b46028afa in TChain::Merge (this=0x7fffdd5b9ad8, file=<optimized out>, basketsize=0, option=0x7f0b540f94f0 "") at /home/mdbg/Desktop/CERN-Root/root-6.18.04/tree/tree/src/TChain.cxx:2050
#21 0x00007f0b540f84b1 in ?? ()
#22 0x000000635f32535f in ?? ()
#23 0x0000000000000041 in ?? ()
#24 0x2d746f6f725f646c in ?? ()
#25 0x0000000100000001 in ?? ()
#26 0x00007fffdd5b9ad8 in ?? ()
#27 0x6975622f746f6f52 in ?? ()
#28 0x646d2f656d6f682f in ?? ()
#29 0x00007f0b462b95f8 in vtable for TChain () from /home/mdbg/Desktop/CERN-Root/build_root-6.18.04/lib/libTree.so
#30 0x0200000000000000 in ?? ()
#31 0x00007f0b53c6c518 in vtable for TString () from /home/mdbg/Desktop/CERN-Root/build_root-6.18.04/lib/libCore.so
#32 0x0000006f63657208 in ?? ()
#33 0x0000000000000000 in ?? ()
===========================================================

```

I really don’t know what’s going on here, as the code seems quite simple. When I commented out the `chain.Merge("test.root");` portion the code runs smoothly. Interacting with the TChain object through

```auto
chain.Draw("clusters[0].f90", "clusters[0].f90 > 0. && clusters[0].f90 < 1.");

```

returns the expected output. I’m quite lost and any help would be greatly appreciated.

Miguel.

Here’s a [link with the root files in question](https://mega.nz/folder/pxwkGAxJ#_SXm1sVGlDZMzzI-t0h6Ig), in case anyone wishes to reproduce the error:

* * *

_ROOT Version:_ 6.18/04  
_Platform:_ Ubuntu 18.04.4 LTS  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [April 21, 2020, 6:23pm UTC](https://root-forum.cern.ch/t/merging-tchain-object-with-merge-method-results-in-break-segmentation-fault/39018/2 "2020-04-21T18:23:39Z")

</div>

Because the class EvHeader inherits from TObject, a pointer to instances of that class can only be written when the its library is loaded.

So to solve the problem either load the library that implements EvHeader or **even better** use the fast mode for Merging (which copies the data without creating the object, just copying the on-disk bytes):

```auto
ch.Merge("test.root","fast");

```

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![Galdiano](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/galdiano/32/19626_2.png) [@Galdiano](https://root-forum.cern.ch/u/Galdiano)\
**Post date:** [April 21, 2020, 6:28pm UTC](https://root-forum.cern.ch/t/merging-tchain-object-with-merge-method-results-in-break-segmentation-fault/39018/3 "2020-04-21T18:28:30Z")

</div>

Wow, it was that simple huh? Thank you very much, this might have just made my day!

Cheers,  
Miguel.
