a
    zn„f
ü  ã                   @  sæ  d Z ddlmZ ddlZddlZddlmZmZmZm	Z	m
Z
 ddlZddlZddlZe d¡Ze e¡Zdd„ Zdd	„ Zd;dd„Zdd„ Zdd„ ZG dd„ dƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd „ d eƒZG d!d"„ d"eƒZ G d#d$„ d$eƒZ!G d%d&„ d&eƒZ"G d'd(„ d(eƒZ#d)d*„ Z$G d+d,„ d,eƒZ%G d-d.„ d.ƒZ&G d/d0„ d0e&eƒZ'G d1d2„ d2e&eƒZ(G d3d4„ d4e&eƒZ)G d5d6„ d6e&eƒZ*G d7d8„ d8e&e	ƒZ+G d9d:„ d:e&eƒZ,dS )<z§
This module interpretations and models for standard containers, such as
``std::vector`` and simple arrays.

See :doc:`uproot.interpretation` and :doc:`uproot.model`.
é    )ÚannotationsN)ÚKeysViewÚMappingÚSequenceÚSetÚ
ValuesViewz>Ic                 C  sH   t | tjƒr"tjjj| j| jf S t | t	ƒr>tj
 | j¡d S | jS d S )Nr   )Ú
isinstanceÚnumpyÚdtypeÚuprootÚinterpretationÚ	numericalZ _dtype_kind_itemsize_to_typenameÚkindÚitemsizeÚtypeÚmodelÚclassname_decodeÚ__name__Útypename)Úcontent© r   úT/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/containers.pyÚ_content_typename   s    
ÿ
r   c                 C  sJ   t | tjƒr0tjjj| j }|› | j› | j	› �S t | t
ƒr@| jS | jS d S ©N)r   r	   r
   r   r   r   Z_numpy_byteorder_to_cache_keyÚ	byteorderr   r   r   r   Ú	cache_key)r   Zbor   r   r   Ú_content_cache_key#   s    ÿ
r   Tc	              
   C  s`  t j |¡}	t| tjƒrØt jj | ¡}
|	d urB|
d u rBt jj	 
¡ ‚|	d urÈt j |¡}t jjd|› �dt jj|
 d|› �dœd�}|j d|› dt jj|
 › d�¡ |j d|
› d	|› d
�¡ |	 |¡ | ||| |¡S tj|td�}|	d urô|	j}t|ƒD ]Z}|	d u�r|	 |¡ t| tƒ�r>| j|||||||d�||< qü|  ||||||¡||< qü|S d S )NÚnodeÚ
NumpyArray)ÚclassÚ	primitiveÚform_key©Zform_detailsúoutput nodez-data Ú
z	stream #!z-> nodeú-data
©r
   ©Úheader)r   Ú_awkwardforthÚget_forth_objr   r	   r
   Zdtype_to_structÚgetr   ÚobjectsÚCannotBeForthÚget_first_key_numberÚNodeZstruct_to_dtype_nameÚheader_codeÚappendÚpre_codeÚadd_nodeÚarrayÚemptyÚ_stl_object_typeZactive_nodeÚrangeÚset_active_nodeÚAsContainerÚread)r   ÚlengthÚchunkÚcursorÚcontextÚfileÚselffileÚparentr(   Ú	forth_objÚsymbolÚkeyÚforth_stashÚvaluesZoriginal_modelÚir   r   r   Ú_read_nested/   sZ    
ýþ	ÿ


ù
ú
	rH   c                 C  s   t | tƒrt| ƒS t| ƒS d S r   )r   ÚstrÚrepr)Úvaluer   r   r   Ú	_tostringp   s    
rL   c                 C  sÔ  t |ƒ}t |ƒ}g g d|d df\}}}	}
}|	|
kr<d}�q| |	ƒ|	|d krRdnd }|	d7 }	|	|
krldnd}|| t |ƒ | |krŒ�q| |¡ |t |ƒ7 }|	|
kr²d}�q| |
ƒ|
|d krÈdnd }|
d8 }
|	|
krâdnd}|| t |ƒ | |k�r�q| d|¡ |t |ƒ7 }q,|dk�r0|| S |�rR|d |¡ d |¡ | S t |ƒt |ƒ  k�rrdk�rŒn n|| dƒ› d� | S t |ƒdk�r°|d |¡ d	 | S |d |¡ d
 d |¡ | S d S )Nr   é   FTÚ ú, é   z, ...z...z..., )Úlenr1   ÚinsertÚjoin)Útostringr;   ZlbracketZrbracketÚlimitZleftlenZrightlenÚleftÚrightrG   ÚjÚdoneÚxZdotslenÚyr   r   r   Ú_str_with_ellipsisw   s@    

$r\   c                   @  sn   e Zd ZdZedd„ ƒZedd„ ƒZdd„ Zddd„Zedd„ ƒZ	e	j
dd„ ƒZ	ddd„Zdd„ Zdd„ ZdS )r9   a  
    Abstract class for all descriptions of data as containers, such as
    ``std::vector``.

    Note that these are not :doc:`uproot.interpretation.Interpretation`
    objects, since they are recursively nestable and have a ``read``
    instance method like :doc:`uproot.model.Model`'s ``read`` classmethod.

    A nested tree of :doc:`uproot.containers.AsContainer` instances and
    :doc:`uproot.model.Model` class objects may be the ``model`` argument
    of a :doc:`uproot.interpretation.objects.AsObjects`.
    c                 C  s   t ‚dS )zp
        String that uniquely specifies this container, to use as part of
        an array's cache key.
        N©ÚAssertionError©Úselfr   r   r   r   ­   s    zAsContainer.cache_keyc                 C  s   t ‚dS )z·
        String that describes this container as a C++ type.

        This type might not exactly correspond to the type in C++, but it would
        have equivalent meaning.
        Nr]   r_   r   r   r   r   µ   s    zAsContainer.typenamec                 C  s   t ‚dS )a°  
        Args:
            file (:doc:`uproot.reading.CommonFileMethods`): The file associated
                with this interpretation's ``TBranch``.
            context (dict): Context for the Form-generation; defaults are
                the remaining arguments below.
            index_format (str): Format to use for indexes of the
                ``awkward.forms.Form``; may be ``"i32"``, ``"u32"``, or
                ``"i64"``.
            header (bool): If True, include header fields of each C++ class.
            tobject_header (bool): If True, include header fields of each ``TObject``
                base class.
            breadcrumbs (tuple of class objects): Used to check for recursion.
                Types that contain themselves cannot be Awkward Arrays because the
                depth of instances is unknown.

        The ``awkward.forms.Form`` to use to put objects of type type in an
        Awkward Array.
        Nr]   ©r`   r?   r>   r   r   r   Úawkward_form¿   s    zAsContainer.awkward_formFTr   Nc                 C  s   t jj | j¡‚dS )a­  
        Args:
            file (:doc:`uproot.reading.ReadOnlyFile`): File to use to generate
                :doc:`uproot.model.Model` classes from its
                :ref:`uproot.reading.ReadOnlyFile.streamers` and ``file_path``
                for error messages.
            header (bool): If True, assume the outermost object has a header.
            tobject_header (bool): If True, assume that ``TObjects`` have headers.
            breadcrumbs (tuple of class objects): Used to check for recursion.
                Types that contain themselves cannot be strided because the
                depth of instances is unknown.
            original (None, :doc:`uproot.model.Model`, or :doc:`uproot.containers.Container`): The
                original, non-strided model or container.

        Returns a list of (str, ``numpy.dtype``) pairs to build a
        :doc:`uproot.interpretation.objects.AsStridedObjects` interpretation.
        N)r   r   r,   ZCannotBeStridedr   )r`   r?   r(   Ztobject_headerZbreadcrumbsÚoriginalr   r   r   Ústrided_interpretationÕ   s    z"AsContainer.strided_interpretationc                 C  s   | j S )z>
        If True, assume this container has a header.
        )Ú_headerr_   r   r   r   r(   ë   s    zAsContainer.headerc                 C  s0   |du s|du r|| _ ntt| ƒj› d�ƒ‚d S )NTFz.header must be True or False)re   Ú	TypeErrorr   r   )r`   rK   r   r   r   r(   ò   s    c                 C  s   t ‚dS )añ  
        Args:
            chunk (:doc:`uproot.source.chunk.Chunk`): Buffer of contiguous data
                from the file :doc:`uproot.source.chunk.Source`.
            cursor (:doc:`uproot.source.cursor.Cursor`): Current position in
                that ``chunk``.
            context (dict): Auxiliary data used in deserialization.
            file (:doc:`uproot.reading.ReadOnlyFile`): An open file object,
                capable of generating new :doc:`uproot.model.Model` classes
                from its :ref:`uproot.reading.ReadOnlyFile.streamers`.
            selffile (:doc:`uproot.reading.CommonFileMethods`): A possibly
                :doc:`uproot.reading.DetachedFile` associated with this object.
            parent (None or calling object): The previous ``read`` in the
                recursive descent.
            header (bool): If True, enable the container's
                :ref:`uproot.containers.AsContainer.header`.

        Read one object as part of a recursive descent.
        Nr]   ©r`   r<   r=   r>   r?   r@   rA   r(   r   r   r   r:   ù   s    zAsContainer.readc                 C  s   t ‚d S r   r]   ©r`   Úotherr   r   r   Ú__eq__  s    zAsContainer.__eq__c                 C  s
   | |k S r   r   rh   r   r   r   Ú__ne__  s    zAsContainer.__ne__)FTr   N)T)r   Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   rb   rd   r(   Úsetterr:   rj   rk   r   r   r   r   r9   Ÿ   s   

	 ÿ



r9   c                   @  sX   e Zd ZdZddd„Zedd„ ƒZdd„ Zed	d
„ ƒZedd„ ƒZ	dd„ Z
ddd„ZdS )Ú	AsDynamica  
    Args:
        model (None, :doc:`uproot.model.Model`, or :doc:`uproot.containers.Container`): Optional
            description of the data, used in
            :ref:`uproot.containers.AsDynamic.awkward_form` but ignored in
            :ref:`uproot.containers.AsDynamic.read`.

    A :doc:`uproot.containers.AsContainer` for one object whose class may
    not be known before reading.

    The byte-stream consists of a class name followed by instance data. Only
    known use: in ``TBranchObject`` branches.
    Nc                 C  s
   || _ d S r   ©Ú_model©r`   r   r   r   r   Ú__init__%  s    zAsDynamic.__init__c                 C  s   | j S )z³
        Optional description of the data, used in
        :ref:`uproot.containers.AsDynamic.awkward_form` but ignored in
        :ref:`uproot.containers.AsDynamic.read`.
        rr   r_   r   r   r   r   (  s    zAsDynamic.modelc                 C  sD   | j d u rd}n(t| j tƒr*d| j j }ndt| j ƒ }d|› d�S )NrN   zmodel=ú
AsDynamic(ú))rs   r   r   r   rJ   rt   r   r   r   Ú__repr__1  s    
zAsDynamic.__repr__c                 C  s$   | j d u rdS dt| j ƒ› d�S d S )NzAsDynamic(None)rv   rw   )rs   r   r_   r   r   r   r   :  s    
zAsDynamic.cache_keyc                 C  s&   | j d u rdS tj | j j¡d S d S )Núvoid*r   )rs   r   r   r   r   r_   r   r   r   r   A  s    
zAsDynamic.typenamec                 C  s:   t j ¡  | jd u r$t jj d¡‚nt j | j||¡S d S )Nzdynamic type)	r   ÚextrasÚawkwardrs   r   r,   ÚCannotBeAwkwardÚ_utilrb   ra   r   r   r   rb   H  s    

zAsDynamic.awkward_formTc           
      C  sP   t j |¡d urt jj ¡ ‚| ||¡}| d¡ | |¡}	|	 	||||||¡S )NrM   )
r   r)   r*   r   r,   r-   ÚstringÚskipZclass_namedr:   )
r`   r<   r=   r>   r?   r@   rA   r(   Ú	classnameÚclsr   r   r   r:   O  s    

zAsDynamic.read)N)T)r   rl   rm   rn   ru   ro   r   rx   r   r   rb   r:   r   r   r   r   rq     s   

	

