How to use the uproot.const 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 / newrootio.py View on Github external
basicletters += "b"
                        elif element.fType == uproot.const.kUChar:
                            basicletters += "B"
                        elif element.fType == uproot.const.kShort:
                            basicletters += "h"
                        elif element.fType == uproot.const.kUShort:
                            basicletters += "H"
                        elif element.fType == uproot.const.kInt:
                            basicletters += "i"
                        elif element.fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
                            basicletters += "I"
                        elif element.fType == uproot.const.kLong:
                            basicletters += "l"
                        elif element.fType == uproot.const.kULong:
                            basicletters += "L"
                        elif element.fType == uproot.const.kLong64:
                            basicletters += "q"
                        elif element.fType == uproot.const.kULong64:
                            basicletters += "Q"
                        elif element.fType in (uproot.const.kFloat, uproot.const.kFloat16):
                            basicletters += "f"
                        elif element.fType in (uproot.const.kDouble, uproot.const.kDouble32):
                            basicletters += "d"
                        else:
                            raise NotImplementedError(element.fType)

                        if elementi + 1 == len(streamerinfo.fElements) or not isinstance(streamerinfo.fElements[elementi + 1], TStreamerBasicType) or streamerinfo.fElements[elementi + 1].fArrayLength != 0:
                            formatnum = len(formats) + 1
                            formats["_format{0}".format(formatnum)] = "struct.Struct('!{0}')".format(basicletters)

                            if len(basicnames) == 1:
                                code.append("        {0} = cursor.field(source, {1}._format{2})".format(basicnames[0], classname, formatnum))
github scikit-hep / uproot / uproot / rootio.py View on Github external
def _ftype2struct(fType):
    if fType == uproot.const.kBool:
        return "?"
    elif fType == uproot.const.kChar:
        return "b"
    elif fType in (uproot.const.kUChar, uproot.const.kCharStar):
        return "B"
    elif fType == uproot.const.kShort:
        return "h"
    elif fType == uproot.const.kUShort:
        return "H"
    elif fType == uproot.const.kInt:
        return "i"
    elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
        return "I"
    elif fType == uproot.const.kLong:
        return "l"
    elif fType == uproot.const.kULong:
        return "L"
    elif fType == uproot.const.kLong64:
        return "q"
    elif fType == uproot.const.kULong64:
        return "Q"
    elif fType in (uproot.const.kFloat, uproot.const.kFloat16):
        return "f"
    elif fType in (uproot.const.kDouble, uproot.const.kDouble32):
github scikit-hep / uproot / uproot / newrootio.py View on Github external
elif fType == uproot.const.kULong64:
                        dtypes[dtypename] = "numpy.dtype('>u8')"
                    elif fType in (uproot.const.kFloat, uproot.const.kFloat16):
                        dtypes[dtypename] = "numpy.dtype('>f4')"
                    elif fType in (uproot.const.kDouble, uproot.const.kDouble32):
                        dtypes[dtypename] = "numpy.dtype('>f8')"
                    else:
                        raise NotImplementedError(fType)
                    code.append("        self.{0} = cursor.array(source, self.{1}, self.{2})".format(name, counter, dtypename))

                elif isinstance(element, TStreamerBasicType):
                    if element.fArrayLength == 0:
                        basicnames.append("self." + element.fName.decode("ascii"))
                        if element.fType == uproot.const.kBool:
                            basicletters += "?"
                        elif element.fType == uproot.const.kChar:
                            basicletters += "b"
                        elif element.fType == uproot.const.kUChar:
                            basicletters += "B"
                        elif element.fType == uproot.const.kShort:
                            basicletters += "h"
                        elif element.fType == uproot.const.kUShort:
                            basicletters += "H"
                        elif element.fType == uproot.const.kInt:
                            basicletters += "i"
                        elif element.fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
                            basicletters += "I"
                        elif element.fType == uproot.const.kLong:
                            basicletters += "l"
                        elif element.fType == uproot.const.kULong:
                            basicletters += "L"
                        elif element.fType == uproot.const.kLong64:
github scikit-hep / uproot / uproot / write / objects / TObjString.py View on Github external
def _write(self, context, cursor, name, compression, key, keycursor, util):
        copy_cursor = copy(cursor)
        write_cursor = copy(cursor)
        cursor.skip(self._format.size)
        vers = 1
        buff = cursor.put_string(self.value)
        length = len(buff) + self._format.size
        cnt = numpy.int64(length - 4) | uproot.const.kByteCountMask
        givenbytes = copy_cursor.put_fields(self._format, cnt, vers, 1, 0, uproot.const.kNotDeleted) + buff
        uproot.write.compress.write(context, write_cursor, givenbytes, compression, key, keycursor)
