a
    zn„fm  ã                   @  s0   d Z ddlmZ ddlZG dd„ dejjƒZdS )zÃ
This module defines an :doc:`uproot.interpretation.Interpretation` and
temporary array for grouped data; usually applied to a ``TBranch`` that does
not contain data but has subbranches that do.
é    )ÚannotationsNc                   @  st   e Zd ZdZd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dd„ Zdd„ ZdS )Ú	AsGroupedus  
    Args:
        branch (:doc:`uproot.behaviors.TBranch.TBranch`): The ``TBranch`` that
            represents the group.
        subbranches (dict of str â†’ :doc:`uproot.behaviors.TBranch.TBranch`): Names
            and interpretations of the ``TBranches`` that actually contain data.
        typename (None or str): If None, construct a plausible C++ typename.
            Otherwise, take the suggestion as given.

    Interpretation for a group of arrays, usually because they are all
    subbranches of the same :doc:`uproot.behaviors.TBranch.TBranch`.

    Each :doc:`uproot.interpretation.library.Library` presents a group
    differently: :doc:`uproot.interpretation.library.NumPy` puts arrays
    in a dict, :doc:`uproot.interpretation.library.Awkward` makes an
    array of records, :doc:`uproot.interpretation.library.Pandas` makes
    a ``pandas.DataFrame``, etc.
    Nc                 C  s   || _ || _|| _d S ©N)Ú_branchÚ_subbranchesÚ	_typename)ÚselfÚbranchÚsubbranchesÚtypename© r   ú`/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/uproot/interpretation/grouped.pyÚ__init__!   s    zAsGrouped.__init__c                 C  s   | j S )z<
        The ``TBranch`` that represents the group.
        )r   ©r   r   r   r   r	   &   s    zAsGrouped.branchc                 C  s   | j S )zA
        The ``TBranches`` that contain the actual data.
        )r   r   r   r   r   r
   -   s    zAsGrouped.subbranchesc                 C  s   d| j › d| j› d�S )NzAsGroup(ú, ú))r   r   r   r   r   r   Ú__repr__4   s    zAsGrouped.__repr__c                 C  s"   t |tƒo | j|jko | j|jkS r   )Ú
isinstancer   r   r   )r   Úotherr   r   r   Ú__eq__7   s
    

ÿ
ýzAsGrouped.__eq__c              	   C  s.   d  t| ƒj| jjd dd„ | j ¡ D ƒ¡¡S )Nz{}({},[{}])ú,c                 s  s*   | ]"\}}|d ur|›d|j › �V  qd S ©Nú:)Ú	cache_key©Ú.0ÚxÚyr   r   r   Ú	<genexpr>C   s   þz&AsGrouped.cache_key.<locals>.<genexpr>)ÚformatÚtypeÚ__name__r   ÚnameÚjoinr   Úitemsr   r   r   r   r   >   s    
þýzAsGrouped.cache_keyc                 C  s4   | j d ur| j S d d dd„ | j ¡ D ƒ¡¡S d S )Nz(group of {})r   c                 s  s*   | ]"\}}|d ur|› d|j › �V  qd S r   )r   r   r   r   r   r   P   s   þz%AsGrouped.typename.<locals>.<genexpr>)r   r   r#   r   r$   r   r   r   r   r   J   s    

þÿzAsGrouped.typenameÚi64Fr   c                 C  sj   |   |||||¡}tj ¡ }g }g }	| j ¡ D ],\}
}|d ur.| |
¡ |	 | ||¡¡ q.|j 	|	|¡S r   )
Z_make_contextÚuprootÚextrasÚawkwardr   r$   ÚappendÚawkward_formZformsZ
RecordForm)r   ÚfileÚcontextZindex_formatÚheaderZtobject_headerZbreadcrumbsr(   ÚnamesÚfieldsr   r   r   r   r   r*   W   s    	
ÿ

zAsGrouped.awkward_formc	           	      C  s<   t d t| jjƒd dd„ | jD ƒ¡| jjj| jj	¡ƒ‚d S )Núugrouping branches like {} should not be read directly; instead read the subbranches:

    {}

in file {}
in object {}r   c                 s  s   | ]}t |ƒV  qd S r   ©Úrepr©r   r   r   r   r   r      ó    z)AsGrouped.basket_array.<locals>.<genexpr>©
Ú
ValueErrorr   r2   r   r"   r#   r   r+   Ú	file_pathZobject_path)	r   ÚdataZbyte_offsetsÚbasketr	   r,   Zcursor_offsetÚlibraryÚoptionsr   r   r   Úbasket_arrayl   s    
÷ÿzAsGrouped.basket_arrayc                 C  s<   t d t| jjƒd dd„ | jD ƒ¡| jjj| jj	¡ƒ‚d S )Nr0   r   c                 s  s   | ]}t |ƒV  qd S r   r1   r3   r   r   r   r   —   r4   z(AsGrouped.final_array.<locals>.<genexpr>r5   )r   Zbasket_arraysZentry_startZ
entry_stopZentry_offsetsr:   r	   r;   r   r   r   Úfinal_array…   s    

÷ÿzAsGrouped.final_array)N)Nr%   FFr   )r!   Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr	   r
   r   r   r   r   r*   r<   r=   r   r   r   r   r      s(   




     ù
r   )r@   Ú
__future__r   r&   ZinterpretationZInterpretationr   r   r   r   r   Ú<module>   s   