rq   c                   @  sZ   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZed
d„ ƒZ	dd„ Z
ddd„Zdd„ ZdS )ÚAsFIXMEaŽ  
    Args:
        message (str): Required string, prefixes the error message.

    A :doc:`uproot.containers.AsContainer` for types that are known to be
    unimplemented. The name is intended to be conspicuous, so that such cases
    may be more easily fixed.

    :ref:`uproot.containers.AsFIXME.read` raises a
    :doc:`uproot.deserialization.DeserializationError` asking for a bug-report.
    c                 C  s
   || _ d S r   ©Úmessage)r`   r„   r   r   r   ru   f  s    zAsFIXME.__init__c                 C  s   t t| jfƒS r   )Úhashr‚   r„   r_   r   r   r   Ú__hash__i  s    zAsFIXME.__hash__c                 C  s   d| j ›d�S ©NzAsFIXME(rw   rƒ   r_   r   r   r   rx   l  s    zAsFIXME.__repr__c                 C  s   d| j ›d�S r‡   rƒ   r_   r   r   r   r   o  s    zAsFIXME.cache_keyc                 C  s   dS )NÚunknownr   r_   r   r   r   r   s  s    zAsFIXME.typenamec                 C  s   t jj | j¡‚d S r   )r   r   r,   r|   r„   ra   r   r   r   rb   w  s    zAsFIXME.awkward_formTc                 C  s   t j | jd d d d d ¡‚d S )Nz; please file a bug report!)r   ÚdeserializationZDeserializationErrorr„   rg   r   r   r   r:   z  s    ÿzAsFIXME.readc                 C  s   t |tƒr| j|jkS dS d S ©NF)r   r‚   r„   rh   r   r   r   rj     s    
zAsFIXME.__eq__N)T)r   rl   rm   rn   ru   r†   rx   ro   r   r   rb   r:   rj   r   r   r   r   r‚   Y  s   


r‚   c                   @  sh   e Zd ZdZddd„Zedd„ ƒZdd	„ Zd
d„ Zedd„ ƒZ	edd„ ƒZ
dd„ Zddd„Zdd„ ZdS )ÚAsStringa2  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        length_bytes ("1-5" or "4"): Method used to determine the length of
            a string: "1-5" means one byte if the length is less than 256,
            otherwise the true length is in the next four bytes; "4" means
            always four bytes.
        typename (None or str): If None, construct a plausible C++ typename.
            Otherwise, take the suggestion as given.

    A :doc:`uproot.containers.AsContainer` for strings nested withing other
    objects.

    This is not an :doc:`uproot.interpretation.Interpretation`; it *must* be
    nested, at least within :doc:`uproot.interpretation.objects.AsObjects`.

    Note that the :doc:`uproot.interpretation.strings.AsStrings` class is
    for a ``TBranch`` that contains only strings.

    (:ref:`uproot.interpretation.objects.AsObjects.simplify` converts an
    :doc:`uproot.interpretation.objects.AsObjects` of
    :doc:`uproot.containers.AsString` into a
    :doc:`uproot.interpretation.strings.AsStrings`.)
    ú1-5Nc                 C  s(   || _ |dv r|| _ntdƒ‚|| _d S )N)rŒ   Ú4z!length_bytes must be '1-5' or '4')r(   Ú_length_bytesÚ
ValueErrorÚ	_typename)r`   r(   Úlength_bytesr   r   r   r   ru      s
    zAsString.__init__c                 C  s   | j S )zÙ
        Method used to determine the length of a string: "1-5" means one byte
        if the length is less than 256, otherwise the true length is in the
        next four bytes; "4" means always four bytes.
        )rŽ   r_   r   r   r   r‘   ¨  s    zAsString.length_bytesc                 C  s   t t| j| jfƒS r   )r…   r‹   re   rŽ   r_   r   r   r   r†   ±  s    zAsString.__hash__c                 C  s8   t | jƒg}| jdkr(| d| j›�¡ d d |¡¡S )NrŒ   zlength_bytes=zAsString({})rO   )rJ   re   rŽ   r1   ÚformatrS   )r`   Úargsr   r   r   rx   ´  s    
zAsString.__repr__c                 C  s   d| j › d| j›d�S )Nz	AsString(ú,rw   )re   rŽ   r_   r   r   r   r   º  s    zAsString.cache_keyc                 C  s   | j d u rdS | j S d S )Nzstd::string)r�   r_   r   r   r   r   ¾  s    
zAsString.typenamec                 C  s4   t j ¡ }|jj|d |jjdddid�ddid�S )NÚindex_formatÚuint8Ú	__array__Úchar©Ú
parametersr~   )r   rz   r{   ÚformsÚListOffsetFormZ	NumpyForm©r`   r?   r>   r{   r   r   r   rb   Å  s    
ýzAsString.awkward_formTc              
   C  sÞ  t j |¡}|r~t j ||t j d¡¡}t j |¡}	|	d }
