a
    zn„fß’  ã                   @  sÒ   d Z ddlmZ ddlZddlZddlZddlZddlZddlZG dd„ dej	j
ƒZdd„ Zdd	„ ZG d
d„ dej	jjƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZdd„ ZG dd„ dƒZdS )ax  
This module defines an :doc:`uproot.interpretation.Interpretation` and
temporary array for object data (Python objects or Awkward Array data structures).

The :doc:`uproot.interpretation.objects.AsObjects` describes fully generic
objects using a :doc:`uproot.model.Model` (or a :doc:`uproot.containers.AsContainer`).
These objects require a non-vectorized loop to deserialize.

The :doc:`uproot.interpretation.objects.AsStridedObjects` describes fixed-width
objects that can be described as a ``numpy.dtype``. These objects can be
interpreted as a single, vectorized cast, and are therefore much faster to
deserialize.

The :doc:`uproot.interpretation.objects.ObjectArray` and
:doc:`uproot.interpretation.objects.StridedObjectArray` classes only hold data
while an array is being built from ``TBaskets``. Its final form is determined
by the :doc:`uproot.interpretation.library.Library`.
é    )ÚannotationsNc                   @  sÂ   e Zd ZdZd,dd„Zedd„ ƒZedd„ ƒZd	d
„ Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZedd„ ƒZedd„ ƒZd-dd„Zdd„ Zdd„ Zd.d d!„Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ ZdS )/Ú	AsObjectsa„  
    Args:
        model (:doc:`uproot.model.Model` or :doc:`uproot.containers.AsContainer`): The
            full Uproot deserialization model for the data.
        branch (None or :doc:`uproot.behaviors.TBranch.TBranch`): The ``TBranch``
            from which the data are drawn.

    Integerpretation for arrays of any kind of data that might reside in a
    ROOT ``TTree``. This interpretation prescribes the full (slow)
    deserialization process.

    :ref:`uproot.interpretation.objects.AsObjects.simplify` attempts to
    replace this interpretation with a faster-to-read equivalent, but not all
    data types can be simplified.
    Nc                 C  s,   || _ || _d | _d| _d | _t ¡ | _d S )NT)Ú_modelÚ_branchÚ_formÚ_forthÚ_complete_forth_codeÚ	threadingÚLockÚ_forth_lock)ÚselfÚmodelÚbranch© r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/interpretation/objects.pyÚ__init__2   s    zAsObjects.__init__c                 C  s   | j S ©z‘
        The full Uproot deserialization model for the data
        (:doc:`uproot.model.Model` or :doc:`uproot.containers.AsContainer`).
        ©r   ©r   r   r   r   r   :   s    zAsObjects.modelc                 C  s   | j S )zM
        The ``TBranch`` from which the data are drawn. May be None.
        ©r   r   r   r   r   r   B   s    zAsObjects.branchc                 C  s,   t | jtƒr| jj}n
t| jƒ}d|› d�S )Nz
AsObjects(ú))Ú
isinstancer   ÚtypeÚ__name__Úrepr)r   r   r   r   r   Ú__repr__I   s    

zAsObjects.__repr__c                 C  s   t |tƒo| j|jkS ©N)r   r   r   ©r   Úotherr   r   r   Ú__eq__P   s    zAsObjects.__eq__c                 C  s   dd„ | j  ¡ D ƒS )Nc                 S  s0   i | ](\}}|t |tjjjƒr(tj ¡ n|“qS r   )r   Úuprootr   Ú_LockPlaceholderZ	lock_type©Ú.0ÚkÚvr   r   r   Ú
<dictcomp>T   s
   ûÿz*AsObjects.__getstate__.<locals>.<dictcomp>)Ú__dict__Úitemsr   r   r   r   Ú__getstate__S   s    úzAsObjects.__getstate__c                 C  s"   dd„ |  ¡ D ƒ}| j |¡ d S )Nc                 S  s,   i | ]$\}}|t |tjjƒr$t ¡ n|“qS r   )r   r    r   r!   r	   r
   r"   r   r   r   r&   ^   s   ÿz*AsObjects.__setstate__.<locals>.<dictcomp>)r(   r'   Úupdate)r   ÚstateZinstance_datar   r   r   Ú__setstate__]   s    þzAsObjects.__setstate__c                 C  s
   t  t¡S r   ©ÚnumpyÚdtypeÚobjectr   r   r   r   Únumpy_dtyped   s    zAsObjects.numpy_dtypec                 C  s$   t j | j¡}t| ƒj› d|› d�S ©Nú(r   )r    Ú
