Skip to content

Commit

Permalink
[RF] Override TObject::Clone() in RooWorkspace
Browse files Browse the repository at this point in the history
Many users expect to use `Clone()` to copy RooWorkspaces, but so far
this resulted in corrupt workspaces because the `Clone()` function was
not overridden.
  • Loading branch information
guitargeek committed Apr 11, 2023
1 parent 5f7c330 commit ad275f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions roofit/roofitcore/inc/RooWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class RooWorkspace : public TNamed {
RooWorkspace(const RooWorkspace& other) ;
~RooWorkspace() override ;

TObject *Clone(const char *newname="") const override;

bool importClassCode(const char* pat="*", bool doReplace=false) ;
bool importClassCode(TClass* theClass, bool doReplace=false) ;

Expand Down
10 changes: 10 additions & 0 deletions roofit/roofitcore/src/RooWorkspace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ RooWorkspace::RooWorkspace(const RooWorkspace& other) :
}


/// TObject::Clone() needs to be overridden.
TObject *RooWorkspace::Clone(const char *newname) const
{
auto out = new RooWorkspace{*this};
if(newname && std::string(newname) != GetName()) {
out->SetName(newname);
}
return out;
}


////////////////////////////////////////////////////////////////////////////////
/// Workspace destructor
Expand Down

0 comments on commit ad275f1

Please sign in to comment.