t jjd|	› �ddddg dd	id|
› �d
œddid|	› �dœd�}| jrÔ|rÔ| ¡ }t j	 
|||¡\}}}|d urÔ|j|j }|dkrÔ|j |› d�¡ | jdk�r| ||¡}|d u�rn|j d|	› d|
› d�¡ n\| jdk�r`| |t|¡}| |||¡}|d u�rn|j d|	› d|
› d�¡ ntt| jƒƒ‚| j�r˜|�r˜t j	 ||||| j||j¡ |d u�rÚ|j d|	› d|
› d�¡ |j d|	› d�¡ | |¡ |S )Nr~   rM   r   ÚListOffsetArrayÚi64r   r–   r—   r˜   )r   r    Úinner_shaperš   r!   ©r   Úoffsetsr   rš   r!   r"   r   ú stream skip
rŒ   zCstream !B-> stack dup 255 = if drop stream !I-> stack then dup nodez$-offsets +<- stack stream #!B-> noder%   r�   zstream !I-> stack dup nodez#-offsets +<- stack stream #B-> noder#   z-offsets int64
output nodez-data uint8
ú0 nodeú-offsets <- stack
)r   r)   r*   Úadd_to_pathÚSpecialPathItemr.   r/   re   Úcopyr‰   Únumbytes_versionÚ_indexr2   r1   rŽ   r~   ÚfieldÚ_stl_container_sizeZstring_with_lengthr^   rJ   Únumbytes_checkr   Ú	file_pathr0   Ú	init_coder3   )r`   r<   r=   r>   r?   r@   rA   r(   rB   Úoffsets_numZdata_numrE   Ústart_cursorÚ	num_bytesÚinstance_versionÚis_memberwiseZcursor_jumpÚoutr;   r   r   r   r:   Í  s~    ÿûõþ
ü
ÿ
ÿù

ÿ
zAsString.readc                 C  s"   t |tƒo | j|jko | j|jkS r   )r   r‹   r(   r‘   rh   r   r   r   rj     s
    

ÿ
ýzAsString.__eq__)rŒ   N)T)r   rl   rm   rn   ru   ro   r‘   r†   rx   r   r   rb   r:   rj   r   r   r   r   r‹   †  s   




Lr‹   c                   @  sh   e Zd ZdZddd„Zedd„ ƒZdd„ Zd	d
„ Zedd„ ƒZ	edd„ ƒZ
dd„ Zddd„Zdd„ ZdS )Ú	AsPointera)  
    Args:
        pointee (None, :doc:`uproot.model.Model`, or :doc:`uproot.containers.Container`): Optional
            description of the data, used in
            :ref:`uproot.containers.AsPointer.awkward_form` but ignored in
            :ref:`uproot.containers.AsPointer.read`.

    A :doc:`uproot.containers.AsContainer` for an object referred to by
    pointer, meaning that it could be None (``nullptr``) or identical to
    an already-read object.

    The deserialization procedure calls
    :doc:`uproot.deserialization.read_object_any`.
    Nc                 C  s
   || _ d S r   ©Ú_pointee©r`   Úpointeer   r   r   ru   1  s    zAsPointer.__init__c                 C  s   | j S )z³
        Optional description of the data, used in
        :ref:`uproot.containers.AsPointer.awkward_form` but ignored in
        :ref:`uproot.containers.AsPointer.read`.
        r·   r_   r   r   r   rº   4  s    zAsPointer.pointeec                 C  s   t t| jfƒS r   )r…   r¶   r¸   r_   r   r   r   r†   =  s    zAsPointer.__hash__c                 C  s<   | j d u rd}n t| j tƒr&| j j}n
t| j ƒ}d|› d�S )NrN   ú
AsPointer(rw   )r¸   r   r   r   rJ   r¹   r   r   r   rx   @  s    


zAsPointer.__repr__c                 C  s$   | j d u rdS dt| j ƒ› d�S d S )NzAsPointer(None)r»   rw   )r¸   r   r_   r   r   r   r   I  s    
zAsPointer.cache_keyc                 C  s    | j d u rdS t| j ƒd S d S )Nry   Ú*)r¸   r   r_   r   r   r   r   P  s    
zAsPointer.typenamec                 C  s   t jj d¡‚d S )Nzarbitrary pointer)r   r   r,   r|   ra   r   r   r   rb   W  s    zAsPointer.awkward_formTc                 C  s   t j ||||||¡S r   )r   r‰   Zread_object_anyrg   r   r   r   r:   Z  s    ÿzAsPointer.readc                 C  s   t |tƒr| j|jkS dS d S rŠ   )r   r¶   r¸   rh   r   r   r   rj   a  s    
zAsPointer.__eq__)N)T)r   rl   rm   rn   ru   ro   rº   r†   rx   r   r   rb   r:   rj   r   r   r   r   r¶   !  s   

	


r¶   c                   @  sp   e Zd ZdZddd„Zedd„ ƒZedd„ ƒZed	d
„ ƒZdd„ Z	edd„ ƒZ
edd„ ƒZdd„ Zddd„ZdS )ÚAsArraya   
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        speedbump (bool): If True, one byte must be skipped before reading the
            data.
        values (:doc:`uproot.model.Model`, :doc:`uproot.containers.Container`, or ``numpy.dtype``): Data
            type for data nested in the array.
        inner_shape (Optional[Tuple[int]]): Shape not counting first axis, if any

    A :doc:`uproot.containers.AsContainer` for simple arrays (not
    ``std::vector``).
    r   c                 C  s4   || _ || _|| _|| _t|tjƒr0|r0tdƒ‚d S )Nz6Logic error: the dtype should have contained the shape)re   Ú
_speedbumpÚ_valuesÚ_inner_shaper   r	   r
   ÚRuntimeError)r`   r(   Ú	speedbumprF   r    r   r   r   ru   v  s    zAsArray.__init__c                 C  s   | j S )zL
        If True, one byte must be skipped before reading the data.
        )r¾   r_   r   r   r   rÂ   ~  s    zAsArray.speedbumpc                 C  s   | j S )z¥
        Data type for data nested in the array. May be a
        :doc:`uproot.model.Model`, :doc:`uproot.containers.Container`, or
        ``numpy.dtype``.
        ©r¿   r_   r   r   r   rF   …  s    zAsArray.valuesc                 C  s   | j S )zF
        The shape of possible extra dimensions in this array
        )rÀ   r_   r   r   r   r    Ž  s    zAsArray.inner_shapec              	   C  sD   t | jtƒr| jj}n