containersZ_content_cache_keyr   r   r   )r   Zcontent_keyr   r   r   Ú	cache_keyh   s    zAsObjects.cache_keyc                 C  s0   t | jtjjƒr| jjS tj | jj¡d S d S ©Nr   )	r   r   r    r4   ZAsContainerÚtypenamer   Úclassname_decoder   r   r   r   r   r7   m   s    zAsObjects.typenameÚi64Fr   c                 C  s$   |   |||||¡}| j | jj|¡S r   )Ú_make_contextr   Úawkward_formr   Úfile)r   r<   ÚcontextÚindex_formatÚheaderÚtobject_headerÚbreadcrumbsr   r   r   r;   t   s    	
ÿzAsObjects.awkward_formc	           
      C  sš   | j ||||||||d� |jd us(J ‚| jrbt|tjjjtjjjfƒrb|  	||||||||¡}	nt
| j|||||ƒ ¡ }	| j||||||	|||d�	 |	S )N©ÚdataÚbyte_offsetsÚbasketr   r=   Úcursor_offsetÚlibraryÚoptions©	rC   rD   rE   r   r=   ÚoutputrF   rG   rH   )Úhook_before_basket_arrayrD   r   r   r    ÚinterpretationrG   ÚAwkwardÚPandasÚbasket_array_forthÚObjectArrayr   Úto_numpyÚhook_after_basket_array)
r   rC   rD   rE   r   r=   rF   rG   rH   rJ   r   r   r   Úbasket_array‚   sX    ø
þþÿ	øÿ÷zAsObjects.basket_arrayc	                 C  sÐ  t j ¡ }	dd l}	| j||||||||d� |jd us:J ‚t|d dd ƒd u rld |d _t j 	| ¡|d _
n
d |d _
| jd u �r˜| j� �ü | js¸|  ||||||||¡W  d   ƒ S | jd u �rxt|ƒ}d|d< z|  |||||¡}
W nT t�y>   d| _d |d _
d |d _|  ||||||||¡ Y W  d   ƒ S 0 |
d u�rx| j||||||
|||d�	 |
W  d   ƒ S W d   ƒ n1 �sŽ0    Y  | jd u�s¨J ‚|d jd u �rz|	j | j¡|d _W nB t�y } z(t|ƒt|ƒd	 | j ƒ|‚W Y d }~n
d }~0 0 ||d |d
 … }|d j t |¡t |d d
… ¡t |dd … ¡dœ¡ |d j t|ƒd ¡ |d j ¡  i }|d jj}|	 | j t|ƒd |¡}
| j||||||
|||d�	 |
S )Nr   rB   ÚforthÚvmr   ÚpathFrI   z,

Forth code generated for this data type:

éÿÿÿÿé   )ÚstreamZbyteoffsetsZ	bytestops)!r    ÚextrasÚawkwardZawkward.forthrK   rD   ÚgetattrrU   Z_awkwardforthZForthGeneratorÚgenr   r   r   rS   ÚdictÚ_discover_forthÚCannotBeForthrR   rT   ZForthMachine64Ú	Exceptionr   ÚstrÚbeginr.   ÚarrayZ
stack_pushÚlenÚresumeÚoutputsZfrom_buffersr   )r   rC   rD   rE   r   r=   rF   rG   rH   r[   rJ   ÚerrZ	temp_dataÚ	containerr   r   r   rO   À   sÐ    
ø



ø
ÿ

ø
÷2ÿÿþÿü
ýÿ÷zAsObjects.basket_array_forthc                 C  s�   ||j  d¡krd S |j |j¡ |j |j¡ |j  d¡rX|jD ]}| j||dd� qB|j	 |j
¡ |jD ]}|  ||¡ ql|j	 |j¡ d S )Nzbase-class zread-members T)Ú	only_base)ÚnameÚ
startswithÚfinal_headerÚextendZheader_codeÚ
final_initZ	init_codeÚchildrenÚ_assemble_forthÚ
final_codeZpre_codeZ	post_code)r   Ú	forth_objÚnoderj   Úchildr   r   r   rq   G  s    

