Re: [Gaudi-talk] PyRoot, Reflex, STL iterators and __deref__()

From: Pere Mato <pere.mato_at_cern.ch>
Date: Thu, 11 Dec 2008 08:25:38 +0100


Hi Brett,

   You have also to create the dictionary for the std::pair<const short,DayaBay::SimHitCollection*>.

                Pere

On Dec 11, 2008, at 5:06 AM, Brett Viren wrote:

> Hi Wim,
>
> Thanks for your test code. I reproduce your results but going just a
> little further I fall down again:
>
> WLavrijsen_at_lbl.gov writes:
>
> [...snip...]
>
>> PyCintex.loadDict( "libbrett" )
>> m = PyCintex.gbl.std.map( 'short', 'DayaBay::SimHitCollection*' )()
>> print m.begin().__deref__
>>
>>
>> I do get a warning about no dictionary being available for class
>> DayaBay::SimHitCollection, but that's a non-issue.
>
> [And, adding this class to the selection.xml quells the warning.]
>
> Now, I can get the Python wrapped pair by calling __deref__() but how
> do I access the first/second members of the pair? There are no such
> members on the Python side. I took a guess and tried treating the
> pair as an 2 element array with the following failure:
>
> In [1]: import PyCintex
> In [2]: PyCintex.loadDict("libbrett")
> In [3]: m =
> PyCintex.gbl.std.map('short','DayaBay::SimHitCollection*')()
> In [4]: b = m.begin()
> In [5]: d = b.__deref__()
> In [6]: d
> Out[6]: <ROOT.pair<const short,DayaBay::SimHitCollection*> object at
> 0x88a38d4>
> In [7]: d.<TAB>
> d.__class__ d.__ge__ d.__init__
> d.__new__ d.__setattr__
> d.__delattr__ d.__getattribute__ d.__le__
> d.__nonzero__ d.__str__
> d.__dict__ d.__getitem__ d.__lt__
> d.__reduce__ d.__weakref__
> d.__doc__ d.__gt__ d.__module__
> d.__reduce_ex__
> d.__eq__ d.__hash__ d.__ne__ d.__repr__
> In [13]: d[0]
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent
> call last)
>
> /home/bviren/work/dayabay/offline/nuwa-git/debug/ExDictionary/wim/
> <ipython console> in <module>()
>
> AttributeError: 'pair<const short,DayaBay::SimHitCollection*>'
> object has no attribute 'first'
>
> In [14]: d[1]
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent
> call last)
>
> /home/bviren/work/dayabay/offline/nuwa-git/debug/ExDictionary/wim/
> <ipython console> in <module>()
>
> AttributeError: 'pair<const short,DayaBay::SimHitCollection*>'
> object has no attribute 'second'
>
>
> Thanks for the help!
> -Brett.



Pere Mato CERN, PH Department, CH 1211 Geneva 23, Switzerland
           e-mail: pere.mato_at_cern.ch      tel: +41 22 76 78696
           fax:  +41 22 76 68792            gsm: +41 76 48 70855
Received on Thu Dec 11 2008 - 08:25:42 CET

This archive was generated by hypermail 2.2.0 : Thu Dec 11 2008 - 11:50:01 CET