I wrote a function with a TChain* as argument (among others), in which I fill a TEntryList* using a TCut, then I loop over the entries of the TEntryList* in the TChain* to compute a weight and fill a histogram (took examples from the documentation) :
tree->Draw(">>skim",cut,"entrylist");
TEntryList *skim = (TEntryList*)gDirectory->Get("skim");
int nEntries = skim->GetN();
tree->SetEntryList(skim);
int treenum, iEntry, chainEntry;
treenum = iEntry = chainEntry = -1;
for(Long64_t i=0 ; i<nEntries ; i++) {
iEntry = skim->GetEntryAndTree(i, treenum);
chainEntry = iEntry + (tree->GetTreeOffset())[treenum];
tree->GetEntry(chainEntry);
[... compute a weight and fill a histogram ...]
}
Is it the correct way to generate the TEntryList* and then to use it to loop over chain entries ?
As I call this function many times to process many TChain* using many different TCuts, at the second call a segmentation violation occurs, when trying the gDirectory->Get.
I guess this is due to recording several times in a row a TEntryList* under the same name, so how should I do this ?
From the code of TChain::SetEntryList(0) , it seems it deletes the previously generated entrylist … Is there a way to avoid such frequent delete, and actually keep rewritting generated tentrylist without causing code crash on deletion of TChain ?
Surprisingly, I checked the ownership and the chain is not the owner.
Yet when chain is deleted the code crashes. I am attaching the file
containing the relevant function as full code is very big. minimal.C (11.0 KB)