TSelector and TTreeFormula update

Hi all,

I am using a TTreeFormula (which is created in the BeginSlave function) inside the Process function of a TSelector in order to apply certain cuts to the entries. When I only have one file in the TChain, everything is fine, but as soon as there are more files I get a segmentation violation.

If I have understood correctly how things work, I guess the TTreeFormula doesn’t point anymore to where it should be as soon a new file from the TChain is loaded. I think the fix should have something to to with the Notify function, but I am not really sure how I should do it.

I have done

in order to Notify the ttreeformulaObject that the tchain has changed, but it is not working.

Any hints/solutions?

Thanks,
Albert

Did you implement the function Notify in your object?

Rene

First of all let me correct myself, I am not using a TSelector but a TPySelector, my bad. Maybe it makes thinks slightly different.

As for implementing the Notify function, do you mean in the TTreeFormula objects? I thought these have the funcition already implemented… Or did you mean in the TPySelector? I tried implementing the Notify method and calling the Notify method of the TTreeFormula object, but it still didn’t work… I am surely missing something.

Albert

Hi,

Where did you put the ‘fChain.SetNotify(ttreeformulaObject)’? TTree::Process is also calling SetNotify (early on) to set it to the Selector. So the ‘right’ thing would be to call ttreeformulaObject->Notify() (or ttreeformulaObject->UpdateFormulaLeaves()) in your selector’s notify.

Cheers,
Philippe.

So, if I understand correctly, I should

  1. Declare the TTreeFormula object in the SlaveBegin method of the Selector (when the fChain has been defined), and do self.fChain.SetNotify(ttreeformulaObject).
  2. Do ttreeformulaObject.Notify() in the Notify method of the Selector.

I tried that but the ttreeformulaObject goes to None, it looks like I am not declaring things in the right place… What am I doing wrong?

Albert

[quote]So, if I understand correctly, I should[/quote]Not quite.
You should:

  1. Declare the TTreeFormula object in the SlaveBegin method of the Selector (when the fChain has been defined)
  2. Do ttreeformulaObject.Notify() in the Notify method of the Selector.

[quote]I tried that but the ttreeformulaObject goes to None, it looks like I am not declaring things in the right place… What am I doing wrong?[/quote]Humm … this seems to be peculiar to TPySelector ; you should re-open this issue in the pyroot forum.

Cheers,
Philippe.

Hi,

just guessing, but if the “ttreeformulaObject goes to None” then something is deleting it on the C++ side. Likely b/c it’s owner goes away?

Do you have a code sample?

Cheers,
Wim

Hi,

I have prepared a sample code, Test.py, with the TPySelectorFix.C. I have noticed something really strange, notice 2 slightly different sessions, and the different answers of the code:

Python 2.5.4 (r254:67916, Sep  3 2009, 13:52:29) 
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ROOT import *
>>> tf = TFile('2009-11.root')
>>> tree = tf.Get('LHCb-Production_Job')
>>> from Test import Test
>>> selector = Test()
>>> tree.Process(selector)
Notify
Notify
0L
>>> chain = TChain("LHCb-Production_Job")
>>> chain.AddFile("2009-11.root")
1
>>> chain.AddFile("2009-12.root")
1
>>> chain.Process(selector)
Notify
Notify
Notify
0L

All is fine, but in a fresh interpreter

[code]Python 2.5.4 (r254:67916, Sep 3 2009, 13:52:29)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-11)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

from ROOT import *
tf = TFile(’/data/lhcb19/a/apuig/tuplesnew/2009-11.root’)
from Test import Test
selector = Test()
chain = TChain(“LHCb-Production_Job”)
chain.AddFile("/data/lhcb19/a/apuig/tuplesnew/2009-11.root")
1

chain.AddFile("/data/lhcb19/a/apuig/tuplesnew/2009-12.root")
1

chain.Process(selector)
Notify
Info in TPySelectorFix::AbortProcess: ‘NoneType’ object has no attribute ‘Notify’
Info in TPySelectorFix::AbortProcess: ‘NoneType’ object has no attribute ‘Notify’
Info in TPySelectorFix::AbortProcess: none of the 2 overloaded methods succeeded. Full details:
TTreeFormula::TTreeFormula() =>
takes at most 0 arguments (3 given)
‘NoneType’ object has no attribute ‘Notify’
Info in TPySelectorFix::AbortProcess: none of the 2 overloaded methods succeeded. Full details:
TTreeFormula::TTreeFormula() =>
takes at most 0 arguments (3 given)
‘NoneType’ object has no attribute ‘Notify’
Notify
Info in TPySelectorFix::AbortProcess: ‘NoneType’ object has no attribute ‘Notify’
Info in TPySelectorFix::AbortProcess: ‘NoneType’ object has no attribute ‘Notify’
Traceback (most recent call last):
File “”, line 1, in
TypeError: none of the 3 overloaded methods succeeded. Full details:
Long64_t TChain::Process(const char* filename, Option_t* option = “”, Long64_t nentries = kBigNumber, Long64_t firstentry = 0) =>
could not convert argument 1 (expected string or Unicode object, Test found)
Long64_t TTree::Process(const char* filename, Option_t* option = “”, Long64_t nentries = 1000000000, Long64_t firstentry = 0) =>
could not convert argument 1 (expected string or Unicode object, Test found)
‘NoneType’ object has no attribute ‘Notify’

[/code]

It is very strange!!!

Cheers,
Albert
TPySelectorFix.C (923 Bytes)
Test.py (552 Bytes)

Hi,

I’ll venture a guess that “self.fChain” is None, hence the TTreeFormula ctor fails, and the self.formula stays set to None as it was initialized that way.

Btw., what is the purpose of “TPySelectorFix”?

Cheers,
WIm

Hi Wim,

if I replace self.fChain for tree (which was my first choice) it fails in the same way, so it doesn’t look like this is the problem. What is interesting is that Notify seems to be called before SlaveBegin, so then it is clear that the TTreeFormula doesn’t exist yet. Maybe I should initialize the TTreeFormula in another method?

BTW, the TPySelectorFix code was an old fix for the fact that one couldn’t inherit from TPySelector, I think it is not needed anymore, so I removed it. Same results…

Albert

Albert,

it was my first guess that Notify() was being called “too early” so I looked up the documentation and according to that, SlaveBegin() should always precede Notify(). But yes, if that happens, then clearly TTreeFormula should be either setup earlier, or Notify() should check for None.

Cheers,
Wim

Hi Wim,

Thanks a lot for the help, I have added a check for None in Notify and everything seems to be working now. I am surprised, though, that Notify is called before SlaveBegin.

Cheers,
Albert