# \*\*\* Break \*\*\* segmentation violation due to a SetBranchAddress

**URL:** <https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207>\
**Category:** Newbie\
**Tags:** tree, cling, root\
**Created:** [November 3, 2022, 5:15am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207 "2022-11-03T05:15:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gale](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/a9a28c/32.png) [@gale](https://root-forum.cern.ch/u/gale)\
**Post date:** [November 3, 2022, 5:15am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207/1 "2022-11-03T05:15:07Z")

</div>

ROOT Version: root/6.26.06\_1  
Platform: Not Provided  
Compiler: cling (I think)

Hi everyone,

I have been running a macro for a few weeks with no problems, slowly adding on to it and it stopped working at some point. I made another smaller macro to test (code at the bottom of this post) and it is also having the same issue. I will attach the error below the code. I have been able to pinpoint the line that is causing it to have the segmentation violation, that being the line:

‘’’  
decay\_tree-\>SetBranchAddress(“decayHashExtended”, &decayHashExtended);  
‘’’

If I comment it out, it runs fine. I know the script can read both files, and it will print everything out, then have the segmentation violation. Because I am a new user, it will not let me post links to the files, what is the best way for me to post them? If anyone knows what is wrong and how to fix it, thank you in advance!

Alex

‘’’  
using namespace std;  
#include \<TFile.h\>  
#include \<TTree.h\>

bool print\_neutral\_events = true;

void eventPrinter() {

```
TFile* neutral_file (TFile::Open("B_neutral_hadronic.root"));
neutral_file->ls();
TTree* neutral_tree (neutral_file->Get<TTree>("variables"));
neutral_tree->Print();
Double_t Mbc, deltaE, SigProb, FEIProbRank0, isSignal, mcErrors, decayModeID, extraInfo __boDecayHash__ bc, extraInfo __boDecayHashExtended__ bc;
Float_t decayHash, decayHashExtended;
Int_t __event__ , __candidate__ , __ncandidates__ ;
string* decayString;
neutral_tree->SetBranchAddress("Mbc", &Mbc);
neutral_tree->SetBranchAddress("deltaE", &deltaE);
neutral_tree->SetBranchAddress("SigProb", &SigProb);
neutral_tree->SetBranchAddress("FEIProbRank0", &FEIProbRank0);
neutral_tree->SetBranchAddress("isSignal", &isSignal);
neutral_tree->SetBranchAddress("mcErrors", &mcErrors);
neutral_tree->SetBranchAddress("decayModeID", &decayModeID);
neutral_tree->SetBranchAddress(" __event__", & __event__ );
neutral_tree->SetBranchAddress(" __candidate__", & __candidate__ ); 
neutral_tree->SetBranchAddress(" __ncandidates__", & __ncandidates__ );
neutral_tree->SetBranchAddress("extraInfo __boDecayHash__ bc", &extraInfo __boDecayHash__ bc);
neutral_tree->SetBranchAddress("extraInfo __boDecayHashExtended__ bc", &extraInfo __boDecayHashExtended__ bc);

TFile* decay_file (TFile::Open("B0_generic_hashmap.root"));
decay_file->ls();
TTree* decay_tree (decay_file->Get<TTree>("hashtable"));
decay_tree->Print(); cout<<endl;
decay_tree->SetBranchAddress("decayHash", &decayHash);
decay_tree->SetBranchAddress("decayHashExtended", &decayHashExtended);
decay_tree->SetBranchAddress("decayString", &decayString);

```

//Print event info  
if (print\_neutral\_events == true){  
cout\<\<“NEUTRAL TREE EVENTS”\<\<endl;  
int a = 55; //for quick testing  
for(int i = a; i \< a + 2; i++) { //Max is i \< 44963  
neutral\_tree-\>Show(i);  
cout\<\<endl;  
decay\_tree-\>Show(i);  
cout\<\<endl;  
}  
cout\<\<endl;  
}

}  
‘’’  
The error printed in the terminal:  
\*\*\* Break \*\*\* segmentation violation  
[/usr/lib/system/libsystem\_platform.dylib] \_sigtramp (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value\*) const (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const\*, cling::Value\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::\_\_1::basic\_string\<char, std::\_\_1::char\_traits, std::\_\_1::allocator \> const&, cling::CompilationOptions, cling::Value\*, cling::Transaction\*\*, unsigned long) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value\*, bool) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor\*, char const\*, cling::Interpreter::CompilationResult&, cling::Value\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] TCling::ProcessLine(char const\*, TInterpreter::EErrorCode\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCling.so] TCling::ProcessLineSynch(char const\*, TInterpreter::EErrorCode\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libCore.so] TApplication::ExecuteFile(char const\*, int\*, bool) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libRint.so] TRint::ProcessLineNr(char const\*, char const\*, int\*) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/lib/root/libRint.so] TRint::Run(bool) (no debug info)  
[/opt/homebrew/Cellar/root/6.26.06\_1/bin/root.exe] main (no debug info)  
[/usr/lib/dyld] start (no debug info)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 3, 2022, 7:36am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207/2 "2022-11-03T07:36:34Z")

</div>

At least: `std::string *decayString = 0;`

---

<div class="post-metadata">

**Author:** ![gale](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/a9a28c/32.png) [@gale](https://root-forum.cern.ch/u/gale)\
**Post date:** [November 3, 2022, 7:50am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207/3 "2022-11-03T07:50:30Z")

</div>

Thank you, that seems to have fixed it! Though, I do not understand why that fixes it, could you explain why this fixed it?

Alex

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 3, 2022, 8:17am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207/4 "2022-11-03T08:17:00Z")

</div>

A similar issue (with explanations):

> [@Making shared library for IO](https://root-forum.cern.ch/t/making-shared-library-for-io/52148):
>
> Hi experts and ROOT friends, ROOT asked me to provide a dictionary for the vector of vector when I tried to compile the following file util.cc which is used in the main function. I followed the instructions on the official tutorial, generated the LinkDef.h, and compiled it using rootcling shown in the Makefile below, and it seems to link successfully to the executable. However, it failed at run time and I have no idea how to debug from here. The error message is attached in the log.txt file.…

---

<div class="post-metadata">

**Author:** ![gale](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/g/a9a28c/32.png) [@gale](https://root-forum.cern.ch/u/gale)\
**Post date:** [November 4, 2022, 1:35am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-due-to-a-setbranchaddress/52207/5 "2022-11-04T01:35:37Z")

</div>

I see, thank you very much!

Alex
