The problem occurs in the getEntry function of the Tbranch class

When I tried to implement a feature, the code I wrote is:

//marco1.cpp
{
	Long64_t target= 100;
	//...

	TChain *tr = new TChain("tree");
	tr->Add("../resources/02-root/*.root");
	
	double trig;
	int nhit;
	vector<double> *ch;
	vector<double> *x;
	vector<double> *y;
	vector<double> *t;

	tr->SetBranchAddress("trig",&trig);
	tr->SetBranchAddress("nhit",&nhit);
	tr->SetBranchAddress("ch",&ch);
	tr->SetBranchAddress("x",&x);
	tr->SetBranchAddress("y",&y);
	tr->SetBranchAddress("t",&t);
	
	//...
	
	tr->GetEntry(target); 

}

When I run root marco1.cpp, the program can run normally. But with the same content in the form of a function (see the code below).

//marco1.cpp
void marco1{

	Long64_t target= 100;
	//...

	TChain *tr = new TChain("tree");
	tr->Add("../resources/02-root/*.root");
	
	double trig;
	int nhit;
	vector<double> *ch;
	vector<double> *x;
	vector<double> *y;
	vector<double> *t;


	tr->SetBranchAddress("trig",&trig);
	tr->SetBranchAddress("nhit",&nhit);
	tr->SetBranchAddress("ch",&ch);
	tr->SetBranchAddress("x",&x);
	tr->SetBranchAddress("y",&y);
	tr->SetBranchAddress("t",&t);
	
	//...
	
	tr->GetEntry(target); 
}

When I ran root marco1.cpp again, I got the following error.

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f373cb80c3a in __GI___wait4 (pid=9109, stat_loc=stat_loc
entry=0x7ffcbe2d4de8, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1  0x00007f373cb80bfb in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffcbe2d4de8, options=options
entry=0) at waitpid.c:38
#2  0x00007f373caeff67 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3  0x00007f373d24200e in TUnixSystem::StackTrace() () from /home/pl/root/lib/libCore.so
#4  0x00007f373d23eeb5 in TUnixSystem::DispatchSignals(ESignals) () from /home/pl/root/lib/libCore.so
#5  <signal handler called>
#6  0x00007f37225d2e5f in TPad::ResizePad(char const*) () from /home/pl/root/lib/libGpad.so
#7  0x00007f37225aab2d in TCanvas::Resize(char const*) () from /home/pl/root/lib/libGpad.so
#8  0x00007f372182a94c in TRootCanvas::HandleContainerConfigure(Event_t*) () from /home/pl/root/lib/libGui.so
#9  0x00007f372174f370 in TGFrame::HandleEvent(Event_t*) () from /home/pl/root/lib/libGui.so
#10 0x00007f37216f8e9e in TGClient::HandleEvent(Event_t*) () from /home/pl/root/lib/libGui.so
#11 0x00007f37216f94d5 in TGClient::ProcessOneEvent() () from /home/pl/root/lib/libGui.so
#12 0x00007f37216f953b in TGClient::HandleInput() () from /home/pl/root/lib/libGui.so
#13 0x00007f373d23f6d0 in TUnixSystem::DispatchOneEvent(bool) () from /home/pl/root/lib/libCore.so
#14 0x00007f373d150059 in TSystem::Run() () from /home/pl/root/lib/libCore.so
#15 0x00007f373d0da9f6 in TApplication::Run(bool) () from /home/pl/root/lib/libCore.so
#16 0x00007f373d3ff32e in TRint::Run(bool) () from /home/pl/root/lib/libRint.so
#17 0x00005592d2d752d3 in main ()
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f37225d2e5f in TPad::ResizePad(char const*) () from /home/pl/root/lib/libGpad.so
#7  0x00007f37225aab2d in TCanvas::Resize(char const*) () from /home/pl/root/lib/libGpad.so
#8  0x00007f372182a94c in TRootCanvas::HandleContainerConfigure(Event_t*) () from /home/pl/root/lib/libGui.so
#9  0x00007f372174f370 in TGFrame::HandleEvent(Event_t*) () from /home/pl/root/lib/libGui.so
#10 0x00007f37216f8e9e in TGClient::HandleEvent(Event_t*) () from /home/pl/root/lib/libGui.so
#11 0x00007f37216f94d5 in TGClient::ProcessOneEvent() () from /home/pl/root/lib/libGui.so
#12 0x00007f37216f953b in TGClient::HandleInput() () from /home/pl/root/lib/libGui.so
#13 0x00007f373d23f6d0 in TUnixSystem::DispatchOneEvent(bool) () from /home/pl/root/lib/libCore.so
#14 0x00007f373d150059 in TSystem::Run() () from /home/pl/root/lib/libCore.so
#15 0x00007f373d0da9f6 in TApplication::Run(bool) () from /home/pl/root/lib/libCore.so
#16 0x00007f373d3ff32e in TRint::Run(bool) () from /home/pl/root/lib/libRint.so
#17 0x00005592d2d752d3 in main ()
===========================================================