t| jƒ}d| j› d| j› d|› d| j› d�	S )NúAsArray(rO   rw   )r   r¿   r   r   rJ   r(   rÂ   r    ©r`   rF   r   r   r   rx   •  s    

zAsArray.__repr__c              	   C  s*   d| j › d| j› dt| jƒ› d| j› d�	S )NrÄ   r”   rw   )r(   rÂ   r   r¿   r    r_   r   r   r   r   œ  s    zAsArray.cache_keyc                 C  s(   d  dd„ | jD ƒ¡}t| jƒd | S )NrN   c                 s  s   | ]}d |› d�V  qdS )ú[ú]Nr   )Ú.0Údr   r   r   Ú	<genexpr>¢  ó    z#AsArray.typename.<locals>.<genexpr>z[])rS   r    r   r¿   )r`   Úshaper   r   r   r      s    zAsArray.typenamec                 C  sL   t j ¡ }t j | j||¡}t| jƒD ]}|j 	||¡}q&|j 
|d |¡S )Nr•   )r   rz   r{   r}   rb   r¿   Úreversedr    r›   ZRegularFormrœ   )r`   r?   r>   r{   Zvalues_formÚdimr   r   r   rb   ¥  s
    
zAsArray.awkward_formTc                 C  s  t j |¡}|d ur”t j ||t j d¡¡}t j |¡}	t| jƒdkrjddd| jd dœi d|	› �dœ}
nddi d|	› �d	œ}
t jjd|	› �|
d
�}| j	�rœ|�rœ| 
¡ }t j |||¡\}}}|ràtdt| ƒj› d|j› �ƒ‚|d u�r|j|j }|dk�r|j |› d�¡ t| jtjƒ�rV| |j|j| ||¡}| | j¡jdg| j¢R Ž S |d u�rä|j d|	› d�¡ |j d|	› d�¡ |j d¡ t| jƒdk�rÆ|j d| jd › d|	› d�¡ n|j d|	› d�¡ | |¡ g }|  |¡|k �rR|d u�r| !|¡ | | j "||t j ||t j d¡¡|||¡¡ |d u�rè| #¡  �qè| j	�r||�r|t j $||||| j%||j¡ t j& '|¡jdg| j¢R Ž S �nz| j(�rÄ|d u�rº|j d¡ | )d¡ t| jtjƒ�r | *|j||¡}| | j¡jdg| j¢R Ž S |d u�rŽ|j d|	› d�¡ |j d|	› d�¡ |j d¡ t| jƒdk�rp|j d| jd › d|	› d�¡ n|j d|	› d�¡ | |¡ g }|j|j+k �rú|d u�r´| !|¡ | | j "||t j ||t j d¡¡|||¡¡ |d u�r’| #¡  �q’t j& '|¡jdg| j¢R Ž S d S )Nr4   r   rž   rŸ   ZRegularArray)r   Úsizer   r¡   ©r   r¢   rš   r!   r"   úmemberwise serialization of z	
in file r£   éÿÿÿÿr#   ú-offsets int64
r¤   r¥   zC0 bytestops I-> stack 
begin
dup stream pos <>
while
swap 1 + swap
zrepeat
swap z / nodez-offsets +<- stack drop
zrepeat
swap nodeÚitemz1 stream skip
rM   ),r   r)   r*   r¦   r§   r.   rQ   r    r/   re   r¨   r‰   r©   ÚNotImplementedErrorr   r   r®   rª   r2   r1   r   r¿   r	   r
   r+   ÚindexÚviewZreshaper0   r¯   Ú	post_coder3   ZdisplacementÚpush_active_noder:   Úpop_active_noder­   r   r}   Zobjectarray1dr¾   r   Ú	remainderÚstop)r`   r<   r=   r>   r?   r@   rA   r(   rB   r°   Z	temp_formrE   r±   r²   r³   r´   Z	temp_jumprÛ   rµ   r   r   r   r:   ¬  s   ÿþøüþüÿÿ

ÿ

ÿ
ÿÿÿ
ÿ



ýöÿ
ù	 



ÿ
ÿÿÿ
ÿ



ýöÿ
zAsArray.readN)r   )T)r   rl   rm   rn   ru   ro   rÂ   rF   r    rx   r   r   rb   r:   r   r   r   r   r½   h  s   





r½   c                   @  sR   e Zd ZdZdd„ Zdd„ Zdd„ Zedd	„ ƒZi Z	d
d„ Z
ddd„Zdd„ ZdS )ÚAsVectorLikea  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        values (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for data nested in the container.

    Superclass of :doc:`uproot.containers.AsRVec`,  :doc:`uproot.containers.AsVector`,
    and :doc:`uproot.containers.AsSet`, which have the same ROOT serialization, but
    represent different runtime classes. The purpose of this superclass is just to
    consolidate implementations.
    c                 C  sn   || _ t| tjjƒr$t tj¡| _nFt|t	ƒr6|| _n4t|t
ƒr^t|tjjtjjfƒr^|| _nt |¡| _d S r   )r(   r   r   Ú
containersÚAsBitSetr	   r
   Zbool_Ú_itemsr9   r   Ú
issubclassr   ÚModelÚDispatchByVersion)r`   r(   rF   r   r   r   ru   a  s    
ÿzAsVectorLike.__init__c                 C  s   t t| ƒ| j| jfƒS r   )r…   r   re   rà   r_   r   r   r   r†   n  s    zAsVectorLike.__hash__c                 C  s>   t | jtƒr| jj}n
t| jƒ}t| ƒj› d| j› d|› d�S )Nú(rO   rw   )r   rà   r   r   rJ   re   rÅ   r   r   r   rx   q  s    

zAsVectorLike.__repr__c                 C  s$   t | ƒj› d| j› dt| jƒ› d�S )Nrä   r”   rw   )r   r   re   r   rà   r_   r   r   r   r   x  s    "ÿzAsVectorLike.cache_keyc                 C  s0   t j ¡ }|jj|d t j | j||¡| jd�S )Nr•   r™   )	r   rz   r{   r›   rœ   r}   rb   rà   Ú_form_parametersr�   r   r   r   rb   €  s    
ýzAsVectorLike.awkward_formTc                 C  sì  t j |¡}|d ur`t j ||t j | j¡¡}t j |¡}	d|	› �}
t jj|
dd| j|
dœd�}| j	r¬|r¬| 
¡ }t j |||¡\}}}|d ur°|j |j|j › d�¡ nd}t| jƒ}|�ræ|d urÔt jj ¡ ‚| d¡�std	t| ƒj› d
|› d|j› �ƒ‚t| jt jjƒ�s6tdt| ƒj› d
|› d|j› �ƒ‚| d¡ | |t|¡}| j  |d¡}t!j"|t#d�}|dk�r´t$|ƒD ]&}| %||t&|dd�|||¡||< �q|t$t'|d j(ƒƒD ],}t$|ƒD ]}||  )|||||¡ �qÂ�q¶nÎ| |t|¡}|d u�rv|j* d|	› d�¡ |j+ d|	› d�¡ |j d|	› d�¡ t,| jt!j-ƒ�sb|j d¡ |j. d¡ | /|¡ | 0|¡ t1| j|||t j ||t j d¡¡|||ƒ}|d u�r´| 2¡  |  3|¡}| j	�rè|�rèt j 4||||| j5||j¡ |S )Nr   rž   rŸ   rÐ   r"   r£   FÚpairrÑ   rä   z)
    in file z/streamerless memberwise serialization of class é   Úmaxr&   r   )Úreadingr#   rÓ   r¤   r¥   ústream !I-> stack
 dup nodeú-offsets +<- stack