zAsObjects._assemble_forthc                 C  sˆ   |dkrdS |  d¡}|d ur(|  |¡S |  d¡}t|tƒrX|D ]}|  |¡r@ dS q@n(t|tƒr€| ¡ D ]}|  |¡rj dS qjdS d S )NZNULLTÚcontentÚcontentsF)ÚgetÚ	_any_NULLr   Úlistr^   Úvalues)r   Úformrv   rw   r   r   r   ry   W  s    







zAsObjects._any_NULLc                 C  s„   |   ||jjd ¡ | j | jjdddddœ¡}td|› dtj	|j 
¡ dd	�› d
d |j¡› dd |j¡› dd |j¡› d�ƒ‚d S )Nr   r9   Fr   )r>   r?   r@   rA   zEXPECTED FORM:
z

DISCOVERED FORM:
é   )ÚindentzI

FORTH CODE:
input stream
    input byteoffsets
    input bytestops
    Ú ú
    ú8
    0 do
    byteoffsets I-> stack
    stream seek
    ú
    loop
    )rq   r   rp   r   r;   r   r<   ra   ÚjsonÚdumpsÚderive_formÚjoinrm   ro   rr   )r   rs   Zexpected_formr   r   r   Ú_debug_forthk  s,    üþ
ÿü

ö
õ
ñÿzAsObjects._debug_forthc              
   C  s@  t jt|ƒd t  t¡d�}tt|ƒd ƒD �]}tjjj	 
|jj||| ||d  … ¡}tjjjd|| |  d�}	|d j ¡  | j ||	||j|jj|¡||< |d jj ¡ }
|  |
¡s,d|d _|  |d j|d jjjd ¡ dd |d jj¡› d	d |d jj¡› d
d |d jj¡› d�| _|
| _ d S q,|S )NrX   ©r/   r   ©ÚoriginrT   Tz;input stream
    input byteoffsets
    input bytestops
    r   r€   r�   r‚   )r.   Úemptyre   r/   r0   Úranger    ÚsourceÚchunkÚChunkÚwrapr<   ÚcursorÚCursorr]   Zreset_active_noder   ÚreadÚdetachedr   r…   ry   Zprereaddonerq   rp   r†   rm   ro   rr   r   r   )r   rC   rD   r   r=   rF   rJ   ÚirŽ   r‘   Zderived_formr   r   r   r_   Œ  s8    
ÿÿÿ

ÿýüø
zAsObjects._discover_forthc              
   C  sÀ  | j |||||||d� g }|d }	tdd„ | ¡ D ƒƒ}
