How to use the uproot.source function in uproot

To help you get started, we’ve selected a few uproot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-hep / uproot / uproot / interp / objects.py View on Github external
def __call__(self, arg):
            bytes, origin = arg
            source = uproot.source.source.Source(bytes)
            cursor = uproot.source.cursor.Cursor(0, origin=origin)
            return self.cls.read(source, cursor, self.context, None)
        def __repr__(self):
github scikit-hep / uproot / uproot / interp / objects.py View on Github external
def __call__(self, arg):
            bytes, origin = arg
            source = uproot.source.source.Source(bytes)
            cursor = uproot.source.cursor.Cursor(0, origin=origin)
            return self.cls.read(source, cursor, self.context, None)
        def __repr__(self):
github scikit-hep / uproot / uproot / source / http.py View on Github external
#!/usr/bin/env python

# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE

from __future__ import absolute_import

import os.path
import re
import multiprocessing
import sys

import numpy

import uproot.source.chunked

class HTTPSource(uproot.source.chunked.ChunkedSource):
    # makes __doc__ attribute mutable before Python 3.3
    __metaclass__ = type.__new__(type, "type", (uproot.source.chunked.ChunkedSource.__metaclass__,), {})

    def __init__(self, path, auth=None, *args, **kwds):
        super(HTTPSource, self).__init__(path, *args, **kwds)
        self._size = None
        self.auth = auth

    defaults = {"chunkbytes": 1024**2, "limitbytes": 100*1024**2, "parallel": 8*multiprocessing.cpu_count() if sys.version_info[0] > 2 else 1}

    def _open(self):
        try:
            import requests
        except ImportError:
            raise ImportError("Install requests package (for HTTP) with:\n    pip install requests\nor\n    conda install -c anaconda requests")
github scikit-hep / uproot / uproot / source / xrootd.py View on Github external
#!/usr/bin/env python

# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE

from __future__ import absolute_import

import os
import threading

import numpy

import uproot.source.chunked

class XRootDSource(uproot.source.chunked.ChunkedSource):
    # makes __doc__ attribute mutable before Python 3.3
    __metaclass__ = type.__new__(type, "type", (uproot.source.chunked.ChunkedSource.__metaclass__,), {})

    def __init__(self, path, timeout=None, *args, **kwds):
        self._size = None
        self.timeout = timeout
        super(XRootDSource, self).__init__(path, *args, **kwds)

    defaults = {"timeout": None, "chunkbytes": 1024**2, "limitbytes": 100*1024**2, "parallel": False}

    def _open(self):
        try:
            os.environ["XRD_RUNFORKHANDLER"] = "1"   # To make uproot + xrootd + multiprocessing work
            import pyxrootd.client
        except ImportError:
            raise ImportError("Install pyxrootd package with:\n    conda install -c conda-forge xrootd\n(or download from http://xrootd.org/dload.html and manually compile with cmake; setting PYTHONPATH and LD_LIBRARY_PATH appropriately).")
github scikit-hep / uproot / uproot / source / memmap.py View on Github external
#!/usr/bin/env python

# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE

from __future__ import absolute_import

import os.path

import numpy

import uproot.source.source

class MemmapSource(uproot.source.source.Source):
    # makes __doc__ attribute mutable before Python 3.3
    __metaclass__ = type.__new__(type, "type", (uproot.source.source.Source.__metaclass__,), {})

    defaults = {}

    def __init__(self, path):
        self.path = os.path.expanduser(path)
        self._source = numpy.memmap(self.path, dtype=numpy.uint8, mode="r")

    def parent(self):
        return self

    def size(self):
        return len(self._source)

    def threadlocal(self):
github diana-hep / oamap / oamap / backend / root / __init__.py View on Github external
def localsource(path):
        return uproot.source.file.FileSource(path, chunkbytes=8*1024, limitbytes=None)
    return _schema(uproot.open(path, localsource=localsource)[treepath], namespace=namespace)
