Nullptr after using chain -> SetEntryList()

Hi,

I am using the following code inside a member function of a class. When I call the member function the first time, I have no issues.

However, upon calling the function a second time, EList has become a nullptr, I have not freed or otherwise destroyed EList, so this is somewhat confusing to me.

void MyClass::GetEventsFromCut(TCut cut)
{
        // get all events from the tree
        this -> Chain -> Draw(">>elist", cut, "entrylist");
        this -> CurrentCut = cut;

        // structure for keeping
        // all events that passed the cut
        this -> EList = (TEntryList*)gDirectory->Get("elist");

        // set the chain to use this entrylist
        this -> Chain -> SetEntryList(this -> EList);

        // number of events to pass cut
        cout << this -> EList -> GetN() << " Events passed cut" << endl;
}

I’ve reviewed the source ROOT: tree/tree/src/TChain.cxx Source File but I don’t see where the pointer could be freed or destroyed unless this is scope management issue on my part. Any help is greatly appreciated.

Thanks,

James


_ROOT Version:6.14/06
_Platform: Linux x8664
_Compiler: gcc


Before the “Draw”, add:
this -> Chain -> SetEntryList(0);

Hi,

Thanks for getting back with me, I was still getting a nullptr error on this line

cout << this -> EList -> GetN() << " Events passed cut" << endl;

So to make sure of what was going on I commented out this line and added some cout statements. So the updated version of this is

void MyClass::GetEventsFromCut(TCut cut)
{
        // get all events from the tree
        this -> Chain -> Draw(">>elist", cut, "entrylist");
        this -> CurrentCut = cut;
        cout << "processed cut!" << endl;
        // structure for keeping
        // all events that passed the cut
        this -> EList = (TEntryList*)gDirectory->Get("elist");

        cout << "got EList!" << endl;

        this -> Chain -> SetEntryList(0);
        
        cout << "emptied entry list!" << endl;
        // set the chain to use this entrylist
        this -> Chain -> SetEntryList(this -> EList);
        
        cout << "set entry list!" << endl;

        // number of events to pass cut
        //cout << this -> EList -> GetN() << " Events passed cut" << endl;
}

It seems anytime after

this -> EList = (TEntryList*)gDirectory->Get("elist");

That EList is a nullptr. I’m going to dig more into gDirectory and see if that maybe has anything to do with it, but any additional feedback is very welcome in the meantime.

Put the “SetEntryList(0)” line right BEFORE the “Draw” line.

Apologies, I was much too tired when I did that last bit and missed that detail. Doing that works!

Thanks so much for your help.