t|dd … ƒD �]®\}}d }|	|krŠ||krŠ||	 }||	 }|| ||… }nŒ|	|  krž|k rÄn n"||	 }||	 }|| ||… }nR|	|  krØ|krún nd}||	 }|| ||… }n||k �r|	|k�r|| }|d u�râ|
�rât|tjjjƒ�rD| 	|¡ nœt|tjjj
ƒ�r’t|tjƒ�r†| 	tjj tj ¡ | j|¡¡ n
| 	|¡ nNt|tjjjƒ�röt|tjƒ�rÖ| 	tjjj|d|jj| jd�¡ n
| 	|¡ n|d u�rö| 	|¡ |}	qJt|ƒdk�rtjg | jd�}nZtd	d„ | ¡ D ƒƒ�rlt|tjjj
tjjjfƒ�rltj ¡ }|j|ddd
�}n
t |¡}| j|||||||d� | ||| |||¡}| j||||||||d� |S )N)Úbasket_arraysÚentry_startÚ
entry_stopÚentry_offsetsrG   r   rH   r   c                 s  s   | ]}t j |d ¡V  qdS ©r[   N©r    Ú_utilZfrom_module©r#   Úxr   r   r   Ú	<genexpr>É  s   z(AsObjects.final_array.<locals>.<genexpr>rX   F)r|   rˆ   c                 s  s   | ]}t j |d ¡V  qdS rš   r›   r�   r   r   r   rŸ     s   )Z	mergeboolZ	highlevel)r–   r—   r˜   r™   rG   r   rJ   )r–   r—   r˜   r™   rG   r   rJ   rH   )Zhook_before_final_arrayÚanyr{   Ú	enumerater   r    rL   rG   ÚNumPyÚappendrM   r.   ÚndarrayZ_object_to_awkward_arrayrZ   r[   r   rN   Z_process_array_for_pandasr<   re   rd   r1   ÚallZconcatenateZhook_before_library_finalizeÚfinalizeZhook_after_final_array)r   r–   r—   r˜   r™   rG   r   rH   ZtrimmedÚstartZhas_any_awkward_typesÚ
basket_numÚstopZ	to_appendZlocal_startZ
local_stoprJ   r[   r   r   r   Úfinal_array´  sº    
ù	ÿÿÿüÿ	

ÿ
þþþ	

ù
ÿøzAsObjects.final_arrayc                 C  sü  | j durPt t¡�, | jj| j jddd| jd�W  d  ƒ S 1 sF0    Y  t| jtj	j
ƒr�d}| jjrpd}tjjj|| jj| jj| jd�S t| jtj	jtj	jtj	jfƒ�rød}t| jtj	jƒrÔ| jjrÔ|d	7 }t| jtj	jtj	jfƒ�r | jj�r |d
7 }t| jjtjƒ�r@tjj | jj¡}tjjj||| jj| jd�S | j du�røt t¡�� | jjj| j jddd| jjd�}t| jtj	jƒ�r¼| jj�r¼t|tjjjƒ�s®tdƒ‚| | jj¡ tjjj||| jj| jd�W  d  ƒ S 1 �sî0    Y  | S )zø
        Attempts to replace this :doc:`uproot.interpretation.objects.AsObjects`
        with an interpretation that can be executed more quickly.

        If there isn't a simpler interpretation, then this method returns
        ``self``.
        NFTr   )r?   r@   rA   Úoriginalr   é   )r«   rX   é
   zI shouldn't be here)r   Ú
contextlibÚsuppressÚCannotBeStridedr   Zstrided_interpretationr<   r   r    r4   ZAsStringr?   rL   ÚstringsZ	AsStringsZlength_bytesr7   ZAsArrayZAsRVecZAsVectorZ	speedbumpr{   r.   r/   Ú	numericalÚAsDtypeZjaggedZAsJaggedÚinner_shapeÚRuntimeErrorÚreshape)r   Úheader_bytesrv   r   r   r   Úsimplify/  sŠ    
û$üýþÿþÿÿüÿûÿþ
ÿü&zAsObjects.simplify)N)Nr9   FFr   )F)r   Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r)   r,   r1   r5   r7   r;   rS   rO   rq   ry   r‡   r_   rª   r¸   r   r   r   r   r   !   s>   






	     ù