github diana-hep / oamap / oamap / backend / root / cmsnano.py View on Github external
def localsource(path):
        return uproot.source.file.FileSource(path, chunkbytes=8*1024, limitbytes=None)
github scikit-hep / uproot / uproot / source / xrootd.py View on Github external
#!/usr/bin/env python

# BSD 3-Clause License; see https://github.com/scikit-hep/uproot/blob/master/LICENSE

from __future__ import absolute_import

import os
import threading

import numpy

import uproot.source.chunked

class XRootDSource(uproot.source.chunked.ChunkedSource):
    # makes __doc__ attribute mutable before Python 3.3
    __metaclass__ = type.__new__(type, "type", (uproot.source.chunked.ChunkedSource.__metaclass__,), {})

    def __init__(self, path, timeout=None, *args, **kwds):
        self._size = None
        self.timeout = timeout
        super(XRootDSource, self).__init__(path, *args, **kwds)

    defaults = {"timeout": None, "chunkbytes": 1024**2, "limitbytes": 100*1024**2, "parallel": False}

    def _open(self):
        try:
            os.environ["XRD_RUNFORKHANDLER"] = "1"   # To make uproot + xrootd + multiprocessing work
            import pyxrootd.client
        except ImportError:
            raise ImportError("Install pyxrootd package with:\n    conda install -c conda-forge xrootd\n(or download from http://xrootd.org/dload.html and manually compile with cmake; setting PYTHONPATH and LD_LIBRARY_PATH appropriately).")

        if self._source is None or not self._source.is_open():
github scikit-hep / uproot / uproot / source / file.py View on Github external
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os.path

import numpy

import uproot.source.chunked

class FileSource(uproot.source.chunked.ChunkedSource):
    # makes __doc__ attribute mutable before Python 3.3
    __metaclass__ = type.__new__(type, "type", (uproot.source.chunked.ChunkedSource.__metaclass__,), {})

    defaults = {"chunkbytes": 8*1024, "limitbytes": 1024**2}

    def __init__(self, path, *args, **kwds):
        self._size = None
        self._parallel = kwds["parallel"]
        super(FileSource, self).__init__(os.path.expanduser(path), *args, **kwds)

    def size(self):
        if self._size is None:
            self._size = os.path.getsize(self.path)
        return self._size

    def threadlocal(self):
github scikit-hep / uproot / uproot / _help.py View on Github external
chunkbytes : int or string matching number + /[kMGTPEZY]?B/i
        number of bytes per chunk.

    limitbytes : int or string matching number + /[kMGTPEZY]?B/i
        maximum number of bytes to keep in the cache.

    Notes
    -----

    {see2}
""".format(**source_fragments)

_method(uproot.source.xrootd.XRootDSource.parent).__doc__ = source_fragments["see1"]
_method(uproot.source.xrootd.XRootDSource.threadlocal).__doc__ = source_fragments["see1"]
_method(uproot.source.xrootd.XRootDSource.dismiss).__doc__ = source_fragments["see1"]
_method(uproot.source.xrootd.XRootDSource.data).__doc__ = source_fragments["see1"]

################################################################ uproot.source.compressed.Compression

uproot.source.compressed.Compression.__doc__ = \
u"""Describe the compression of a compressed block.

    **Attributes, properties, and methods:**

    - **algo** (*int*) algorithm code.
    - **level** (*int*) 0 is no compression, 1 is least, 9 is most.
    - **algoname** (*str*) algorithm expressed as a string: ``"zlib"``, ``"lzma"``, ``"old"``, ``"lz4"`` or ``"zstd"``.
    - **copy(algo=None, level=None)** copy this :py:class:`Compression ` object, possibly changing a field.
    - **decompress(source, cursor, compressedbytes, uncompressedbytes)** decompress data from **source** at **cursor**, knowing the compressed and uncompressed size.

    Parameters
    ----------