[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()
ws.factory("Gaussian::pdf(x[0,10],mu[4,0,10],sigma[1.0,0.1,10.0])")
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"))
ws.Import(dataset1)
ws.Import(dataset2)

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

ws.Import(dataset1)
dataset = ws.data("asimovData")
dataset.SetName("asimovDataOld")
ws.Import(dataset2)

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.