Saving and retrieving datasets from a RooWorkspace

Dear Experts,
I’m trying to save a set of datasets inside a workspace and then retrieving them.
I manage to import my dataset to the workspace, but when I open the workspace again all it looks like the dataset are all without a name.

I’m doing:

w = RooWorkspace(workspacename)
for d in datasets:
    getattr(w,'import')(d)
w.Print()

w.writeToFile(workspacename+".root", kTRUE)

f = TFile(workspacename+'.root')
w2 = RooWorkspace(f.Get(workspacename))
w2.Print()

And the obtained output is:
[#1] INFO:ObjectHandling – RooWorkspace::import(data50000_j70_nSigma5_0_pt_200) importing dataset DataSet
[#1] INFO:ObjectHandling – RooWorkspace::import(data50000_j70_nSigma5_0_pt_200) importing RooRealVar::DeltaY
[#1] INFO:ObjectHandling – RooWorkspace::import(data50000_j70_nSigma5_0_pt_200) importing dataset longDataSet
[#1] INFO:ObjectHandling – RooWorkspace::import(data50000_j70_nSigma5_0_pt_200) importing dataset LongSigmaDataSet
[#1] INFO:ObjectHandling – RooWorkspace::import(data50000_j70_nSigma5_0_pt_200) importing dataset DownstreamSigmaDataSet

RooWorkspace(data50000_j70_nSigma5_0_pt_200) data50000_j70_nSigma5_0_pt_200 contents

variables

(DeltaY)

datasets

RooDataSet::DataSet(DeltaY)
RooDataSet::longDataSet(DeltaY)
RooDataSet::LongSigmaDataSet(DeltaY)
RooDataSet::DownstreamSigmaDataSet(DeltaY)

RooWorkspace(data50000_j70_nSigma5_0_pt_200) data50000_j70_nSigma5_0_pt_200 contents

variables

(DeltaY)

datasets

RooDataSet::(DeltaY)
RooDataSet::(DeltaY)
RooDataSet::(DeltaY)
RooDataSet::(DeltaY)

What am I doing wrong?
Thanks a lot in advance and sorry for such a stupid question.

      Barbara

Dear All,
I found the solution of my problem:
the wrong line was:

 w2 = RooWorkspace(f.Get(workspacename))

it doesn’t make sense to try to use the constructor in order to explicitly cast the returned value of f.Get, as in PyROOT this is already the instantiated object, and not a mere pointer to it.

For reference, the recipe to save and retrieve a RooWorkspace is:

    #  Writing a workspace
    w = RooWorkspace(workspacename)
    for d in datasets:
        # Trick to use the import method in PyROOT
        getattr(w,'import')(d)
    w.writeToFile(workspacename+".root", kTRUE)
    # Retrieving the workspace
    f = TFile(workspacename+'.root')
    w2 = (f.Get(workspacename))

Cheers,

    Barbara