ú0 do
úloop
rÔ   )6r   r)   r*   r¦   r§   Ú_specialpathitem_namer.   r/   rå   re   r¨   r‰   r©   r2   r1   rª   r   rà   r   r,   r-   Ú
startswithrÕ   r   r   r®   rá   r   rã   r   r«   r¬   Ú	new_classr	   r5   r6   r7   r:   ÚdictrQ   Zmember_namesZread_member_nr0   r¯   r   r
   rØ   r3   rÙ   rH   rÚ   Ú_container_typer­   r   )r`   r<   r=   r>   r?   r@   rA   r(   rB   rD   Znode_keyrE   r±   r²   r³   r´   Z_value_typenamer;   r   rF   rG   Zmember_indexrµ   r   r   r   r:   ˆ  sÌ    ý
üþ

üÿ
ÿÿÿÿ


ú

ÿ

ÿ

ÿö

ù
zAsVectorLike.readc                 C  sz   t |t| ƒƒsdS | j|jkr"dS t | jtjƒrJt |jtjƒrJ| j|jkS t | jtjƒsrt |jtjƒsr| j|jkS dS d S rŠ   )r   r   r(   rà   r	   r
   rh   r   r   r   rj     s    ÿÿzAsVectorLike.__eq__N)T)r   rl   rm   rn   ru   r†   rx   ro   r   rå   rb   r:   rj   r   r   r   r   rÝ   T  s   

 
rÝ   c                   @  s8   e Zd ZdZdZedd„ ƒZedd„ ƒZedd„ ƒZd	S )
ÚAsRVeca.  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        values (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for data nested in the container.

    A :doc:`uproot.containers.AsContainer` for ``ROOT::VecOps::RVec``.
    ZRVecc                 C  s   dt | jƒ› d�S )NzRVec<ú>©r   rF   r_   r   r   r   r   0  s    zAsRVec.typenamec                 C  s   | j S ©z=
        Data type for data nested in the container.
        ©rà   r_   r   r   r   rF   4  s    zAsRVec.valuesc                 C  s   t S r   )ÚROOTRVecr_   r   r   r   rò   ;  s    zAsRVec._container_typeN©	r   rl   rm   rn   rî   ro   r   rF   rò   r   r   r   r   ró   $  s   	

ró   c                   @  s8   e Zd ZdZdZedd„ ƒZedd„ ƒZedd„ ƒZd	S )
ÚAsVectora'  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        values (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for data nested in the container.

    A :doc:`uproot.containers.AsContainer` for ``std::vector``.
    Zvectorc                 C  s   dt | jƒ› d�S )Nzstd::vector<rô   rõ   r_   r   r   r   r   L  s    zAsVector.typenamec                 C  s   | j S rö   r÷   r_   r   r   r   rF   P  s    zAsVector.valuesc                 C  s   t S r   )Ú	STLVectorr_   r   r   r   rò   W  s    zAsVector._container_typeNrù   r   r   r   r   rú   @  s   	

rú   c                   @  s8   e Zd ZdZdZedd„ ƒZedd„ ƒZedd„ ƒZd	S )
ÚAsLista$  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        values (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for data nested in the container.
    A :doc:`uproot.containers.AsContainer` for ``std::list``.
    Úlistc                 C  s   dt | jƒ› d�S )Nz
std::list<rô   rõ   r_   r   r   r   r   g  s    zAsList.typenamec                 C  s   | j S rö   r÷   r_   r   r   r   rF   k  s    zAsList.valuesc                 C  s   t S r   )ÚSTLListr_   r   r   r   rò   r  s    zAsList._container_typeNrù   r   r   r   r   rü   \  s   

rü   c                   @  s@   e Zd ZdZdZedd„ ƒZedd„ ƒZddiZedd	„ ƒZ	d
S )rß   a%  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        keys (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for data nested in the container.

    A :doc:`uproot.containers.AsContainer` for ``std::bitset``.
    Zbitsetc                 C  s   dt | jƒ› d�S )Nzstd::bitset<rô   ©r   Úkeysr_   r   r   r   r   ƒ  s    zAsBitSet.typenamec                 C  s   | j S rö   r÷   r_   r   r   r   r   ‡  s    zAsBitSet.keysr—   c                 C  s   t S r   )Ú	STLBitSetr_   r   r   r   rò   �  s    zAsBitSet._container_typeN)
r   rl   rm   rn   rî   ro   r   r   rå   rò   r   r   r   r   rß   w  s   	

rß   c                      sP   e Zd ZdZ‡ fdd„ZdZedd„ ƒZedd„ ƒZd	diZ	ed
d„ ƒZ
‡  ZS )ÚAsSeta"  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        keys (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for data nested in the container.

    A :doc:`uproot.containers.AsContainer` for ``std::set``.
    c                   s   t ƒ  ||¡ d S r   )Úsuperru   )r`   r(   r   ©Ú	__class__r   r   ru   Ÿ  s    zAsSet.__init__Úsetc                 C  s   dt | jƒ› d�S )Nz	std::set<rô   rÿ   r_   r   r   r   r   ¤  s    zAsSet.typenamec                 C  s   | j S rö   r÷   r_   r   r   r   r   ¨  s    z
AsSet.keysr—   c                 C  s   t S r   )ÚSTLSetr_   r   r   r   rò   ±  s    zAsSet._container_type)r   rl   rm   rn   ru   rî   ro   r   r   rå   rò   Ú__classcell__r   r   r  r   r  •  s   	

r  c                 C  s   t | tƒr| jS dS d S rŠ   )r   r9   r(   )Úobjr   r   r   Ú_has_nested_header¶  s    
r
  c                   @  sr   e Zd ZdZdd„ Zdd„ Zedd„ ƒZedd	„ ƒZd
d„ Z	edd„ ƒZ
edd„ ƒZdd„ Zddd„Zdd„ ZdS )ÚAsMapa’  
    Args:
        header (bool): Sets the :ref:`uproot.containers.AsContainer.header`.
        keys (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for the map's keys.
        values (:doc:`uproot.model.Model` or :doc:`uproot.containers.Container`): Data
            type for the map's values.

    A :doc:`uproot.containers.AsContainer` for ``std::map``.
    c                 C  s–   || _ t|tƒr|| _n4t|tƒr@t|tjjtjj	fƒr@|| _nt
 |¡| _t|tƒr^|| _n4t|tƒr†t|tjjtjj	fƒr†|| _nt
 |¡| _d S r   )r(   r   r9   Ú_keysr   rá   r   r   râ   rã   r	   r
   r¿   )r`   r(   r   rF   r   r   r   ru   É  s    
ÿ
ÿzAsMap.__init__c                 C  s   t t| j| j| jfƒS r   )r…   r  re   r  r¿   r_   r   r   r   r†   Þ  s    zAsMap.__hash__c                 C  s   | j S )z/
        Data type for the map's keys.
        ©r  r_   r   r   r   r   á  s    z
AsMap.keysc                 C  s   | j S )z1
        Data type for the map's values.
        rÃ   r_   r   r   r   rF   è  s    zAsMap.valuesc                 C  sX   t | jtƒr| jjnt| jƒ}t | jtƒr4| jj}n
t| jƒ}d| j› d|› d|› d�S )NúAsMap(rO   rw   )r   r  r   r   rJ   r¿   re   )r`   r   rF   r   r   r   rx   ï  s
    