github scikit-hep / uproot / uproot / rootio.py View on Github external
def _ftype2dtype(fType):
    if fType == uproot.const.kBool:
        return "numpy.dtype(numpy.bool_)"
    elif fType == uproot.const.kChar:
        return "numpy.dtype('i1')"
    elif fType in (uproot.const.kUChar, uproot.const.kCharStar):
        return "numpy.dtype('u1')"
    elif fType == uproot.const.kShort:
        return "numpy.dtype('>i2')"
    elif fType == uproot.const.kUShort:
        return "numpy.dtype('>u2')"
    elif fType == uproot.const.kInt:
        return "numpy.dtype('>i4')"
    elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
        return "numpy.dtype('>u4')"
    elif fType == uproot.const.kLong:
        return "numpy.dtype(numpy.long).newbyteorder('>')"
    elif fType == uproot.const.kULong:
        return "numpy.dtype('>u' + repr(numpy.dtype(numpy.long).itemsize))"
    elif fType == uproot.const.kLong64:
        return "numpy.dtype('>i8')"
    elif fType == uproot.const.kULong64:
        return "numpy.dtype('>u8')"
    elif fType in (uproot.const.kFloat, uproot.const.kFloat16):
        return "numpy.dtype('>f4')"
    elif fType in (uproot.const.kDouble, uproot.const.kDouble32):
        return "numpy.dtype('>f8')"
    else:
        return "None"
github scikit-hep / uproot / uproot / newrootio.py View on Github external
code.append("        {0} = cursor.fields(source, {1}._format{2})".format(", ".join(basicnames), classname, formatnum))

                            basicnames = []
                            basicletters = ""

                    else:
                        raise NotImplementedError(element.fArrayLength)

                elif isinstance(element, TStreamerLoop):
                    raise NotImplementedError

                elif isinstance(element, TStreamerObjectAnyPointer):
                    raise NotImplementedError

                elif isinstance(element, TStreamerObjectPointer):
                    if element.fType == uproot.const.kObjectp:
                        code.append("        {0} = {1}.read(source, cursor, context)".format(element.fName, element.fTypeName.rstrip("*")))
                    elif element.fType == uproot.const.kObjectP:
                        code.append("        {0} = _readanyref(source, cursor, context)".format(element.fName))
                    else:
                        raise NotImplementedError

                elif isinstance(element, TStreamerSTL):
                    raise NotImplementedError

                elif isinstance(element, TStreamerSTLString):
                    raise NotImplementedError

                elif isinstance(element, (TStreamerObject, TStreamerObjectAny, TStreamerString)):
                    code.append("        {0} = {1}.read(source, cursor, context)".format(element.fName, element.fTypeName))

                else:
github scikit-hep / uproot / uproot / interp / auto.py View on Github external
return awkward.numpy.dtype(awkward.numpy.bool_)
    elif fType == uproot.const.kChar:
        return awkward.numpy.dtype("i1")
    elif fType == uproot.const.kUChar:
        return awkward.numpy.dtype("u1")
    elif fType == uproot.const.kShort:
        return awkward.numpy.dtype(">i2")
    elif fType == uproot.const.kUShort:
        return awkward.numpy.dtype(">u2")
    elif fType == uproot.const.kInt:
        return awkward.numpy.dtype(">i4")
    elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
        return awkward.numpy.dtype(">u4")
    elif fType == uproot.const.kLong:
        return awkward.numpy.dtype(awkward.numpy.long).newbyteorder(">")
    elif fType == uproot.const.kULong:
        return awkward.numpy.dtype(">u" + repr(awkward.numpy.dtype(awkward.numpy.long).itemsize))
    elif fType == uproot.const.kLong64:
        return awkward.numpy.dtype(">i8")
    elif fType == uproot.const.kULong64:
        return awkward.numpy.dtype(">u8")
    elif fType == uproot.const.kFloat:
        return awkward.numpy.dtype(">f4")
    elif fType == uproot.const.kDouble:
        return awkward.numpy.dtype(">f8")
    else:
        raise _NotNumerical
