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] Add RooAbsArg::getParameters RooAbsArg::getObservables overloads that takes output parameter #8142

Merged

Conversation

guitargeek
Copy link
Contributor

Creating RooArgSets on the heap should be avoided. The existing
RooAbsArg::getParameters/Observables created a RooArgSet calling operator new.
This commit adds an overload of RooAbsArg::getParameters/Observables that takes an
output parameter such that the output RooArgSet can also be created on
the stack.

Using these new methods, a memory leak in RooAbsReal::evaluateSpan is fixed. This leak was recently introduced in PR #7742 and backported to 6.24.

Therefore, this fix should also be backported to 6.24.

@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@guitargeek guitargeek force-pushed the fillObservablesParameters_1 branch from e650d89 to b6b9b52 Compare May 10, 2021 22:19
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

Copy link
Member

@lmoneta lmoneta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me !
I think is nice to have this new API for avoid creating all the time new RooArgset on the heap.
Only general comment thjat in general such functions in RooFit returns a Bool value , that is True if the function result in an error. Maybe we should change this to be consistent.

return getParameters(&data,stripDisconnected) ;
}
/// Return the parameters of the p.d.f given the provided set of observables
RooArgSet* getParameters(const RooArgSet& observables, Bool_t stripDisconnected=kTRUE) const {
RooArgSet* getParameters(const RooArgSet& observables, bool stripDisconnected=true) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add also a void getParameters also in the RooAbsData case ?
I would not add for the other cases where a reference instead of a pointer is passed.

Same below in case of getObservables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to not do this to not blow up the interface too much. The caller can just do data.get() to get a RooArgSet to use with the new void getParameters/Observables. If we see at some point that this becomes too verbose we can still add a void getParameters for the RooAbsData case, but I think it doesn't have to be done now. Is that okay for you?

}


void RooAbsArg::getParameters(const RooArgSet* nset, RooArgSet& out, bool stripDisconnected) const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe call maybe the output set outList or outSet or as before parList

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

out.clear();
out.setName("dependents");

if (!dataList) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return something here from the function (like False) or True ?
See for example bool RooAbsCollection::snapshot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@guitargeek guitargeek force-pushed the fillObservablesParameters_1 branch from b6b9b52 to 772c0f7 Compare May 11, 2021 17:20
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

@guitargeek guitargeek force-pushed the fillObservablesParameters_1 branch from 772c0f7 to e6aee2f Compare May 11, 2021 17:32
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

Creating RooArgSets on the heap should be avoided. The existing
`RooAbsArg::getParameters` created a RooArgSet calling `operator new`.
This commit adds an overload of `RooAbsArg::getParameters` that takes an
output parameter such that the output RooArgSet can also be created on
the stack.
Creating RooArgSets on the heap should be avoided. The existing
`RooAbsArg::getObservables` created a RooArgSet calling `operator new`.
This commit adds an overload of `RooAbsArg::getObservables` that takes an
output parameter such that the output RooArgSet can also be created on
the stack.
With this fix, the calls to getObservables and getParameters are
replaced with calls to the overloads that fill the RooArgSet in place.

This avoids the creation of RooArgSets on the heap, which should be
avoided to not let the MemPoolForRooSets grow too much.
@guitargeek guitargeek force-pushed the fillObservablesParameters_1 branch from e6aee2f to d55568e Compare May 11, 2021 17:35
@phsft-bot
Copy link
Collaborator

Starting build on ROOT-debian10-i386/cxx14, ROOT-performance-centos8-multicore/default, ROOT-fedora30/cxx14, ROOT-fedora31/noimt, ROOT-ubuntu16/nortcxxmod, mac1014/python3, mac11.0/cxx17, windows10/cxx14
How to customize builds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants