Hi,
I looked at these files. I saw that MulAFibMD was of type buffer and was iterable (did exactly as you would expect), but pmfDataMD was not. I'm not sure if it's because of its type of Bool_t or because it's a 2D C++ array. In Python, bool (True, False) is a subset of int, but I'm not sure if that's the case for ROOT.
I'm not sure how to extract this information out of the C++ array with Python. Maybe Wim would know...
On Nov 25, 2008, at 11:14 AM, Dennis Petschull wrote:
> Dear Chris,
>
> As this is getting a little confusing for me, I attached a sample
> rootfile and the python script. I also attached a simple C++ makro,
> which shows how I would achieve my goal in C++.
>
> Maybe this will help to solve the problem easier.
>
> Thanks in advance for your efforts!
>
>
> Cheers,
> Dennis
>
>
> -----Ursprüngliche Nachricht-----
> Von: Christopher Jones [mailto:c_jones_at_MIT.EDU]
> Gesendet: Di 25.11.2008 16:29
> An: Dennis Petschull
> Betreff: Re: AW: [ROOT] PyROOT: Getting boolean array (branch) out
> of tree
>
> Hmm okay. If you just dropped the "if" test and wrote "print
> pmfDataMD", what happens? Still nothing? What happens if you do
> type(tree.pmfDataMD)? I think you did that for nEvent in pmfDataMD but
> pmfDataMD itself is probably a container.
>
> On Nov 25, 2008, at 10:18 AM, Dennis Petschull wrote:
>
>> Dear Chris,
>>
>> if I try your code, there is no output at all.
>>
>> Btw, if I do the following in C++, I have no problem accessing the
>> data (maybe this helps):
>>
>> [...]
>> Bool_t pmfDataMD[NUMLAYMD][NUMFIBMD];
>> [...]
>> correl_tree->SetBranchAddress("pmfDataMD",&pmfDataMD);
>> [...]
>>
>>
>> Cheers,
>> Dennis
>>
>>
>> -----Ursprüngliche Nachricht-----
>> Von: Christopher Jones [mailto:c_jones_at_MIT.EDU]
>> Gesendet: Di 25.11.2008 16:03
>> An: Dennis Petschull
>> Cc: roottalk_at_lxbuild091.cern.ch
>> Betreff: Re: [ROOT] PyROOT: Getting boolean array (branch) out of
>> tree
>>
>> Okay, so it's a long int in your tree, and you can only iterate
>> over a
>> sequence; I'm guessing your other branches contain lists, tuples, etc
>> and that's why you can use loops. As a matter of fact, the long int
>> is just tree.pmfDataMD. Why can't you just type:
>>
>> [...all your previous code...]
>>
>> nb = tree.GetEntry( jentry )
>> if nb <= 0:
>> continue
>>
>> if tree.pmfDataMD >= 1:
>> print tree.pmfDataMD
>>
>> On Nov 25, 2008, at 9:44 AM, Dennis Petschull wrote:
>>
>>> Thanks for your response,
>>>
>>> The error is the following for pmfDataMD:
>>>
>>> Traceback (most recent call last):
>>> File "layer_eff_rt.py", line 18, in ?
>>> for nEvent in tree.pmfDataMD:
>>> TypeError: iteration over non-sequence
>>>
>>>
>>> If I insert print type(tree.pmfDataMD) right after the
>>>
>>> tree = gDirectory.Get( 'correl_tree' )
>>> entries = tree.GetEntriesFast()
>>>
>>> statements, I get the following printed out:
>>> <type 'long'>
>>> Traceback (most recent call last):
>>> File "layer_eff_rt.py", line 19, in ?
>>> for nEvent in tree.pmfDataMD:
>>> TypeError: iteration over non-sequence
>>>
>>>
>>> Cheers,
>>> Dennis
>>>
>>>
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: Christopher Jones [mailto:c_jones_at_MIT.EDU]
>>> Gesendet: Di 25.11.2008 15:16
>>> An: Dennis Petschull
>>> Cc: roottalk_at_lxbuild091.cern.ch
>>> Betreff: Re: [ROOT] PyROOT: Getting boolean array (branch) out of
>>> tree
>>>
>>> Hi,
>>>
>>> What does the error look like when you try this? Also, in your
>>> loop,
>>>
>>>>
>>>> for nEvent in tree.pmfDataMD:
>>>> if nEvent >= 1:
>>>> print nEvent
>>>
>>>
>>> could you find out the type of the iterable "nEvent" (with say
>>> type(nEvent) )? Maybe you have to do a little more to tease out the
>>> value you want (like indexing), depending on your error message or
>>> bug.
>>>
>>> Chris Jones
>>> c_jones_at_mit.edu
>>>
>>>
>>>
>>>
>>>
>>>
>>
>> Chris Jones
>> c_jones_at_mit.edu
>>
>>
>>
>>
>>
>>
>
> Chris Jones
> c_jones_at_mit.edu
>
>
>
>
>
>
>
>
> <correl_SI_853_ALFA_67.root><layer_eff_rt.py><Layer_eff.C>
Chris Jones
c_jones_at_mit.edu
Received on Tue Nov 25 2008 - 18:05:48 CET
This archive was generated by hypermail 2.2.0 : Tue Nov 25 2008 - 23:50:02 CET