Returning RooArgList from function


I see an issue with returning an RooArgList instance that is generated inside a function.

[code]def scope_test():
x = RooRealVar(“x”,"",0)
list = rt.RooArgList(“list”)
print list[0]
return list

lst = scope_test()[/code]

I can see the output; lst. But when I try to access its member via lat[0], the kernel report C++ error, not x.
The code above works if it is written outside the function. So it appears to be a scope issue. Could you please give me any suggestions or workarounds? I am using root 5.34 on Mac OS X 10.9


the problem is that RooFit likes to play footloose with const correctness. Even in C++, the const RooAbsArg& taken by add() may be a temporary per the language rules, but RooFit still does this: // add a pointer to this variable to our list (we don't own it!) _list.Add((RooAbsArg*)&var);
There are many cases of similar coding style in RooFit, and this will cause problems. Sometimes obviously, sometimes subversively. I do not recommend using RooFit from Python.

For this particular case, the easiest workaround here is to make the list an owner (takeOnwership()) and use addClone() instead of add() or release ownership on the Python side and use addOwned().