zAsMap.__repr__c                 C  s&   d| j › dt| jƒ› dt| jƒ› d�S )Nr  r”   rw   )re   r   r  r¿   r_   r   r   r   r   ÷  s    zAsMap.cache_keyc                 C  s   dt | jƒ› dt | jƒ› d�S )Nz	std::map<rO   rô   )r   r  r¿   r_   r   r   r   r   û  s    zAsMap.typenamec              
   C  sN   t j ¡ }|j |d |jjt j | j||¡t j | j	||¡fd ddid�¡S )Nr•   r—   Ú
sorted_mapr™   )
r   rz   r{   r›   rœ   Z
RecordFormr}   rb   r  r¿   r�   r   r   r   rb   ÿ  s    
þúþzAsMap.awkward_formTc                 C  sö  t j |¡}|d urht j ||t j d¡¡}t j |¡}	t jjd|	› �dddddidœd|	› �d	œd
�}
| jr’|r’| ¡ }t j	 
|||¡\}}}nd}|�r4| jrÒ|rÒ| d¡ |d urÒ|
j |j|j › d�¡ | |t|¡}|d u�r&|
j d|	› d�¡ |
j d|	› d�¡ |
j d|	› d�¡ t| jƒ�rX|�rX| d¡ |d u�rX|
j d¡ |d u�r t| jtjƒ�s€|
j d¡ n|
j d¡ | |
¡ | |
¡ t| j|||t j ||t j d¡¡|||dd�	}|d u�rt| jtjƒ�st|
jƒdk�r|
jd j d¡ t| jƒ�rT|�rT| d¡ |d u�rTt|
jƒdk�rT|
jd j d¡ |d u�r�t| jtjƒ�s�t|
jƒdk�r�|
jd j d¡ t| j|||t j ||t j d¡¡|||dd�	}|d u�rüt| jtjƒ�süt|
jƒdk�rü|
jd j d¡ t||ƒ}| j�r0|�r0t j	  ||||| j!||j"¡ |S |d u�rJt j#j$ %¡ ‚| |t|¡}g g  }}t&|ƒD ]B}| t| jd||||||ƒ¡ | t| jd||||||ƒ¡ �qjtt '|¡t '|¡ƒ}| j�rî|�rît j	  ||||| j!||j"¡ |S d S )NÚmapr   rž   rŸ   ZRecordArrayr—   r  )r   rš   )r   r¢   r   r!   r"   Frç   r£   r#   rÓ   r¤   r¥   rê   rë   z6 stream skip
z	dup 0 do
zdup
r   r'   r   rí   rì   rF   rM   )(r   r)   r*   r¦   r§   r.   r/   re   r¨   r‰   r©   r   r2   r1   rª   r«   r¬   r0   r¯   r
  r  r   r	   r
   r3   r8   rH   rQ   ÚchildrenrØ   r¿   ÚSTLMapr­   r   r®   r   r,   r-   r7   Zconcatenate)r`   r<   r=   r>   r?   r@   rA   r(   rB   rD   rE   r±   r²   r³   r´   r;   r   rF   rµ   Ú_r   r   r   r:     s   ÿþùþ
üý

ÿ

ÿ




ÿõÿþý
ÿþýÿõÿþý
ù


ÿÿÿÿù	z
AsMap.readc                 C  sÖ   t |tƒsdS | j|jkrdS t | jtjƒrLt |jtjƒrL| j|jkr~dS n2t | jtjƒszt |jtjƒsz| j|jkr~dS ndS t | jtjƒr¦t |jtjƒr¦| j|jkS t | jtjƒsÎt |jtjƒsÎ| j|jkS dS d S rŠ   )r   r  r(   r   r	   r
   rF   rh   r   r   r   rj   §  s,    
ÿÿÿzAsMap.__eq__N)T)r   rl   rm   rn   ru   r†   ro   r   rF   rx   r   r   rb   r:   rj   r   r   r   r   r  ½  s    




 r  c                   @  s    e Zd ZdZdd„ Zdd„ ZdS )Ú	ContainerzK
    Abstract class for Python representations of C++ STL collections.
    c                 C  s
   | |k S r   r   rh   r   r   r   rk   Ê  s    zContainer.__ne__c                 C  s   t ‚dS )zg
        Convert the data this collection contains into nested lists, sets,
        and dicts.
        Nr]   r_   r   r   r   ÚtolistÍ  s    zContainer.tolistN)r   rl   rm   rn   rk   r  r   r   r   r   r  Å  s   r  c                   @  sl   e Zd ZdZdd„ Zddd„Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )rø   zµ
    Args:
        values (``numpy.ndarray`` or iterable): Contents of the ``ROOT::VecOps::RVec``.

    Representation of a C++ ``ROOT::VecOps::RVec`` as a Python ``Sequence``.
    c                 C  sX   t |tjƒrt t|ƒ¡}n2t |tƒr6t t|ƒ¡}nt |ttfƒrNt |¡}|| _d S r   ©	r   ÚtypesÚGeneratorTyper	   Úasarrayrý   r   Útupler¿   rÅ   r   r   r   ru   Ý  s    

zROOTRVec.__init__éU   c                   s    ‡ fdd„}t |tˆ ƒdd|ƒS )Nc                   s   t ˆ j|  ƒS r   ©rL   r¿   ©rG   r_   r   r   rT   è  s    z"ROOTRVec.__str__.<locals>.tostringrÆ   rÇ   ©r\   rQ   ©r`   rU   rT   r   r_   r   Ú__str__ç  s    zROOTRVec.__str__c                 C  s$   d| j |d d�› dt| ƒd›d�S )Nz
<ROOTRVec é   ©rU   ú at 0xÚ012xrô   ©r   Úid©r`   rU   r   r   r   rx   í  s    zROOTRVec.__repr__c                 C  s
   | j | S r   rÃ   ©r`   Úwherer   r   r   Ú__getitem__ð  s    zROOTRVec.__getitem__c                 C  s
   t | jƒS r   ©rQ   r¿   r_   r   r   r   Ú__len__ó  s    zROOTRVec.__len__c                 C  s
   || j v S r   rÃ   ©r`   Úwhatr   r   r   Ú__contains__ö  s    zROOTRVec.__contains__c                 C  s
   t | jƒS r   ©Úiterr¿   r_   r   r   r   Ú__iter__ù  s    zROOTRVec.__iter__c                 C  s   t | jd d d… ƒS ©NrÒ   )rø   r¿   r_   r   r   r   Ú__reversed__ü  s    zROOTRVec.__reversed__c                 C  s2   t |tƒr| j|jkS t |tƒr*| j|kS dS d S rŠ   )r   rø   r¿   r   rh   r   r   r   rj   ÿ  s
    


zROOTRVec.__eq__c                 O  s   t j| jg|¢R i |¤ŽS r   ©r	   r  Z_vector©r`   r“   Úkwargsr   r   r   r—     s    zROOTRVec.__array__c                 C  s   dd„ | D ƒS )Nc                 S  s(   g | ] }t |ttjfƒr | ¡ n|‘qS r   ©r   r  r	   Úndarrayr  ©rÈ   rZ   r   r   r   Ú
<listcomp>  s   z#ROOTRVec.tolist.<locals>.<listcomp>r   r_   r   r   r   r  
  s    ÿzROOTRVec.tolistN)r  )r  ©r   rl   rm   rn   ru   r   rx   r*  r,  r/  r2  r4  rj   r—   r  r   r   r   r   rø   Õ  s   


