Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RF] Remove safeDeleteList functionality of RooAbsCollection #9685

Merged
merged 2 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion roofit/roofitcore/inc/RooAbsCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class RooAbsCollection : public TObject, public RooPrintable {
TString _name; // Our name.
Bool_t _allRRV ; // All contents are RRV

void safeDeleteList() ;
void deleteList() ;

// Support for snapshot method
Bool_t addServerClonesToList(const RooAbsArg& var) ;
Expand Down
45 changes: 7 additions & 38 deletions roofit/roofitcore/src/RooAbsCollection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -198,52 +198,21 @@ RooAbsCollection::~RooAbsCollection()
{
// Delete all variables in our list if we own them
if(_ownCont){
safeDeleteList() ;
deleteList() ;
}
}


////////////////////////////////////////////////////////////////////////////////
/// Examine client server dependencies in list and
/// delete contents in safe order: any client
/// is deleted before a server is deleted
/// Delete contents of the list.
/// The RooAbsArg destructor ensures clients and servers can be deleted in any
/// order.
/// Also cleans the hash-map for fast lookups if present.

void RooAbsCollection::safeDeleteList()
void RooAbsCollection::deleteList()
{
_hashAssistedFind = nullptr;

// Handle trivial case here
if (_list.size() > 1) {
std::vector<RooAbsArg*> tmp;
tmp.reserve(_list.size());
do {
tmp.clear();
for (auto arg : _list) {
// Check if arg depends on remainder of list
if (!arg->dependsOn(*this, arg)) tmp.push_back(arg);
}

// sort and uniquify, in case some elements occur more than once
std::sort(tmp.begin(), tmp.end());

tmp.erase(std::unique(tmp.begin(), tmp.end()), tmp.end());
// okay, can remove and delete what's in tmp
auto newEnd = _list.end();
for (auto item : tmp) {
newEnd = std::remove(_list.begin(), newEnd, item);
delete item;
}
_list.erase(newEnd, _list.end());
} while (!tmp.empty() && _list.size() > 1);

// Check if there are any remaining elements
if (_list.size() > 1) {
coutW(ObjectHandling) << "RooAbsCollection::safeDeleteList(" << GetName()
<< ") WARNING: unable to delete following elements in client-server order " ;
Print("1") ;
}
}

// Built-in delete remaining elements
for (auto item : _list) {
delete item;
Expand Down Expand Up @@ -757,7 +726,7 @@ void RooAbsCollection::removeAll()
_hashAssistedFind = nullptr;

if(_ownCont) {
safeDeleteList() ;
deleteList() ;
_ownCont= kFALSE;
}
else {
Expand Down