> 
!({r   c                 C  sZ   g }| D ]L\}}t |tƒrFt|jƒD ]\}}| |d | |f¡ q$q| ||f¡ q|S )Nú/)r   ÚAsStridedObjectsÚ_unravel_membersÚmembersr£   )rÀ   Úoutrk   ÚmemberÚnÚmr   r   r   r¿   „  s    
r¿   c           	      C  s¦   i }|D ]v\}}|d s"|dv r"q|d s4|dv r4qt |tƒrjtj |jj¡d }t| ||j||ƒ||< qtj	 
|||¡||< q| jjt| ¡ ƒt| ¡ ƒd|id�S )Nr?   )ú
@num_bytesú@instance_versionr@   )NrÅ   rÆ   z
@fUniqueIDz@fBitsz@pidfr   Z
__record__)Ú
parameters)r   r¾   r    r   r8   r   r   Ú_strided_awkward_formÚ_membersrœ   r;   ÚformsZ
RecordFormrz   r{   Úkeys)	r[   Ú	classnamerÀ   r<   r=   rw   rk   rÂ   Úcnamer   r   r   rÈ   �  s"    
ÿ


ýrÈ   c                      s    e Zd ZdZd ‡ fdd„	Zedd„ ƒZedd„ ƒZed	d
„ ƒZdd„ Z	dd„ Z
edd„ ƒZedd„ ƒZd!dd„Zedd„ ƒZedd„ ƒZdd„ Zdd„ Z‡  ZS )"r¾   ay  
    Args:
        model (:doc:`uproot.model.Model` or :doc:`uproot.containers.AsContainer`): The
            full Uproot deserialization model for the data.
        members (list of (str, :doc:`uproot.interpretation.Interpretation`) tuples): The
            name and fixed-width interpretation for each member of the objects.
        original (None, :doc:`uproot.model.Model`, or :doc:`uproot.containers.AsContainer`): If
            this interpretation is derived from
            :ref:`uproot.interpretation.objects.AsObjects.simplify`, this is a
            reminder of the original
            :ref:`uproot.interpretation.objects.AsObjects.model`.

    Interpretation for an array (possibly
    :doc:`uproot.interpretation.jagged.AsJagged`) of fixed-size objects. Since
    the objects have a fixed number of fields with a fixed number of bytes each,
    the whole array (or :ref:`uproot.interpretation.jagged.AsJagged.content`)
    can be interpreted in one vectorized array-cast. Therefore, this
    interpretation is faster than :doc:`uproot.interpretation.objects.AsObjects`
    *when it is possible*.

    Unlike :doc:`uproot.interpretation.numerical.AsDtype` with a
    `structured array <https://numpy.org/doc/stable/user/basics.rec.html>`__,
    the objects in the final array have the methods required by its ``model``.
    If the ``library`` is :doc:`uproot.interpretation.library.NumPy`, these
    are instantiated as Python objects (slow); if
    :doc:`uproot.interpretation.library.Awkward`, they are behaviors passed to
    the Awkward Array's local
    `behavior <https://awkward-array.readthedocs.io/en/latest/ak.behavior.html>`__.
    Nc           	        s®   d}t t|ƒƒD ]}|| dkr q&qt |t|ƒƒD ]B}|| \}}|d urT|sTd}|d u r`|slt|ƒdkr4d}||= q4|| _||d … | _|| _|| _tƒ  t| jƒ¡ d S )NF)NNTrX   )	rŒ   re   r   rÉ   Ú	_originalÚ_all_headers_prependedÚsuperr   r¿   )	r   r   rÀ   r«   Úall_headers_prependedZfirst_value_locr•   rÂ   Úvalue©Ú	__class__r   r   r   Ì  s     zAsStridedObjects.__init__c                 C  s   | j S r   r   r   r   r   r   r   á  s    zAsStridedObjects.modelc                 C  s   | j S )z§
        The name (str) and fixed-width
        :doc:`uproot.interpretation.Interpretation` for each member of the
        objects as a list of 2-tuple pairs.
        )rÉ   r   r   r   r   rÀ   é  s    zAsStridedObjects.membersc                 C  s   | j S )a  
        If not None, this was the original
        :ref:`uproot.interpretation.objects.AsObjects.model` from an
        :doc:`uproot.interpretation.objects.AsObjects` that was simplified
        into this :doc:`uproot.interpretation.objects.AsStridedObjects`.
        )rÎ   r   r   r   r   r«   ò  s    zAsStridedObjects.originalc                 C  s2   | j rd| jj› d| j › d�S d| jj› d�S d S )NzAsStridedObjects(ú, r   )r´   r   r   r   r   r   r   r   ü  s    zAsStridedObjects.__repr__c                 C  s   t |tƒo| j|jkS r   )r   r¾   r   r   r   r   r   r     s    zAsStridedObjects.__eq__c                 C  s
   t  t¡S r   r-   r   r   r   r   r1     s    zAsStridedObjects.numpy_dtypec                 C  s   | j S r   )rÏ   r   r   r   r   rÑ   	  s    z&AsStridedObjects.all_headers_prependedr9   Fr   c                 C  sd   |   |||||¡}tj ¡ }tj | jj¡d }t||| j	||ƒ}	t
| jƒD ]}
|j |	|
¡}	qL|	S r6   )r:   r    rZ   r[   r   r8   r   r   rÈ   rÉ   Úreversedr´   rÊ   ZRegularForm)r   r<   r=   r>   r?   r@   rA   r[   rÍ   r|   Údimr   r   r   r;     s    	
ÿ
zAsStridedObjects.awkward_formc                 C  s   t | ƒj› d| jj› d�S r2   )r   r   r   r   r   r   r   r5      s    zAsStridedObjects.cache_keyc                 C  s   t j | jj¡d S r6   )r    r   r8   r   r   r   r   r   r   r7   $  s    zAsStridedObjects.typenamec                 C  s
   t | |ƒS r   )ÚStridedObjectArray)r   rd   r   r   r   Ú_wrap_almost_finalized(  s    z'AsStridedObjects._wrap_almost_finalizedc	                 C  s4  | j ||||||||d� tjj | j¡\}	}
|d urœ|	j|d |d  krœ| jrœdd|d |d  |	j fgdd„ t|	j	 
¡ dd	„ d
�D ƒ }	t |	¡| _z| |	¡ dg|
¢R ¡}W nZ t�y } z@td|j› d|j› dt|ƒ› d| › d|jj› �
ƒ|‚W Y d }~n
d }~0 0 | j|||||||||d�	 |S )NrB   rX   r   z@headersÚu1c                 S  s    g | ]\}}|t |d  ƒf‘qS )r   )rb   )r#   rž   Úyr   r   r   Ú
<listcomp>J  s   ÿz1AsStridedObjects.basket_array.<locals>.<listcomp>c                 S  s   | d S ©NrX   r   )r$   r   r   r   Ú<lambda>L  ó    z/AsStridedObjects.basket_array.<locals>.<lambda>)ÚkeyrW   zbasket z in tree/branch z  has the wrong number of bytes (z) for interpretation z	
in file rI   )rK   r    rL   r²   Z_dtype_shapeZ_from_dtypeÚitemsizerÑ   ÚsortedÚfieldsr(   r.   r/   Z	_to_dtypeÚviewr¶   Ú
ValueErrorr¨   Zobject_pathre   r<   Ú	file_pathrR   )r   rC   rD   rE   r   r=   rF   rG   rH   r/   ÚshaperJ   rh   r   r   r   rS   +  s`    øÿþýÿþþÿþÿü÷zAsStridedObjects.basket_array)N)Nr9   FFr   )r   r¹   rº   r»   r   r¼   r   rÀ   r«   r   r   r1   rÑ   r;   r5   r7   rÙ   rS   Ú__classcell__r   r   rÓ   r   r¾   ­  s4   


	

     ù


