Hi Rooters,
I’m new to ROOT and has a probabily stupid question.
There’re many root files and I want to export a branch data called “dth”, which is a 9X5 array(dth[9][5]).
I need the x (dth[0][0]) and chargx (dth[0][3]) data, y (dth[0][1]) and chargy (dth[0][4]) data in that array, and make a x-chargx , a y-chargy TH1D of them.
Then I have a problem. I’m not sure if I express clearly, so this is my macro:
(I am running Root 6.02/13 on Mac)
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x0000003c7d0ac7be in waitpid () from /lib64/libc.so.6
#1 0x0000003c7d03e5c9 in do_system () from /lib64/libc.so.6
#2 0x00007f94f5d8406a in TUnixSystem::StackTrace() () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCore.so
#3 0x00007f94f5d8603c in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCore.so
#4 <signal handler called>
#5 0x00007f94f309028f in ?? ()
#6 0x00007ffe5ed951c0 in ?? ()
#7 0x00007f94f4ee4903 in llvm::FoldingSetNodeID::operator==(llvm::FoldingSetNodeIDRef) const () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#8 0x00007f94f4ee492a in llvm::FoldingSetNodeID::operator==(llvm::FoldingSetNodeID const&) const () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#9 0x00007f94f4ee5054 in llvm::FoldingSetImpl::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&, void*&) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#10 0x00007f94f43e6fef in clang::NestedNameSpecifier::FindOrInsert(clang::ASTContext const&, clang::NestedNameSpecifier const&) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#11 0x0000000000000000 in ?? ()
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x00007f94f309028f in ?? ()
#6 0x00007ffe5ed951c0 in ?? ()
#7 0x00007f94f4ee4903 in llvm::FoldingSetNodeID::operator==(llvm::FoldingSetNodeIDRef) const () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#8 0x00007f94f4ee492a in llvm::FoldingSetNodeID::operator==(llvm::FoldingSetNodeID const&) const () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#9 0x00007f94f4ee5054 in llvm::FoldingSetImpl::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&, void*&) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#10 0x00007f94f43e6fef in clang::NestedNameSpecifier::FindOrInsert(clang::ASTContext const&, clang::NestedNameSpecifier const&) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCling.so
#11 0x0000000000000000 in ?? ()
===========================================================
In the code snippet show here, the input file is never open; i.e. m_f is never initialized and thus the line TTree *dst = (TTree*)m_f->Get("dst");
will crash.
Is that just a copy/paste ommision or the actual problem?
Error in <TFile::TFile>: file YiAnalytics_MC.0000000.root YiAnalytics_MC.0000017.root does not exist
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x0000003c7d0ac7be in waitpid () from /lib64/libc.so.6
#1 0x0000003c7d03e5c9 in do_system () from /lib64/libc.so.6
#2 0x00007feaabbb606a in TUnixSystem::StackTrace() () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCore.so
#3 0x00007feaabbb803c in TUnixSystem::DispatchSignals(ESignals) () from /cvmfs/cms.cern.ch/slc6_amd64_gcc493/lcg/root/6.02.12-kpegke4/lib/libCore.so
#4 <signal handler called>
#5 0x00007feaa8ec2307 in ?? ()
#6 0x0000000000000000 in ?? ()
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#5 0x00007feaa8ec2307 in ?? ()
#6 0x0000000000000000 in ?? ()
===========================================================
I have totally 33 root files and it said that two of them can not be found.
After searching on website, I still can’t find out what’s wrong with it.
for (unsigned int iFile=0; iFile<FileList.size(); ++iFile)
{
m_f = TFile::Open(FileList[iFile].c_str());
if (!m_f || m_f->IsZombie()) continue;
TTree *dst = nullptr;
m_f->GetObject("dst",dst);
if (!dst) {
std::cerr << "Can not find the tree named dst in file named: " << FileList[iFile] << '\n';
continue;
}
You need to initialize your variables properly! histx1 und histy1 are used but not initialized. → before entering the loop do: TH1* histx1 = new TH1D(…);
Also:
This is a loop that does NOT read the tree! Instead of dst->GetEntries() you need to call dst->GetEntry(i) instead.
Also, why are you storing the values in the arrays x,y,chargex,chargey? You can fill them directly into your histogram. This also avoids problems for cases with more than 1000 entries (also make i Long64_t).
One more thing: when looping over files, don’t forget to “delete m_f” at the end of the loop body.
okay, thanks to your help I find out the problem. Root files and my macro are in the different directory so none of them can’t be found.
But I don’t have permission to create a C file in where the root files are.
So should I put in the absolute path? But where should I put in? Or how can I change my macro?
SysError in <TFile::ReadBuffer>: error reading from file /data1/yuhsuan/data39/ (Is a directory)
Error in <TFile::Init>: /data1/yuhsuan/data39/ failed to read the file type data.
and I still have to interrupt program to get out.
so this is all my macro now…
std::vector<std::string> GetFileList(const char* fileName)
{
std::vector<std::string> fileList;
char infile[1000];
sprintf(infile, "%s.txt" , fileName);
std::string line;
std::ifstream ifs(infile);
while(std::getline(ifs, line))
{
fileList.push_back(line);
}
return fileList;
}
void ELECdth2(){
std::vector<std::string> FileList = GetFileList("filelist");
TFile* m_f;
Double_t x[1000],y[1000],chargx[1000],chargy[1000];
Int_t entry;
for (unsigned int iFile=0; iFile<FileList.size(); ++iFile)
{
m_f = TFile::Open(FileList[iFile].c_str());
if (!m_f || m_f->IsZombie()) continue;
TTree *dst = nullptr;
m_f->GetObject("dst",dst);
if (!dst) {
std::cerr << "Can not find the tree named dst in file named: " << FileList[iFile] << '\n';
continue;
}
}
TH1D *histx1 = new TH1D("histx1","",1000,0,1000);
TH1D *histy1 = new TH1D("histy1","",1000,0,1000);
for (unsigned int iFile=0; iFile<FileList.size(); ++iFile)
{
m_f = TFile::Open( FileList[iFile].c_str());
TTree *dst = (TTree*)m_f->Get("dst");
Double_t table[9][5];
dst->SetBranchAddress("dth",table);
entry = dst->GetEntries();
for(Int_t i=0; i<entry; i++){
dst->GetEntry(i);
histx1->Fill(table[0][0],table[0][3]);
histy1->Fill(table[0][1],table[0][4]);
}
}
TCanvas *canvas = new TCanvas("","",1000,800);
canvas->Divide(2,9,0.01,0.01,0);
canvas->cd(1);
histx1->Draw();
canvas->cd(2);
histy1->Draw();
m_f->Close();
TFile* outF = new TFile("outFile.root", "RECREATE");
canvas->Write();
canvas->Print("ELECdth.pdf");
outF->Close();
}
I think file problem is solved(every files shows YiAnalytics_MC.00000–.root
Attempting to open: ‘YiAnalytics_MC.00000–.root’), but then histo doesn’t show anything.