[RooFit] How to overwrite an existing dataset in a workspace?

For example, if I try to import two datasets of the same name

import ROOT

ws = ROOT.RooWorkspace()
pdf = ws.pdf("pdf")
x = ws.var("x")
dataset1 = pdf.generate(ROOT.RooArgSet(x), ROOT.RooFit.NumEvents(1000), ROOT.RooFit.Name(f"asimovData"))
dataset2 = pdf.generate(ROOT.RooArgSet(x), ROOT.RooFit.NumEvents(1000), ROOT.RooFit.Name(f"asimovData"))

I will get the following message

[#0] ERROR:ObjectHandling -- RooWorkspace::import() ERROR dataset with name asimovData already exists in workspace, import aborted

I could work around this by first renaming the old dataset and then import the new dataset like this

dataset = ws.data("asimovData")

However, this does not remove the old dataset from the workspace. Is there a way to overwrite/delete an existing dataset without rebuilding the entire workspace?

@jonas can you have a look here?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.