Python crashes when using rootlogon.py and gROOT->SetStyle

Hello. I hope someone can point out why I’m getting an error with the following, it seems to simple…

I have a ~/.rootlogon.C with:

{ cout << endl << "Welcome to ./.rootlogon.C" << endl; gROOT->SetStyle("Plain"); }

and/or a ~/.rootlogon.py with:

import ROOT print "Welcome to your ./.rootlogon.py" ROOT.gROOT.SetStyle("Plain")

When I run python code with .rootlogon.py defined as above, I error like the following:

[code]mwoods 12:13:48 ~$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import ROOT
x = ROOT.Long()
Welcome to your ./.rootlogon.py
Traceback (most recent call last):
File “”, line 1, in
File “lib/ROOT.py”, line 396, in __getattr1
self.__finalSetup()
File “lib/ROOT.py”, line 479, in __finalSetup
imp.load_module( ‘rootlogon’, open( rootlogon, ‘r’ ), rootlogon, (’.py’,‘r’,1) )
File “/Users/mwoods/.rootlogon.py”, line 3, in
ROOT.gROOT.SetStyle(“Plain”)
File “lib/ROOT.py”, line 344, in getattr
self._master._ModuleFacade__finalSetup()
File “lib/ROOT.py”, line 447, in __finalSetup
self.class.getattr = self.class.__getattr2
AttributeError: type object ‘ModuleFacade’ has no attribute ‘_ModuleFacade__getattr2’

[/code]

If I remove .rootlogon.py then .rootlogon.C runs just fine (I see the cout and the style is changed). It is the SetStyle method that is causing problems, but I can’t figure out why. Any ideas? Thanks.

Hi,

not so much SetStyle(), but just that gROOT is initially a special case so that SetBatch() can be called on it before the TApplication is created (and hence pre-empting any graphics initialization). The __finalSetup() is calling rootlogon.py, but at that point gROOT is still the wrapper, so __finalSetup() is called again from within rootlogon.py.

Now fixed in trunk.

As a workaround, do:ROOT.module._root.gROOT.SetStyle("Plain")which will bypass the gROOT wrapper.

Cheers,
Wim

Thanks Wim. Worked like a charm.