But when I comment out this line of code //tr->GetEntry(value);, the code is able to continue running.

Attach Environment Information
root version
image

gcc version

Can anyone help me understand what the problem is? Please help me, thank you very much. :smiley: :smiley:

I cannot reproduce this error. Do you have a simple reproducer ?

Sorry, I cannot provide the root file to you, but I can provide more error information.

 ------------------------------------------------------------------
  | Welcome to ROOT 6.30/06                        https://root.cern |
  | (c) 1995-2024, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for linuxx8664gcc on Apr 03 2024, 10:34:21                 |
  | From tags/v6.30.06@v6.30.06                                      |
  | With c++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0                   |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q'  |
   ------------------------------------------------------------------

root [0] 
Processing marco2.cpp...

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007ff8a194dc3a in __GI___wait4 (pid=13453, stat_loc=stat_loc
entry=0x7fff481137e8, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:27
#1  0x00007ff8a194dbfb in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7fff481137e8, options=options
entry=0) at waitpid.c:38
#2  0x00007ff8a18bcf67 in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:172
#3  0x00007ff8a200f00e in TUnixSystem::StackTrace() () from /home/pl/root/lib/libCore.so
#4  0x00007ff8a200beb5 in TUnixSystem::DispatchSignals(ESignals) () from /home/pl/root/lib/libCore.so
#5  <signal handler called>
#6  0x00007ff8a1388b19 in int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType<double>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /home/pl/root/lib/libRIO.so
#7  0x00007ff8a121ebe5 in TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) () from /home/pl/root/lib/libRIO.so
#8  0x00007ff8873cacdb in TBranchElement::ReadLeavesMember(TBuffer&) () from /home/pl/root/lib/libTree.so
#9  0x00007ff8873c3690 in TBranch::GetEntry(long long, int) () from /home/pl/root/lib/libTree.so
#10 0x00007ff8873d6420 in TBranchElement::GetEntry(long long, int) () from /home/pl/root/lib/libTree.so
#11 0x00007ff88743c887 in TTree::GetEntry(long long, int) () from /home/pl/root/lib/libTree.so
#12 0x00007ff89b35c1f6 in ?? ()
#13 0x00007fff481166a0 in ?? ()
#14 0x4059000000000000 in ?? ()
#15 0x000055987d5bcbe0 in ?? ()
#16 0x00007ff89c087232 in cling::runtime::internal::setValueNoAlloc(void*, void*, void*, char) () from /home/pl/root/lib/libCling.so
#17 0x00007ff89b35f03f in ?? ()
#18 0x00007fff48116d70 in ?? ()
#19 0x00007ff89c04bf21 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const () from /home/pl/root/lib/libCling.so
#20 0x00007ff89bfc86df in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/pl/root/lib/libCling.so
#21 0x00007ff89bfcb531 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/pl/root/lib/libCling.so
#22 0x00007ff89c0cddd1 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) () from /home/pl/root/lib/libCling.so
#23 0x00007ff89c0dda34 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) () from /home/pl/root/lib/libCling.so
#24 0x00007ff89c0df2e2 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) () from /home/pl/root/lib/libCling.so
#25 0x00007ff89c0c6a18 in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /home/pl/root/lib/libCling.so
#26 0x00007ff89bea30ec in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/pl/root/lib/libCling.so
#27 0x00007ff89beb5aee in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /home/pl/root/lib/libCling.so
#28 0x00007ff89beb5f1a in TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /home/pl/root/lib/libCling.so
#29 0x00007ff8a1eaa15a in TApplication::ExecuteFile(char const*, int*, bool) () from /home/pl/root/lib/libCore.so
#30 0x00007ff8a1eabadd in TApplication::ProcessLine(char const*, bool, int*) () from /home/pl/root/lib/libCore.so
#31 0x00007ff8a21ca2d6 in TRint::ProcessLineNr(char const*, char const*, int*) () from /home/pl/root/lib/libRint.so
#32 0x00007ff8a21cc186 in TRint::Run(bool) () from /home/pl/root/lib/libRint.so
#33 0x000055987a9dc2d3 in main ()
===========================================================


