# uproot.model.DispatchByVersion

Defined in [uproot.model](https://github.com/scikit-hep/uproot5/blob/db953cf9827349b3d24eb6742404158c1dfd5481/src/uproot/model.py) on [line 1172](https://github.com/scikit-hep/uproot5/blob/db953cf9827349b3d24eb6742404158c1dfd5481/src/uproot/model.py#L1172).

### *class* uproot.model.DispatchByVersion

A Python class that models all versions of a ROOT C++ class by maintaining
a dict of [uproot.model.VersionedModel](uproot.model.VersionedModel.html.md) classes.

The [read](#uproot-model-dispatchbyversion-read) classmethod reads the
instance version number from the byte stream, backs up the
[uproot.Cursor](uproot.source.cursor.Cursor.html.md) to the starting position, and invokes
the appropriate [uproot.model.VersionedModel](uproot.model.VersionedModel.html.md)’s `read` classmethod.

If a [uproot.model.VersionedModel](uproot.model.VersionedModel.html.md) does not exist for the specified
version, the `file`’s `TStreamerInfo` is queried to attempt to create
one, and failing that, an [uproot.model.UnknownClassVersion](uproot.model.UnknownClassVersion.html.md) is
created instead.

Note that [uproot.model.DispatchByVersion](uproot.model.DispatchByVersion.html.md) is not a subclass of
[uproot.Model](uproot.model.Model.html.md). Instances of this class are not usable as
stand-ins for ROOT data.

<a id="uproot-model-dispatchbyversion-awkward-form"></a>

## awkward_form

#### *classmethod* DispatchByVersion.awkward_form(file, context)

* **Parameters:**
  * **cls** (subclass of [uproot.model.DispatchByVersion](uproot.model.DispatchByVersion.html.md)) – This class.
  * **file** ([uproot.ReadOnlyFile](uproot.reading.ReadOnlyFile.html.md)) – File to use to generate
    [uproot.Model](uproot.model.Model.html.md) classes from its
    [streamers](uproot.reading.ReadOnlyFile.html.md#uproot-reading-readonlyfile-streamers) and `file_path`
    for error messages.
  * **context** (*dict*) – Context for the Form-generation; defaults are
    `{"index_format": "i64", "header": False, "tobject_header": True, "breadcrumbs": ()}`.
    See below for context argument descriptions.
  * **index_format** (*str*) – Format to use for indexes of the
    `awkward.forms.Form`; may be `"i32"`, `"u32"`, or
    `"i64"`.
  * **header** (*bool*) – If True, include headers in the Form’s `"uproot"`
    parameters.
  * **tobject_header** (*bool*) – If True, include headers for `TObject`
    classes in the Form’s `"uproot"` parameters.
  * **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.

<a id="uproot-model-dispatchbyversion-strided-interpretation"></a>

## strided_interpretation

#### *classmethod* DispatchByVersion.strided_interpretation(file, header=False, tobject_header=True, breadcrumbs=(), original=None)

* **Parameters:**
  * **cls** (subclass of [uproot.model.DispatchByVersion](uproot.model.DispatchByVersion.html.md)) – This class.
  * **file** ([uproot.ReadOnlyFile](uproot.reading.ReadOnlyFile.html.md)) – File to use to generate
    [uproot.Model](uproot.model.Model.html.md) classes from its
    [streamers](uproot.reading.ReadOnlyFile.html.md#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.
  * **original** (None, [uproot.Model](uproot.model.Model.html.md), or [uproot.containers.Container](uproot.containers.Container.html.md)) – The
    original, non-strided model or container.
  * **breadcrumbs** (*tuple* *of* *class objects*) – Used to check for recursion.
    Types that contain themselves cannot be strided because the
    depth of instances is unknown.

Returns a list of (str, `numpy.dtype`) pairs to build a
[uproot.AsStridedObjects](uproot.interpretation.objects.AsStridedObjects.html.md) interpretation.

<a id="uproot-model-dispatchbyversion-class-of-version"></a>

## class_of_version

#### *classmethod* DispatchByVersion.class_of_version(version)

Returns the class corresponding to a specified `version` if it exists.

If not, this classmethod returns None. No attempt is made to create a
missing class.

<a id="uproot-model-dispatchbyversion-has-version"></a>

## has_version

#### *classmethod* DispatchByVersion.has_version(version)

Returns True if a class corresponding to a specified `version`
currently exists; False otherwise.

<a id="uproot-model-dispatchbyversion-new-class"></a>

## new_class

#### *classmethod* DispatchByVersion.new_class(file, version)

Uses `file` to create a new class for a specified `version`.

As a side-effect, this new class is added to `cls.known_versions`
(for [class_of_version](#uproot-model-dispatchbyversion-class-of-version) and
[has_version](#uproot-model-dispatchbyversion-has-version)).

If the `file` lacks a `TStreamerInfo` for the class, this function
returns a [uproot.model.UnknownClassVersion](uproot.model.UnknownClassVersion.html.md) (adding it to
`uproot.unknown_classes` if it’s not already there).

<a id="uproot-model-dispatchbyversion-read"></a>

## read

#### *classmethod* DispatchByVersion.read(chunk, cursor, context, file, selffile, parent, concrete=None)

* **Parameters:**
  * **cls** (subclass of [uproot.model.DispatchByVersion](uproot.model.DispatchByVersion.html.md)) – This class.
  * **chunk** ([uproot.source.chunk.Chunk](uproot.source.chunk.Chunk.html.md)) – Buffer of contiguous data
    from the file [uproot.source.chunk.Source](uproot.source.chunk.Source.html.md).
  * **cursor** ([uproot.Cursor](uproot.source.cursor.Cursor.html.md)) – Current position in
    that `chunk`.
  * **context** (*dict*) – Auxiliary data used in deserialization.
  * **file** ([uproot.ReadOnlyFile](uproot.reading.ReadOnlyFile.html.md)) – An open file object,
    capable of generating new [uproot.Model](uproot.model.Model.html.md) classes
    from its [streamers](uproot.reading.ReadOnlyFile.html.md#uproot-reading-readonlyfile-streamers).
  * **selffile** ([uproot.reading.CommonFileMethods](uproot.reading.CommonFileMethods.html.md)) – A possibly
    [uproot.reading.DetachedFile](uproot.reading.DetachedFile.html.md) associated with this object.
  * **parent** (*None* *or* *calling object*) – The previous `read` in the
    recursive descent.
  * **concrete** (None or [uproot.Model](uproot.model.Model.html.md) instance) – If None,
    this model corresponds to the concrete (instantiated) class in
    C++. Otherwise, this model represents a superclass part of the
    object, and `concrete` points to the concrete instance.

Reads the instance version number from the byte stream, backs up the
[uproot.Cursor](uproot.source.cursor.Cursor.html.md) to the starting position, and
invokes the appropriate [uproot.model.VersionedModel](uproot.model.VersionedModel.html.md)’s `read`
classmethod.

If a [uproot.model.VersionedModel](uproot.model.VersionedModel.html.md) does not exist for the
specified version, the `file`’s `TStreamerInfo` is queried to
attempt to create one, and failing that, an
[uproot.model.UnknownClassVersion](uproot.model.UnknownClassVersion.html.md) is created instead.

<a id="uproot-model-dispatchbyversion-postprocess"></a>

## postprocess

#### *classmethod* DispatchByVersion.postprocess(self, chunk, cursor, context, file)

* **Parameters:**
  * **cls** (subclass of [uproot.model.DispatchByVersion](uproot.model.DispatchByVersion.html.md)) – This class.
  * **chunk** ([uproot.source.chunk.Chunk](uproot.source.chunk.Chunk.html.md)) – Buffer of contiguous data
    from the file [uproot.source.chunk.Source](uproot.source.chunk.Source.html.md).
  * **cursor** ([uproot.Cursor](uproot.source.cursor.Cursor.html.md)) – Current position in
    that `chunk`.
  * **context** (*dict*) – Auxiliary data used in deserialization.
  * **file** ([uproot.ReadOnlyFile](uproot.reading.ReadOnlyFile.html.md)) – An open file object,
    capable of generating new [uproot.Model](uproot.model.Model.html.md) classes
    from its [streamers](uproot.reading.ReadOnlyFile.html.md#uproot-reading-readonlyfile-streamers).

Called for any additional processing after the object has been fully
read.

The return value from this method is the object that actually represents
the ROOT data, which might be a different instance or even a different
type from this class. The default in [uproot.Model](uproot.model.Model.html.md) is to
return `self`.

Note that for versioned models,
[postprocess](uproot.model.VersionedModel.html.md#uproot-model-versionedmodel-postprocess) is called first, then
[postprocess](#uproot-model-dispatchbyversion-postprocess) is called on its
output, allowing a [uproot.model.DispatchByVersion](uproot.model.DispatchByVersion.html.md) to refine all
data of its type, regardless of version.
