Hello,
I need help with understanding why my program is failing with message Error in <TBufferFile::WriteByteCount>: bytecount too large (more than 1073741822) and terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted (core dumped)
.
In brief, std::vector<TH2F*>
contains 12 histograms, where every histogram is created by adding 20 histograms (h1->Add(h2)
). Now when I am trying to write histogram (through loop over vector elements) to file, my program fails with:
Error in <TBufferFile::WriteByteCount>: bytecount too large (more than 1073741822)
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Aborted (core dumped).
Here is my code:
void TWCA(LEDplsSepByIntensity* selected_pulsesTWC){
fOutTWC->cd();
fOutTWC->mkdir(Form("%d",fSDC));
fOutTWC->cd(Form("%d",fSDC));
int Nch, IntensityID;
float Charge, Time;
TTree *tree = new TTree("T","Nch, time and charge of LED pulses");
tree->Branch("IntensityID", &IntensityID, "IntensityID/I");
tree->Branch("Nch", &Nch, "Nch/I");
tree->Branch("Charge", &Charge, "Charge/F");
tree->Branch("Time", &Time, "Time/F");
for (UInt_t i=0; i < selected_pulsesTWC->size(); i++){
for (UInt_t j=0; j < selected_pulsesTWC->at(i).size(); j++){
TH2F* hist = new TH2F (Form("TvsChargeHistAtOM%d", j), Form("TvsChargeHistAtOM%d", j), 50000, 0.0, 1700.0, 8000, 0.0, 8000.0);
if (selected_pulsesTWC->at(i).at(j).size() == 0) continue;
for (UInt_t k = 0; k < selected_pulsesTWC->at(i).at(j).size(); k++ ){
if (selected_pulsesTWC->at(i).at(j).at(k).Q != 0) {
IntensityID = i;
Nch = j;
Charge = selected_pulsesTWC->at(i).at(j).at(k).Q;
Time = selected_pulsesTWC->at(i).at(j).at(k).T;
hist->Fill(Charge, Time);
tree->Fill();
}
}
if (i==0) {
TvsChargeHist.push_back(hist);
}
if (i>0) {
TvsChargeHist[j]->Add(hist);
delete hist; hist = nullptr;
}
}
}
tree->Write();
for (UInt_t i = 0; i < TvsChargeHist.size(); i++) {
TvsChargeHist.at(i)->Write(); //Program terminates here!
}
delete tree; tree = nullptr;
fOutTWC->Close();
}
Maybe, adding histograms is not the best way in my situation, but can you guys help me to understand why the program terminates and fix? Thanks a lot in advance!