I’ve encountered an unexpected behaviour when working with my RooWorkspace interactively. To reproduce, create a file like this:
RooWorkspace w("w","w");
w.writeToFile("/tmp/test.root");
Now open the file in an interactive root session (root /tmp/test.root
) …
If, on the root prompt, I simply type “w” I get one pointer. But if I do gDirectory->Get("w")
I get a different pointer. Additionally, if I repeat calls to this, I get different pointers each time. So each time a new copy of the workspace is being read from the file, yes? I wanted to make the behaviour more like other standard ROOT objects, so after reading the workspace I add it to the gDirectory. This resolves my issue with different pointers retrieved by the Get
method, but the root prompt shortcut of using just the workspace name still refers to a different workspace.
root [1] .ls
TFile** /tmp/test.root
TFile* /tmp/test.root
KEY: RooWorkspace w;1 w
root [2] w
(RooWorkspace *) 0x7f8284c55a00
root [3] gDirectory->Get("w")
(TObject *) 0x7f8284d46a00
root [4] gDirectory->Get("w")
(TObject *) 0x7f8284d80e00
root [5] gDirectory->Add(gDirectory->Get("w"))
root [6] gDirectory->Get("w")
(TObject *) 0x7f82839c0c00
root [7] gDirectory->Get("w")
(TObject *) 0x7f82839c0c00
root [8] w
(RooWorkspace *) 0x7f8284c55a00
How can I access the same instance of the workspace that the ROOT prompt is accessing here? Or rather, how can I assure the ROOT prompt accesses the same version as my C++ code would access through the Get method?