Hello, everyone. I have a strong problem while running my code, but no error while compiling.
The error is below:
Error in <TTree::Fill>: Failed filling branch:Mu_staco.muon_charge_staco, nbytes=-1, entry=7977
This error is symptomatic of a Tree created as a memory-resident Tree
Instead of doing:
TTree *T = new TTree(...)
TFile *f = new TFile(...)
you should do:
TFile *f = new TFile(...)
TTree *T = new TTree(...)
Error in <TTree::Fill>: Failed filling branch:Mu_staco.muon_pt_staco, nbytes=-1, entry=7978
This error is symptomatic of a Tree created as a memory-resident Tree
Instead of doing:
TTree *T = new TTree(...)
TFile *f = new TFile(...)
you should do:
TFile *f = new TFile(...)
TTree *T = new TTree(...)
……(other several similar errors are left out here)……
Here is the skeleton of my code:
……(definitions and inclusions are left out)……
void HZZ4lmc::Loop(){
TTree *El_event=new TTree("El_info","variables of electron events"); // Branches are left out
TTree *Mu_staco_event=new TTree("Mu_staco","variables of muon events");
……(Some other trees are left out, and then some declarations of some classes)……
if (fChain == 0) return;
Long64_t nentries = fChain->GetEntriesFast();
Long64_t nbytes = 0, nb = 0;
for (Long64_t jentry=0; jentry<nentries;jentry++) {
Long64_t ientry = LoadTree(jentry);
if (ientry < 0) break;
nb = fChain->GetEntry(jentry); nbytes += nb;
for(int im=0;im<mu_staco_n;++im){
……(some cuts of the muon events, and then fill in the muon tree)……
}
for(int ie=0;ie<el_n;++ie){
……(some cuts of the electron events, and then fill in the electron tree)……
}
}
TFile *f1=new TFile("/directory/name.root","RECREATE");
f1->cd();
El_event->Write();
Mu_staco_event->Write();
f1->Close();
}
I just don’t know how to fix this error. Do you have any idea about that ? Thanks a lot !
By the way, I’ve searched in the forum, and I found several similar topics, but, because of a lack of knowledge and experience, I’m sorry that I still don’t understand how to correct my code.
Best regards,
John
The error message tells you the fix: you should create your TFile BEFORE creating the TTrees. If the TTrees are created first, they exist in memory (hence the “memory-resident”) part, but because TTrees can get quite large, your program can essentially run out of memory.
The solution is to create the TFile to which you want to save the TTrees before creating the TTrees, then they will be automatically attached and become non-memory-resident. When the TTrees get large enough, the data will be dumped to disk rather than being held in memory.
Jean-François
[quote=“jfcaron”]The error message tells you the fix: you should create your TFile BEFORE creating the TTrees. If the TTrees are created first, they exist in memory (hence the “memory-resident”) part, but because TTrees can get quite large, your program can essentially run out of memory.
The solution is to create the TFile to which you want to save the TTrees before creating the TTrees, then they will be automatically attached and become non-memory-resident. When the TTrees get large enough, the data will be dumped to disk rather than being held in memory.
Jean-François[/quote]
Thanks a lot, I’ll try.
[quote=“jfcaron”]The error message tells you the fix: you should create your TFile BEFORE creating the TTrees. If the TTrees are created first, they exist in memory (hence the “memory-resident”) part, but because TTrees can get quite large, your program can essentially run out of memory.
The solution is to create the TFile to which you want to save the TTrees before creating the TTrees, then they will be automatically attached and become non-memory-resident. When the TTrees get large enough, the data will be dumped to disk rather than being held in memory.
Jean-François[/quote]
Thanks for your explanation. I’m sorry, I tried it, but still doesn’t work. Could there be any other reason, like the wrong usage of some class ?
cheers,
John
[quote=“jfcaron”]The error message tells you the fix: you should create your TFile BEFORE creating the TTrees. If the TTrees are created first, they exist in memory (hence the “memory-resident”) part, but because TTrees can get quite large, your program can essentially run out of memory.
The solution is to create the TFile to which you want to save the TTrees before creating the TTrees, then they will be automatically attached and become non-memory-resident. When the TTrees get large enough, the data will be dumped to disk rather than being held in memory.
Jean-François[/quote]
I have to appolygize, according to you, I created a TFile before the TTrees, and now it really works! Although the other day it seemed not so useful. I think perhaps it is the machine’s problem. Thank you very much!
I get this error while using genie
and is generated by the command:
ntp_writer.AddEventRecord(i_event, &event);
no TTree
s have been defined before a TFile
definition, as you can see from the definition and the declaration of the ntp_writer
ntp_writer.CustomizeFilenamePrefix(fOptOutPrefix.c_str());
ntp_writer.Initialize();
Here’s the NtpWriter class reference , as you can see it manages TFile
and TTree
s properly. Also, I get this error sometimes, on some random events, the event output look perfectly normal, for example here
Or this:
The error message:
Error in <TBranchObject::TBranch::WriteBasketImpl>: basket's WriteBuffer failed.
Error in <TBranchObject::TBranch::Fill>: Failed to write out basket.
Error in <TTree::Fill>: Failed filling branch:gtree.gmcrec, nbytes=-1, entry=911
This error is symptomatic of a Tree created as a memory-resident Tree
Instead of doing:
TTree *T = new TTree(...)
TFile *f = new TFile(...)
you should do:
TFile *f = new TFile(...)
TTree *T = new TTree(...)
As this happens on some events, if I can’t solve it, I would really appreciate if I could catch it from &event
and skip writing it to the file through ntp_writer
, how can I catch that? What does nbites=-1
mean? Maybe that’s how I could catch it, nbites=-1
, how do I access that value other than from the error message?
Thanks
Some info:
Machine: any Fermilab gpvm nodes for the DUNE experiment: for example: dunegpvm03@fnal.gov
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: Scientific
Description: Scientific Linux release 7.8 (Nitrogen)
Release: 7.8
Codename: Nitrogen
Versions of various software:
genie v2_12_10d -q e17:prof
geant4 v4_10_3_p03d -q e17:prof
cmake v3_14_3 -q Linux64bit+3.10-2.17 (used to build the package: rock_propagation)
root v6_16_00 -q e17:prof
Can it be that for all these “random events”, you also get some another strange warnings, like the “FOUND UNKNOWN PARTICLE with PDG:”?
If yes, it could be the origin of the problem.