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
gcc version
Can anyone help me understand what the problem is? Please help me, thank you very much.