github scikit-hep / uproot / uproot / newrootio.py View on Github external
fType = element.fType - uproot.const.kOffsetP

                    dtypename = "_dtype{0}".format(len(dtypes) + 1)
                    if fType == uproot.const.kBool:
                        dtypes[dtypename] = "numpy.dtype(numpy.bool_)"
                    elif fType == uproot.const.kChar:
                        dtypes[dtypename] = "numpy.dtype('i1')"
                    elif fType == uproot.const.kUChar:
                        dtypes[dtypename] = "numpy.dtype('u1')"
                    elif fType == uproot.const.kShort:
                        dtypes[dtypename] = "numpy.dtype('>i2')"
                    elif fType == uproot.const.kUShort:
                        dtypes[dtypename] = "numpy.dtype('>u2')"
                    elif fType == uproot.const.kInt:
                        dtypes[dtypename] = "numpy.dtype('>i4')"
                    elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
                        dtypes[dtypename] = "numpy.dtype('>u4')"
                    elif fType == uproot.const.kLong:
                        dtypes[dtypename] = "numpy.dtype(numpy.long).newbyteorder('>')"
                    elif fType == uproot.const.kULong:
                        dtypes[dtypename] = "numpy.dtype(numpy.ulong).newbyteorder('>')"
                    elif fType == uproot.const.kLong64:
                        dtypes[dtypename] = "numpy.dtype('>i8')"
                    elif fType == uproot.const.kULong64:
                        dtypes[dtypename] = "numpy.dtype('>u8')"
                    elif fType in (uproot.const.kFloat, uproot.const.kFloat16):
                        dtypes[dtypename] = "numpy.dtype('>f4')"
                    elif fType in (uproot.const.kDouble, uproot.const.kDouble32):
                        dtypes[dtypename] = "numpy.dtype('>f8')"
                    else:
                        raise NotImplementedError(fType)
                    code.append("        self.{0} = cursor.array(source, self.{1}, self.{2})".format(name, counter, dtypename))
github scikit-hep / uproot / uproot / interp / auto.py View on Github external
return awkward.numpy.dtype("u1")
    elif fType == uproot.const.kShort:
        return awkward.numpy.dtype(">i2")
    elif fType == uproot.const.kUShort:
        return awkward.numpy.dtype(">u2")
    elif fType == uproot.const.kInt:
        return awkward.numpy.dtype(">i4")
    elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
        return awkward.numpy.dtype(">u4")
    elif fType == uproot.const.kLong:
        return awkward.numpy.dtype(awkward.numpy.long).newbyteorder(">")
    elif fType == uproot.const.kULong:
        return awkward.numpy.dtype(">u" + repr(awkward.numpy.dtype(awkward.numpy.long).itemsize))
    elif fType == uproot.const.kLong64:
        return awkward.numpy.dtype(">i8")
    elif fType == uproot.const.kULong64:
        return awkward.numpy.dtype(">u8")
    elif fType == uproot.const.kFloat:
        return awkward.numpy.dtype(">f4")
    elif fType == uproot.const.kDouble:
        return awkward.numpy.dtype(">f8")
    else:
        raise _NotNumerical
github scikit-hep / uproot / uproot / newrootio.py View on Github external
dtypes[dtypename] = "numpy.dtype('u1')"
                    elif fType == uproot.const.kShort:
                        dtypes[dtypename] = "numpy.dtype('>i2')"
                    elif fType == uproot.const.kUShort:
                        dtypes[dtypename] = "numpy.dtype('>u2')"
                    elif fType == uproot.const.kInt:
                        dtypes[dtypename] = "numpy.dtype('>i4')"
                    elif fType in (uproot.const.kBits, uproot.const.kUInt, uproot.const.kCounter):
                        dtypes[dtypename] = "numpy.dtype('>u4')"
                    elif fType == uproot.const.kLong:
                        dtypes[dtypename] = "numpy.dtype(numpy.long).newbyteorder('>')"
                    elif fType == uproot.const.kULong:
                        dtypes[dtypename] = "numpy.dtype(numpy.ulong).newbyteorder('>')"
                    elif fType == uproot.const.kLong64:
                        dtypes[dtypename] = "numpy.dtype('>i8')"
                    elif fType == uproot.const.kULong64:
                        dtypes[dtypename] = "numpy.dtype('>u8')"
                    elif fType in (uproot.const.kFloat, uproot.const.kFloat16):
                        dtypes[dtypename] = "numpy.dtype('>f4')"
                    elif fType in (uproot.const.kDouble, uproot.const.kDouble32):
                        dtypes[dtypename] = "numpy.dtype('>f8')"
                    else:
                        raise NotImplementedError(fType)
                    code.append("        self.{0} = cursor.array(source, self.{1}, self.{2})".format(name, counter, dtypename))

                elif isinstance(element, TStreamerBasicType):
                    if element.fArrayLength == 0:
                        basicnames.append("self." + element.fName.decode("ascii"))
                        if element.fType == uproot.const.kBool:
                            basicletters += "?"
                        elif element.fType == uproot.const.kChar:
                            basicletters += "b"