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

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)

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

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

A similar issue (with explanations):

I see, thank you very much!

Alex