rø   c                   @  sd   e Zd ZdZdd„ Zddd„Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )rþ   z£
    Args:
        values (``numpy.ndarray`` or iterable): Contents of the ``std::list``.

    Representation of a C++ ``std::list`` as a Python ``Sequence``.
    c                 C  sX   t |tjƒrt t|ƒ¡}n2t |tƒr6t t|ƒ¡}nt |ttfƒrNt |¡}|| _d S r   r  rÅ   r   r   r   ru     s    

zSTLList.__init__r  c                   s    ‡ fdd„}t |tˆ ƒdd|ƒS )Nc                   s   t ˆ j|  ƒS r   r  r  r_   r   r   rT   #  s    z!STLList.__str__.<locals>.tostringrÆ   rÇ   r  r  r   r_   r   r   "  s    zSTLList.__str__c                 C  s$   d| j |d d�› dt| ƒd›d�S )Nz	<STLList r!  r"  r#  r$  rô   r%  r'  r   r   r   rx   (  s    zSTLList.__repr__c                 C  s
   | j | S r   rÃ   r(  r   r   r   r*  +  s    zSTLList.__getitem__c                 C  s
   t | jƒS r   r+  r_   r   r   r   r,  .  s    zSTLList.__len__c                 C  s
   || j v S r   rÃ   r-  r   r   r   r/  1  s    zSTLList.__contains__c                 C  s
   t | jƒS r   r0  r_   r   r   r   r2  4  s    zSTLList.__iter__c                 C  s   t | jd d d… ƒS r3  )rþ   r¿   r_   r   r   r   r4  7  s    zSTLList.__reversed__c                 C  s2   t |tƒr| j|jkS t |tƒr*| j|kS dS d S rŠ   )r   rþ   r¿   r   rh   r   r   r   rj   :  s
    


zSTLList.__eq__c                 C  s   dd„ | D ƒS )Nc                 S  s(   g | ] }t |ttjfƒr | ¡ n|‘qS r   r8  r:  r   r   r   r;  C  s   z"STLList.tolist.<locals>.<listcomp>r   r_   r   r   r   r  B  s    ÿzSTLList.tolistN)r  )r  )r   rl   rm   rn   ru   r   rx   r*  r,  r/  r2  r4  rj   r  r   r   r   r   rþ     s   


rþ   c                   @  sl   e Zd ZdZdd„ Zddd„Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )rû   z§
    Args:
        values (``numpy.ndarray`` or iterable): Contents of the ``std::vector``.

    Representation of a C++ ``std::vector`` as a Python ``Sequence``.
    c                 C  sX   t |tjƒrt t|ƒ¡}n2t |tƒr6t t|ƒ¡}nt |ttfƒrNt |¡}|| _d S r   r  rÅ   r   r   r   ru   P  s    

zSTLVector.__init__r  c                   s    ‡ fdd„}t |tˆ ƒdd|ƒS )Nc                   s   t ˆ j|  ƒS r   r  r  r_   r   r   rT   [  s    z#STLVector.__str__.<locals>.tostringrÆ   rÇ   r  r  r   r_   r   r   Z  s    zSTLVector.__str__c                 C  s$   d| j |d d�› dt| ƒd›d�S )Nz<STLVector r!  r"  r#  r$  rô   r%  r'  r   r   r   rx   `  s    zSTLVector.__repr__c                 C  s
   | j | S r   rÃ   r(  r   r   r   r*  c  s    zSTLVector.__getitem__c                 C  s
   t | jƒS r   r+  r_   r   r   r   r,  f  s    zSTLVector.__len__c                 C  s
   || j v S r   rÃ   r-  r   r   r   r/  i  s    zSTLVector.__contains__c                 C  s
   t | jƒS r   r0  r_   r   r   r   r2  l  s    zSTLVector.__iter__c                 C  s   t | jd d d… ƒS r3  )rû   r¿   r_   r   r   r   r4  o  s    zSTLVector.__reversed__c                 C  s2   t |tƒr| j|jkS t |tƒr*| j|kS dS d S rŠ   )r   rû   r¿   r   rh   r   r   r   rj   r  s
    


zSTLVector.__eq__c                 O  s   t j| jg|¢R i |¤ŽS r   r5  r6  r   r   r   r—   z  s    zSTLVector.__array__c                 C  s   dd„ | D ƒS )Nc                 S  s(   g | ] }t |ttjfƒr | ¡ n|‘qS r   r8  r:  r   r   r   r;  ~  s   z$STLVector.tolist.<locals>.<listcomp>r   r_   r   r   r   r  }  s    ÿzSTLVector.tolistN)r  )r  r<  r   r   r   r   rû   H  s   


rû   c                   @  sT   e Zd ZdZdd„ Zddd„Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )r  z§
    Args:
        values (``numpy.ndarray`` or iterable): Contents of the ``std::vector``.

    Representation of a C++ ``std::bitset`` as a Python ``Sequence``.
    c                 C  s   t  |¡| _d S r   )r	   r  Ú	_numbytes)r`   Únumbytesr   r   r   ru   ‹  s    zSTLBitSet.__init__r  c                   s    ‡ fdd„}t |tˆ ƒdd|ƒS )Nc                   s   t ˆ j|  ƒS r   r  r  r_   r   r   rT   �  s    z#STLBitSet.__str__.<locals>.tostringrÆ   rÇ   r  r  r   r_   r   r   Ž  s    zSTLBitSet.__str__c                 C  s$   d| j |d d�› dt| ƒd›d�S )Nz<STLBitSet r!  r"  r#  r$  rô   r%  r'  r   r   r   rx   ”  s    zSTLBitSet.__repr__c                 C  s
   | j | S r   ©r=  r(  r   r   r   r*  —  s    zSTLBitSet.__getitem__c                 C  s   | j S r   r?  r_   r   r   r   r,  š  s    zSTLBitSet.__len__c                 C  s
   t | jƒS r   )r1  r=  r_   r   r   r   r2  �  s    zSTLBitSet.__iter__c                 C  s2   t |tƒr| j|jkS t |tƒr*| j|kS dS d S rŠ   )r   r  r=  r   rh   r   r   r   rj      s
    


zSTLBitSet.__eq__c                 C  s   dd„ | D ƒS )Nc                 S  s(   g | ] }t |ttjfƒr | ¡ n|‘qS r   r8  r:  r   r   r   r;  ©  s   z$STLBitSet.tolist.<locals>.<listcomp>r   r_   r   r   r   r  ¨  s    ÿzSTLBitSet.tolistN)r  )r  )r   rl   rm   rn   ru   r   rx   r*  r,  r2  rj   r  r   r   r   r   r  ƒ  s   

r  c                   @  s\   e Zd ZdZdd„ Zddd„Zddd„Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )r  zš
    Args:
        keys (``numpy.ndarray`` or iterable): Contents of the ``std::set``.

    Representation of a C++ ``std::set`` as a Python ``Set``.
    c                 C  sP   t |tjƒrt t|ƒ¡}n$t |tƒr6t t|ƒ¡}n
t |¡}t |¡| _d S r   )	r   r  r  r	   r  rý   r   Úsortr  )r`   r   r   r   r   ru   ¶  s    