The lines below might hint at the cause of the crash. If you see question
marks as part of the stack trace, try to recompile with debugging information
enabled and export CLING_DEBUG=1 environment variable before running.
You may get help by asking at the ROOT forum https://root.cern/forum
preferably using the command (.forum bug) in the ROOT prompt.
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs or (preferably) using the command (.gh bug) in
the ROOT prompt. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007ff8a1388b19 in int TStreamerInfoActions::VectorLooper::ReadCollectionBasicType<double>(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /home/pl/root/lib/libRIO.so
#7  0x00007ff8a121ebe5 in TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) () from /home/pl/root/lib/libRIO.so
#8  0x00007ff8873cacdb in TBranchElement::ReadLeavesMember(TBuffer&) () from /home/pl/root/lib/libTree.so
#9  0x00007ff8873c3690 in TBranch::GetEntry(long long, int) () from /home/pl/root/lib/libTree.so
#10 0x00007ff8873d6420 in TBranchElement::GetEntry(long long, int) () from /home/pl/root/lib/libTree.so
#11 0x00007ff88743c887 in TTree::GetEntry(long long, int) () from /home/pl/root/lib/libTree.so
#12 0x00007ff89b35c1f6 in ?? ()
#13 0x00007fff481166a0 in ?? ()
#14 0x4059000000000000 in ?? ()
#15 0x000055987d5bcbe0 in ?? ()
#16 0x00007ff89c087232 in cling::runtime::internal::setValueNoAlloc(void*, void*, void*, char) () from /home/pl/root/lib/libCling.so
#17 0x00007ff89b35f03f in ?? ()
#18 0x00007fff48116d70 in ?? ()
#19 0x00007ff89c04bf21 in cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const () from /home/pl/root/lib/libCling.so
#20 0x00007ff89bfc86df in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/pl/root/lib/libCling.so
#21 0x00007ff89bfcb531 in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/pl/root/lib/libCling.so
#22 0x00007ff89c0cddd1 in cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) () from /home/pl/root/lib/libCling.so
#23 0x00007ff89c0dda34 in cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) () from /home/pl/root/lib/libCling.so
#24 0x00007ff89c0df2e2 in cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) () from /home/pl/root/lib/libCling.so
#25 0x00007ff89c0c6a18 in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) () from /home/pl/root/lib/libCling.so
#26 0x00007ff89bea30ec in HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/pl/root/lib/libCling.so
===========================================================

ok, whats is marco2.cpp ?

marco2.cpp and the marco1.cpp I provided have the same content. Sorry for the confusion.

Well , it is hard to help you further if do not provide some code reproducing the problem.

Nice, I found the reason. I need to initialize the pointer object.


	vector<double> *ch = new std::vector<double>;
	vector<double> *x = new std::vector<double>;
	vector<double> *y = new std::vector<double>;
	vector<double> *t = new std::vector<double>;

	tr->SetBranchAddress("trig",&trig);
	tr->SetBranchAddress("nhit",&nhit);
	tr->SetBranchAddress("ch",&ch);
	tr->SetBranchAddress("x",&x);
	tr->SetBranchAddress("y",&y);
	tr->SetBranchAddress("t",&t);
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.