r¾   c                   @  s   e Zd ZdZdS )r°   z×
    Exception used to stop recursion over
    :ref:`uproot.model.Model.strided_interpretation` and
    :ref:`uproot.containers.AsContainer.strided_interpretation` as soon as a
    non-conforming type is found.
    N©r   r¹   rº   r»   r   r   r   r   r°   f  s   r°   c                   @  s   e Zd ZdZdS )r`   z�
    Exception used to stop recursion over
    :ref:`uproot.model.Model.read` as soon as a
    non-conforming type is found.
    Nré   r   r   r   r   r`   o  s   r`   c                   @  s$   e Zd ZdZdd„ Zedd„ ƒZdS )ÚCannotBeAwkwarda  
    Exception used to stop recursion over
    :ref:`uproot.interpretation.Interpretation.awkward_form`,
    :ref:`uproot.model.Model.awkward_form` and
    :ref:`uproot.containers.AsContainer.awkward_form` as soon as a
    non-conforming type is found.
    c                 C  s
   || _ d S r   ©Z_because)r   Úbecauser   r   r   r   €  s    zCannotBeAwkward.__init__c                 C  s   | j S r   rë   r   r   r   r   rì   ƒ  s    zCannotBeAwkward.becauseN)r   r¹   rº   r»   r   r¼   rì   r   r   r   r   rê   w  s   rê   c                   @  sˆ   e Zd ZdZdd„ Zdd„ Zedd„ ƒZedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )rP   aI  
    Args:
        model (:doc:`uproot.model.Model` or :doc:`uproot.containers.AsContainer`): The
            full Uproot deserialization model for the data.
        branch (:doc:`uproot.behaviors.TBranch.TBranch`): The ``TBranch`` from
            which the data are drawn.
        context (dict): Auxiliary data used in deserialization.
        byte_offsets (array of ``numpy.int32``): Index where each entry of the
            ``byte_content`` starts and stops.
        byte_content (array of ``numpy.uint8``): Raw but uncompressed data,
            directly from
            :ref:`uproot.interpretation.Interpretation.basket_array`.
        cursor_offset (int): Correction to the integer keys used in
            :ref:`uproot.source.cursor.Cursor.refs` for objects deserialized
            by reference (:doc:`uproot.deserialization.read_object_any`).

    Temporary array filled by
    :ref:`uproot.interpretation.objects.AsObjects.basket_array`, which will be
    turned into a NumPy, Awkward, or other array, depending on the specified
    :doc:`uproot.interpretation.library.Library`.
    c                 C  s4   || _ || _|| _|| _|| _|| _| jjj| _d S r   )	r   r   Ú_contextÚ_byte_offsetsÚ_byte_contentÚ_cursor_offsetr<   r”   Ú_detached_file)r   r   r   r=   rD   Úbyte_contentrF   r   r   r   r   Ÿ  s    zObjectArray.__init__c                 C  s6   d| j › d| j› d| j› d| j› d| j› d| j› d�S )NzObjectArray(rÕ   r   )r   r   rí   rî   rï   rð   r   r   r   r   r   ª  s    zObjectArray.__repr__c                 C  s   | j S r   r   r   r   r   r   r   ­  s    zObjectArray.modelc                 C  s   | j S )z@
        The ``TBranch`` from which the data are drawn.
        r   r   r   r   r   r   µ  s    zObjectArray.branchc                 C  s   | j S )z@
        Auxiliary data used in deserialization (dict).
        )rí   r   r   r   r   r=   ¼  s    zObjectArray.contextc                 C  s   | j S )zR
        Index where each entry of the ``byte_content`` starts and stops.
        )rî   r   r   r   r   rD   Ã  s    zObjectArray.byte_offsetsc                 C  s   | j S )z|
        Raw but uncompressed data, directly from
        :ref:`uproot.interpretation.Interpretation.basket_array`.
        )rï   r   r   r   r   rò   Ê  s    zObjectArray.byte_contentc                 C  s   | j S )zÇ
        Correction to the integer keys used in
        :ref:`uproot.source.cursor.Cursor.refs` for objects deserialized by
        reference (:doc:`uproot.deserialization.read_object_any`).
        )rð   r   r   r   r   rF   Ò  s    zObjectArray.cursor_offsetc                 C  s:   t jt| ƒt  t¡d�}tt| ƒƒD ]}| | ||< q$|S )zU
        Convert this ObjectArray into a NumPy ``dtype="O"`` (object) array.
        rˆ   )r.   r‹   re   r/   r0   rŒ   )r   rJ   r•   r   r   r   rQ   Û  s    zObjectArray.to_numpyc                 C  s   t | jƒd S rÝ   )re   rî   r   r   r   r   Ú__len__ä  s    zObjectArray.__len__c                 C  sÀ   t j |¡r„| j| }| j|d  }| j||… }t jjj | j	j
j|¡}t jjjd|| j  d�}| j ||| j| j	j
| j| j	¡S t|tƒr°t| j| j	| j| j| | j| jƒS tt|ƒƒ‚d S )NrX   r   r‰   )r    rœ   Zisintrî   rï   r�   rŽ   r�   r�   r   r<   r‘   r’   rð   r   r“   rí   rñ   r   ÚslicerP   ÚNotImplementedErrorr   )r   ÚwhereÚ
byte_startÚ	byte_stoprC   rŽ   r‘   r   r   r   Ú__getitem__ç  s4    
ÿú	
ú
zObjectArray.__getitem__c              	   c  s˜   | j jj}| j}| j j}| j}| j }| jd }| jdd … D ]V}| j||… }tjjj	 
||¡}	tjjjd| j d�}
| j |	|
||||¡V  |}q<d S )Nr   rX   r‰   )r   r<   r�   rí   rñ   rî   rï   r    rŽ   r�   r�   r‘   r’   rð   r   r“   )r   r�   r=   r<   Zselffiler   r÷   rø   rC   rŽ   r‘   r   r   r   Ú__iter__  s    

zObjectArray.__iter__N)r   r¹   rº   r»   r   r   r¼   r   r   r=   rD   rò   rF   rQ   ró   rù   rú   r   r   r   r   rP   ˆ  s&   





	rP   c                 C  sf   |j  ¡ }|jD ]P\}}|}t| ƒdkr4| d | }t|tƒrRt|||ƒ|j|< q|| |j|< q|S )Nr   r½   )r   r‹   rÉ   re   r   r¾   Ú_strided_object)rV   rL   rC   rÁ   rk   rÂ   Úpr   r   r   rû     s    

rû   c                   @  sd   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZedd	„ ƒZd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )rØ   a÷  
    Args:
        interpretation (:doc:`uproot.interpretation.objects.AsStridedObjects`): The
            interpretation that produced this array.
        array (array): Underlying array object, which may be NumPy or another
            temporary array.

    Temporary array filled by
    :ref:`uproot.interpretation.objects.AsStridedObjects.basket_array`, which
    will be turned into a NumPy, Awkward, or other array, depending on the
    specified :doc:`uproot.interpretation.library.Library`.
    c                 C  s&   || _ || _t| jtjƒs"tdƒ‚d S )NzEnon-numpy temporary arrays require changes in library interpretations)Ú_interpretationÚ_arrayr   r.   r¤   rõ   )r   rL   rd   r   r   r   r   0  s    ÿzStridedObjectArray.__init__c                 C  s   | j S )z>
        The interpretation that produced this array.
        )rý   r   r   r   r   rL   8  s    z!StridedObjectArray.interpretationc                 C  s   | j S )zY
        Underlying array object, which may be NumPy or another temporary array.
        )rþ   r   r   r   r   rd   ?  s    zStridedObjectArray.arrayc                 C  s(   | j jt| ƒg| jj¢R ks J ‚| j jS r   )rþ   rç   re   rý   r´   r   r   r   r   rç   F  s     zStridedObjectArray.shapec                 C  s   d| j › d| j› d�S )NzStridedObjectArray(rÕ   r   )rý   rþ   r   r   r   r   r   K  s    zStridedObjectArray.__repr__c                 C  s
   t | jƒS r   )re   rþ   r   r   r   r   ró   N  s    zStridedObjectArray.__len__c                 C  s2   | j | }t|tƒr"td| j|ƒS t| j|ƒS d S ©Nr   ©rþ   r   Útuplerû   rý   rØ   )r   rö   rÁ   r   r   r   rù   Q  s    

zStridedObjectArray.__getitem__c                 c  s:   | j D ].}t|tƒr&td| j|ƒV  qt| j|ƒV  qd S rÿ   r   )r   rž   r   r   r   rú   X  s    

zStridedObjectArray.__iter__c                 c  s.   t  | j¡D ]\}}|td| j|ƒfV  qd S rÿ   )r.   Úndenumeraterþ   rû   rý   )r   r•   rž   r   r   r   r  _  s    zStridedObjectArray.ndenumerateN)r   r¹   rº   r»   r   r¼   rL   rd   rç   r   ró   rù   rú   r  r   r   r   r   rØ   "  s   


rØ   )r»   Ú
__future__r   r®   rƒ   r	   r.   r    Zuproot._awkwardforthrL   ZInterpretationr   r¿   rÈ   r²   r³   r¾   ra   r°   r`   rê   rP   rû   rØ   r   r   r   r   Ú<module>   s.       g :	 