Hello,
I can’t execute this macro.
int binchangeinrun(int runnum){
char *calibpath;
sprintf(calibpath, "./%04d/calib.txt",runnum);
ifstream ifs(calibpath);
cout<<calibpath << " is read."<<endl;
double a[22];
double channum[22];
float A[22][3] = {};
string str;
int ii = 0;
int jj = 0;
int kk = 0;
float temp = 0;
if(!ifs){
std::cout<<"Error!";
return 1;
}
while(getline(ifs,str)){
string token;
istringstream stream(str);
while(getline(stream,token,'\t')){
ii = kk/3;
jj = kk%3;
temp = stod(token);
A[ii][jj] = temp;
kk++;
}
}
for (size_t hh = 0; hh < 22; hh++) {
channum[hh]=A[hh][0];
a[hh]=A[hh][2];
}
TFile *specout = new TFile("./outroot/Spectrumbintest.root","recreate");
TH1D *newhist;
TH1D *hist[22];
newhist = new TH1D(Form("GammaEnergy_Run%d",runnum),Form("Run %d,GammaEnergy",runnum),10000,0,10000);
char *histname;
TFile *file = TFile::Open(Form("./outroot/Spectrum_run%04d.root",runnum));
cout<<"run"<< runnum << " is loaded."<<endl;
int chnum[22]={1,2,3,4,5,6,7,8, 17,18,19,20,21,22,23, 29,30,31,32,33,34,35};
for (size_t i = 0; i < 22; i++) {
sprintf(histname,"GammaEnergy_s%d_Run%d",chnum[i],runnum);
hist[i] = (TH1D*)file->Get(histname);
}
///////////////////////////////////////////////////////////////
int binnum = 10000;
int n;
double xx;
int x;
double yy;
int y;
int event_x;
int event_y;
int event_z;
int c_event;
for(int d = 0; d < binnum; d ++){
for (size_t i = 0; i < 22; i++) {
}
}
return 0;
}
It is compiled with no error.
But when I execute the macro, root called
*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/usr/lib/system/libsystem_c.dylib] __sfvwrite (no debug info)
[/usr/lib/system/libsystem_c.dylib] __vfprintf (no debug info)
[/usr/lib/system/libsystem_c.dylib] __v2printf (no debug info)
[/usr/lib/system/libsystem_c.dylib] vsprintf_l (no debug info)
[/usr/lib/system/libsystem_c.dylib] sprintf (no debug info)
[/Volumes/BUFFALO/binchange_cpp.so] binchangeinrun(int) (no debug info)
[<unknown binary>] (no debug info)
[/usr/local/root-6.14.04/cmake_build/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/usr/local/root-6.14.04/cmake_build/lib/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/usr/local/root-6.14.04/cmake_build/lib/libCling.so] cling::Interpreter::process(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) (no debug info)
[/usr/local/root-6.14.04/cmake_build/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/usr/local/root-6.14.04/cmake_build/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) /usr/local/root-6.14.04/core/metacling/src/TCling.cxx:2069
[/usr/local/root-6.14.04/cmake_build/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) /usr/local/root-6.14.04/core/metacling/src/TCling.cxx:2218
[/usr/local/root-6.14.04/cmake_build/lib/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) /usr/local/root-6.14.04/core/rint/src/TRint.cxx:741
[/usr/local/root-6.14.04/cmake_build/lib/libRint.so] TRint::HandleTermInput() /usr/local/root-6.14.04/core/rint/src/TRint.cxx:603
[/usr/local/root-6.14.04/cmake_build/lib/libCore.so] TUnixSystem::CheckDescriptors() /usr/local/root-6.14.04/core/unix/src/TUnixSystem.cxx:1324
[/usr/local/root-6.14.04/cmake_build/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) /usr/local/root-6.14.04/core/macosx/src/TMacOSXSystem.mm:378
[/usr/local/root-6.14.04/cmake_build/lib/libCore.so] TSystem::InnerLoop() /usr/local/root-6.14.04/core/base/src/TSystem.cxx:412
[/usr/local/root-6.14.04/cmake_build/lib/libCore.so] TSystem::Run() /usr/local/root-6.14.04/core/base/src/TSystem.cxx:362
[/usr/local/root-6.14.04/cmake_build/lib/libCore.so] TApplication::Run(bool) /usr/local/root-6.14.04/core/base/src/TApplication.cxx:1174
[/usr/local/root-6.14.04/cmake_build/lib/libRint.so] TRint::Run(bool) /usr/local/root-6.14.04/core/rint/src/TRint.cxx:458
[/usr/local/root-6.14.04/cmake_build/bin/root.exe] main /usr/local/root-6.14.04/main/src/rmain.cxx:32
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
What is the problem…?
What is debug info?
Simple macro (it is only cout<<OK<<endl) can excecute.
_ROOT Version:6.14.04(cmake)
_Platform:macOS High Sierra 10.13.6
_Compiler:Xcode Version 10.0 (10A255)