zSTLSet.__init__r  c                   s    ‡ fdd„}t |tˆ ƒdd|ƒS )Nc                   s   t ˆ j|  ƒS r   )rL   r  r  r_   r   r   rT   Á  s    z STLSet.__str__.<locals>.tostringÚ{Ú}r  r  r   r_   r   r   À  s    zSTLSet.__str__c                 C  s$   d| j |d d�› dt| ƒd›d�S )Nz<STLSet r!  r"  r#  r$  rô   r%  r'  r   r   r   rx   Æ  s    zSTLSet.__repr__c                 C  s
   t | jƒS r   ©rQ   r  r_   r   r   r   r,  É  s    zSTLSet.__len__c                 C  s
   t | jƒS r   ©r1  r  r_   r   r   r   r2  Ì  s    zSTLSet.__iter__c                 C  sX   t  |¡}t j| j |j¡|dd�}tj |¡rPt	|t
| jƒk oL| j| |kƒS dS d S ©NrV   ©ZsideF©r	   r  Úsearchsortedr  Úastyper
   r   r}   ÚisintÚboolrQ   ©r`   r)  rÖ   r   r   r   r/  Ï  s
    
 zSTLSet.__contains__c                 C  sb   t |tƒrt |tƒs"t|ƒ}ndS t| jƒt|jƒkr:dS | j|jk}t |tƒrT|S t |¡S d S rŠ   )r   r   r  rQ   r  rK  r	   Úall)r`   ri   Ú	keys_samer   r   r   rj   Ù  s    



zSTLSet.__eq__c                 O  s   t j| jg|¢R i |¤ŽS r   )r	   r  r  r6  r   r   r   r—   é  s    zSTLSet.__array__c                 C  s   dd„ | D ƒS )Nc                 S  s(   h | ] }t |ttjfƒr | ¡ n|’qS r   r8  r:  r   r   r   Ú	<setcomp>í  s   z STLSet.tolist.<locals>.<setcomp>r   r_   r   r   r   r  ì  s    ÿzSTLSet.tolistN)r  )r  )r   rl   rm   rn   ru   r   rx   r,  r2  r/  rj   r—   r  r   r   r   r   r  ®  s   



r  c                   @  sŠ   e Zd ZdZedd„ ƒZdd„ Zd dd„Zd!d	d
„Zdd„ Z	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 )#r  a"  
    Args:
        keys (``numpy.ndarray`` or iterable): Keys of the ``std::map``.
        values (``numpy.ndarray`` or iterable): Values of the ``std::map``.

    Representation of a C++ ``std::map`` as a Python ``Mapping``.

    The ``keys`` and ``values`` must have the same length.
    c                 C  s   t | ¡ | ¡ ƒS )z|
        Construct a :doc:`uproot.containers.STLMap` from a Python object with
        ``keys()`` and ``values()``.
        )r  r   rF   )r�   Úmappingr   r   r   Úfrom_mappingý  s    zSTLMap.from_mappingc                 C  s   t d ur"t|t ƒr"t t|ƒ¡}n@t|tjƒr>t t|ƒ¡}n$t|tƒrXt t|ƒ¡}n
t |¡}td ur„t|tƒr„t t|ƒ¡}nt|tjƒržt t|ƒ¡}t	|ƒt	|ƒkr¶t
dƒ‚t |¡}|| | _z|| | _W n" tyú   t |¡| | _Y n0 d S )Nz4number of keys must be equal to the number of values)r   r   r	   r  rý   r  r  r   r   rQ   r�   Zargsortr  r¿   Ú	Exception)r`   r   rF   rÖ   r   r   r   ru     s&    



zSTLMap.__init__r  c                   s    ‡ fdd„}t |tˆ ƒdd|ƒS )Nc                   s    t ˆ j|  ƒd t ˆ j|  ƒ S )Nz: )rL   r  r¿   r  r_   r   r   rT      s    z STLMap.__str__.<locals>.tostringrA  rB  r  r  r   r_   r   r     s    zSTLMap.__str__c                 C  s$   d| j |d d�› dt| ƒd›d�S )Nz<STLMap r!  r"  r#  r$  rô   r%  r'  r   r   r   rx   %  s    zSTLMap.__repr__c                 C  s   | j S )zB
        Keys of the ``std::map`` as a ``numpy.ndarray``.
        r  r_   r   r   r   r   (  s    zSTLMap.keysc                 C  s   | j S )zD
        Values of the ``std::map`` as a ``numpy.ndarray``.
        rÃ   r_   r   r   r   rF   .  s    zSTLMap.valuesc                 C  s   t  t  | j| jg¡¡S )zN
        Key, value pairs of the ``std::map`` as a ``numpy.ndarray``.
        )r	   Z	transposeZvstackr  r¿   r_   r   r   r   Úitems4  s    zSTLMap.itemsc                 C  sÂ   t  |¡}t j| j |j¡|dd�}tj |¡r`|t	| jƒk rV| j| |krV| j
| S t|ƒ‚n^t	| jƒdkrŠt  t	|ƒ¡}t j |d¡S d||t	| jƒk< | j| |k}t j | j
| |¡S d S )NrV   rF  r   T)r	   r  rH  r  rI  r
   r   r}   rJ  rQ   r¿   ÚKeyErrorr5   ÚmaZMaskedArray)r`   r)  rÖ   rF   Úmaskr   r   r   r*  :  s    


zSTLMap.__getitem__Nc                 C  sâ   t  |¡}t j| j |j¡|dd�}tj |¡r\|t	| jƒk rV| j| |krV| j
| S |S n‚t	| jƒdkrˆt  |g¡t  t	|ƒt j¡ S d||t	| jƒk< | j| |k}| j
| }t  |g¡t  t	|ƒt j¡ }t  |||¡S dS )z4
        Get with a default, like dict.get.
        rV   rF  r   N)r	   r  rH  r  rI  r
   r   r}   rJ  rQ   r¿   r4   ZzerosZint32r)  )r`   r)  ÚdefaultrÖ   ÚmatchesrF   Údefaultsr   r   r   r+   M  s    


z
STLMap.getc                 C  s
   t | jƒS r   rC  r_   r   r   r   r,  d  s    zSTLMap.__len__c                 C  s
   t | jƒS r   rD  r_   r   r   r   r2  g  s    zSTLMap.__iter__c                 C  sX   t  |¡}t j| j |j¡|dd�}tj |¡rPt	|t
| jƒk oL| j| |kƒS dS d S rE  rG  rL  r   r   r   r/  j  s
    
 zSTLMap.__contains__c                 C  sŒ   t |tƒr(t |tƒs,t| ¡ | ¡ ƒ}ndS t| jƒt|jƒkrDdS | j|jk}| j|jk}t |tƒrxt |tƒrx|ov|S t	 
||¡ ¡ S d S rŠ   )r   r   r  r   rF   rQ   r  r¿   rK  r	   Úlogical_andrM  )r`   ri   rN  Zvalues_samer   r   r   rj   t  s    

zSTLMap.__eq__c                 C  sV   i }t t| ƒƒD ]@}| j| }t|ttjfƒrB| ¡ || j| < q||| j| < q|S r   )	r7   rQ   r¿   r   r  r	   r9  r  r  )r`   rµ   rG   rZ   r   r   r   r  …  s    
zSTLMap.tolist)r  )r  )N)r   rl   rm   rn   ÚclassmethodrQ  ru   r   rx   r   rF   rS  r*  r+   r,  r2  r/  rj   r  r   r   r   r   r  ò  s    





r  )T)-rn   Ú
__future__r   Ústructr  Úcollections.abcr   r   r   r   r   r	   r   Zuproot._awkwardforthÚStructr¬   r
   Úobjectr6   r   r   rH   rL   r\   r9   rq   r‚   r‹   r¶   r½   rÝ   ró   rú   rü   rß   r  r
  r  r  rø   rþ   rû   r  r  r  r   r   r   r   Ú<module>   sR   

 ÿ
A(wC- G m Q!  
;8;+D