Please read tips for efficient and successful posting and posting code
ROOT Version: root-6.18.04
Platform: Not Provided
Compiler: Not Provided
I have these two TH1D objects that keep giving me a segment fault when I try to write them into a .root file. I declare them here in a my class, as private like this:
#ifndef TMAKECOINCIDENCES_HH
#define TMAKECOINCIDENCES_HH
//Include standard libraries
#include <map>
//Include ROOT headers
#include "TString.h"
#include "TGraph.h"
#include "TH1D.h"
#include "TH2D.h"
class TMakeCoincidences{
public:
TMakeCoincidences();
~TMakeCoincidences(){}
bool ExtractData();
private:
void ReadMacroInputs();
void usage()
{
printf("The file must end with .txt\n");
exit(-1);
}
void InitializeHistograms();
// void WriteHistograms();
void ColumnUsage()
{
printf("File failed to run properly, check to make sure that the number of input columns is 1");
}
void CheckCoincidences(std::vector<int> charge_lessEntries,std::vector<int> charge_moreEntries,std::vector<long long int> time_lessEntries,std::vector<long long int> time_moreEntries, int timeGap);
void WriteFile();
void GraphTimeDifference(std::vector<long long int> time_chan1, std::vector<long long int> time_chan2, long long int timeGap, TH1D* timeInterval_chan1, TH1D* timeInterval_chan2, TH1D* timeEvol_chan0, TH1D *timeEvol_chan1);
void InitializeTimeEvolution(int maxTime_chan0,int maxTime_chan1,int binning);
TString fDataFileName_channel0;
TString fDataFileName_channel1;
TString fOutputFileName;
int timeGap;
TH1D *hADCIntegral, *timeDif_chan0,*timeDif_chan1, *timeEvol_chan0,*timeEvol_chan1;
TH2D *chargeVsTime;
std::vector<long long int> timeStamps_chan0,timeStamps_chan1;
std::vector<int> Charges_chan1, Charges_chan0;
};
#endif
then I initialize them here:
void TMakeCoincidences::InitializeTimeEvolution(int maxTime_chan0,int maxTime_chan1,int binning)
{
printf("Initializing time evolution graphs \n");
timeEvol_chan0 = new TH1D("hTimeEvolution0","Rate vs Time; Time (ns); Number of Events",maxTime_chan0,0,maxTime_chan0);
printf("debug %d \n", timeEvol_chan0->GetEntries());
timeEvol_chan1 = new TH1D("hTimeEvolution1","Rate vs Time; Time (ns); Number of Events",maxTime_chan1,0,maxTime_chan1);
printf("debug %d \n", timeEvol_chan1->GetEntries());
printf("Done initializing time evolution graphs \n");
}
then I write them to the output file here:
void TMakeCoincidences::WriteFile()
{
TFile *oFile=new TFile(fOutputFileName.Data(),"RECREATE");
oFile->cd();
printf("Writing histograms to the file %s\n",fOutputFileName.Data());
// hADCIntegral->Write();
timeDif_chan0->Write();
printf("Wrote timeDif0");
delete timeDif_chan0;
timeDif_chan1->Write();
printf("Wrote timeDi1");
delete timeDif_chan1;
chargeVsTime->Write();
printf("Wrote chargevsTime");
delete chargeVsTime;
printf("About to write time_chan0 \n");
timeEvol_chan0->Write();
delete timeEvol_chan0;
printf("About to write time_chan1 \n");
timeEvol_chan1->Write();
delete timeEvol_chan1;
oFile->Write();
oFile->Close();
}
Even when I don’t fill up the histrograms they still give me a segment fault. I am not sure what’s going on.
here is the error:
*** Break *** segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00000032442ac89e in waitpid () from /lib64/libc.so.6
#1 0x000000324423e4e9 in do_system () from /lib64/libc.so.6
#2 0x00007fef607d4bfe in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x18cc7f0) at /cmn/cuore/root-6.18.04/core/unix/src/TUnixSystem.cxx:2106
#3 TUnixSystem::StackTrace (this=0x18cc7f0) at /cmn/cuore/root-6.18.04/core/unix/src/TUnixSystem.cxx:2400
#4 0x00007fef607d7183 in TUnixSystem::DispatchSignals (this=0x18cc7f0, sig=kSigSegmentationViolation) at /cmn/cuore/root-6.18.04/core/unix/src/TUnixSystem.cxx:3631
#5 <signal handler called>
#6 0x00007fef5fd728b6 in tobuf (x=0, buf=
0x195f6b8: 0x7fef5c4d7ffe "") at /cmn/cuore/root-6.18.04_build/include/Bytes.h:258
#7 TBufferFile::WriteFastArray (this=0x195f690, d=0x7fedaee9b010, n=863684050) at /cmn/cuore/root-6.18.04/io/io/src/TBufferFile.cxx:2123
#8 0x00007fef60720b6c in TArrayD::Streamer (this=0x1da74d0, b=...) at /cmn/cuore/root-6.18.04/core/cont/src/TArrayD.cxx:155
#9 0x00007fef607b7d9b in TStreamerBase::WriteBuffer (this=this
entry=0x2a1f940, b=..., pointer=0x1da7100 "\240k\232_\357\177") at /cmn/cuore/root-6.18.04/core/meta/src/TStreamerElement.cxx:846
#10 0x00007fef5ffefdcc in TStreamerInfo::WriteBufferAux<char**> (this=0x2a0c7f0, b=..., arr=
0x7ffdb1c57898: 0x7ffdb1c57890, compinfo=0x2a21c18, first=first
entry=0, last=last
entry=1, narr=1, eoffset=0, arrayMode=0) at /cmn/cuore/root-6.18.04/io/io/src/TStreamerInfoWriteBuffer.cxx:626
#11 0x00007fef5fe39ffd in TStreamerInfoActions::GenericWriteAction (buf=..., addr=<optimized out>, config=<optimized out>) at /cmn/cuore/root-6.18.04/io/io/src/TStreamerInfoActions.cxx:192
#12 0x00007fef5fd792ee in TStreamerInfoActions::TConfiguredAction::operator() (this=<optimized out>, this=<optimized out>, object=0x1da7100, buffer=...) at /cmn/cuore/root-6.18.04_build/include/TStreamerInfoActions.h:124
#13 TBufferFile::ApplySequence (obj=0x1da7100, sequence=..., this=0x195f690) at /cmn/cuore/root-6.18.04/io/io/src/TBufferFile.cxx:3564
#14 TBufferFile::WriteClassBuffer (this=0x195f690, cl=0x26cd710, pointer=0x1da7100) at /cmn/cuore/root-6.18.04/io/io/src/TBufferFile.cxx:3533
#15 0x00007fef5fe14397 in TKey::TKey (this=0x195ff70, obj=0x1da7100, name=0x1960a00 "hTimeEvolution0", bufsize=285799683, motherDir=<optimized out>) at /cmn/cuore/root-6.18.04/io/io/src/TKey.cxx:251
#16 0x00007fef5fdc7845 in TFile::CreateKey (this=<optimized out>, mother=0x1da7cd0, obj=0x1da7100, name=0x1960a00 "hTimeEvolution0", bufsize=285799683) at /cmn/cuore/root-6.18.04/io/io/src/TFile.cxx:1014
#17 0x00007fef5fdb9c84 in TDirectoryFile::WriteTObject (this=0x1da7cd0, obj=0x1da7100, name=<optimized out>, option=<optimized out>, bufsize=0) at /cmn/cuore/root-6.18.04/io/io/src/TDirectoryFile.cxx:1908
#18 0x00007fef606c7add in TObject::Write (this=0x1da7100, name=0x0, option=<optimized out>, bufsize=0) at /cmn/cuore/root-6.18.04/core/base/src/TObject.cxx:771
#19 0x00000000004065d6 in TMakeCoincidences::WriteFile() ()
#20 0x0000000000407812 in TMakeCoincidences::ExtractData() ()
#21 0x0000000000403263 in main ()
===========================================================
The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum
Only if you are really convinced it is a bug in ROOT then please submit a
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.
===========================================================
#6 0x00007fef5fd728b6 in tobuf (x=0, buf=
0x195f6b8: 0x7fef5c4d7ffe "") at /cmn/cuore/root-6.18.04_build/include/Bytes.h:258
#7 TBufferFile::WriteFastArray (this=0x195f690, d=0x7fedaee9b010, n=863684050) at /cmn/cuore/root-6.18.04/io/io/src/TBufferFile.cxx:2123
#8 0x00007fef60720b6c in TArrayD::Streamer (this=0x1da74d0, b=...) at /cmn/cuore/root-6.18.04/core/cont/src/TArrayD.cxx:155
#9 0x00007fef607b7d9b in TStreamerBase::WriteBuffer (this=this
entry=0x2a1f940, b=..., pointer=0x1da7100 "240k232_357177") at /cmn/cuore/root-6.18.04/core/meta/src/TStreamerElement.cxx:846
#10 0x00007fef5ffefdcc in TStreamerInfo::WriteBufferAux<char**> (this=0x2a0c7f0, b=..., arr=
0x7ffdb1c57898: 0x7ffdb1c57890, compinfo=0x2a21c18, first=first
entry=0, last=last
entry=1, narr=1, eoffset=0, arrayMode=0) at /cmn/cuore/root-6.18.04/io/io/src/TStreamerInfoWriteBuffer.cxx:626
#11 0x00007fef5fe39ffd in TStreamerInfoActions::GenericWriteAction (buf=..., addr=<optimized out>, config=<optimized out>) at /cmn/cuore/root-6.18.04/io/io/src/TStreamerInfoActions.cxx:192
#12 0x00007fef5fd792ee in TStreamerInfoActions::TConfiguredAction::operator() (this=<optimized out>, this=<optimized out>, object=0x1da7100, buffer=...) at /cmn/cuore/root-6.18.04_build/include/TStreamerInfoActions.h:124
#13 TBufferFile::ApplySequence (obj=0x1da7100, sequence=..., this=0x195f690) at /cmn/cuore/root-6.18.04/io/io/src/TBufferFile.cxx:3564
#14 TBufferFile::WriteClassBuffer (this=0x195f690, cl=0x26cd710, pointer=0x1da7100) at /cmn/cuore/root-6.18.04/io/io/src/TBufferFile.cxx:3533
#15 0x00007fef5fe14397 in TKey::TKey (this=0x195ff70, obj=0x1da7100, name=0x1960a00 "hTimeEvolution0", bufsize=285799683, motherDir=<optimized out>) at /cmn/cuore/root-6.18.04/io/io/src/TKey.cxx:251
#16 0x00007fef5fdc7845 in TFile::CreateKey (this=<optimized out>, mother=0x1da7cd0, obj=0x1da7100, name=0x1960a00 "hTimeEvolution0", bufsize=285799683) at /cmn/cuore/root-6.18.04/io/io/src/TFile.cxx:1014
#17 0x00007fef5fdb9c84 in TDirectoryFile::WriteTObject (this=0x1da7cd0, obj=0x1da7100, name=<optimized out>, option=<optimized out>, bufsize=0) at /cmn/cuore/root-6.18.04/io/io/src/TDirectoryFile.cxx:1908
#18 0x00007fef606c7add in TObject::Write (this=0x1da7100, name=0x0, option=<optimized out>, bufsize=0) at /cmn/cuore/root-6.18.04/core/base/src/TObject.cxx:771
#19 0x00000000004065d6 in TMakeCoincidences::WriteFile() ()
#20 0x0000000000407812 in TMakeCoincidences::ExtractData() ()
#21 0x0000000000403263 in main ()
===========================================================