Hi,
The loop ends with
which seems never used. Similarly, the loop seems to open new files with TFile *thisFile = TFile::Open(segmentName[r][iExtra].c_str(),"READ");
But it nevers deletes any of them. Most likely, the problem is that your are running out of resources (file descriptor and memory).
bool declared;
if (!declared) {
gROOT->ProcessLine(".L /data/macros/treesort/gtree.C");
gtree ttree; /* load class into memory (not doing this causes crash) */
declared = true; /* value will persist between runs in this session */
}
is doubly odd. ‘declared’ is never initialized and thus the if statement is ‘random’ per se. ‘declared’ is not set as a function static variable and thus the comment " value will persist between runs in this session" is technically wrong (albeit the same memory stack ‘might’ be re-used and not re-initialized and thus it ‘might’ appear to work sometimes … but will also fail some other time.
This should not be the case, unless the constructor of ‘gtree’ does something ‘important’
You can simplify this code:
TKey *tebKey = gDirectory->FindKey("teb");
if (tebKey == 0) {
cout << "Can't find tree 'teb'!" << endl;
return;
}
TTree *thistree = (TTree*)gROOT->FindObject("teb");
with just
TTree *thistree = nullptr;
thisFile->GetObject("teb",thistree);
if (thistree == nullptr) {
cout << "Can't find tree 'teb'!" << endl;
return;
}
Note: this pattern is used multiple time in your script.
which part is ‘held in memory and dumped periodically’ (beside the ‘entry’ of the output TTree)?
Yes. Just make sure that either AutoSave is set to the frequency you want (SetAutoSave(frequencyInNumberOfEntries) for example) or call it explicitly. In addition you need to call SaveSelf on the TFile ptr.
ntuple->SetAutoSave(numberOfEntries);
.....
if (readyToSnapshot) outputfile->SaveSelf();
[/code]or[code]
if (readyToSnapshot) {
ntuple->AutoSave();
outputfile->SaveSelf();
};
Note: don’t do that ‘too often’ as this is a slow operation and doing too often with reduce the efficient of both writing and reading the output file.
On the reading side, you can monitor this file then with something like:
while(1) {
f->ReadKeys();
TTree *ntuple = nullptr;
f->Get("ntuple",ntuple);
if (first == 0) ntuple->Draw("px>>hpx","","",10000000,first);
else ntuple->Draw("px>>+hpx","","",10000000,first);
first = (Int_t)ntuple->GetEntries();
delete ntuple; // Since it will change the next time we loop around, we don't want to keep it.
c1.Update();
gSystem->Sleep(1000); //sleep 1 second
}
Cheers,
Philippe.