TPySelector different behavior in 5.26 and 5.30 (both bad)

Hi,

I am having some trouble getting even a basic TPySelector working under an Atlas Setup framework. To start I am not attempting to use Proof, although this is the goal. I see two behaviors depending on which version of ROOT is running, both are non-functional. I am using Atlas D3PDs. See below for details.

Thanks,

Peter

test.py

import time
from ROOT import *

myAtlasD3PD = 'pathToAtlasD3PD'

dataset = TChain('physics')
dataset.Add(myAtlasD3PD)

print dataset.Process( 'TPySelector', 'aapje' )

aapje.py

### selector module (aapje.py, name has to match as per above)
from ROOT import TPySelector

class MyPySelector( TPySelector ):
  def Begin( self ):
      print 'py: beginning'

  def SlaveBegin( self, tree ):
      print 'py: slave beginning'

  def Process( self, entry ):
      if not entry%10000: print 'py: processing {0}'.format(entry)

  def SlaveTerminate( self ):
      print 'py: slave terminating'

  def Terminate( self ):
      print 'py: terminating'

In 5.26.00e_python2.6 (Atlas Software release) it seems to run fine and then crashes:
py: beginning
py: slave beginning
py: processing 0
py: processing 10000
py: processing 20000
py: processing 30000
py: slave terminating
py: terminating
Traceback (most recent call last):
File “test2.py”, line 10, in
print dataset.Process( ‘TPySelector’, ‘aapje’ )
SystemError: Objects/longobject.c:237: bad argument to internal function

In 5.30.02 it seems to run TWICE and then crashes:
py: beginning
py: slave beginning
py: processing 0
py: processing 10000
py: processing 20000
py: processing 30000
py: slave terminating
py: terminating
py: beginning
py: slave beginning
py: processing 0
py: processing 10000
py: processing 20000
py: processing 30000
py: slave terminating
py: terminating
Traceback (most recent call last):
File “test2.py”, line 10, in
print dataset.Process( ‘TPySelector’, ‘aapje’ )
TypeError: none of the 4 overloaded methods succeeded. Full details:
Objects/longobject.c:237: bad argument to internal function
Objects/longobject.c:237: bad argument to internal function
Long64_t TChain::Process(void* selector, Option_t* option = “”, Long64_t nentries = kBigNumber, Long64_t firstentry = 0) =>
could not convert argument 1
Long64_t TTree::Process(void* selector, Option_t* option = “”, Long64_t nentries = 1000000000, Long64_t firstentry = 0) =>
could not convert argument 1

Hi,

at the very least, the Process overridden function needs to return a boolean, as per the C++ TSelector interface that it overrides:Bool_t Process(Long64_t /*entry*/);In your implementation, it returns None, hence the error when trying to turn None into a python long value that is to become the Bool_t. Likely the other errors will go away once that is fixed. E.g. if a python method fails and is part of an overload, the next choice is tried. That may explain why it runs twice (and fails twice) in the your v5-30 trial.

Cheers,
Wim

Thanks Wim!

That was it. It works perfectly now, with or without Proof.

Cheers,
Peter