Ejemplo n.º 1
0
 def test_serialization_asobj(self):
     self.roundtrip_interp(
         uproot.asobj(
             uproot.astable(
                 uproot.asdtype([("fX", ">f8"), ("fY", ">f8"),
                                 ("fZ", ">f8"), ("fE", ">f8")])),
             uproot_methods.classes.TLorentzVector.Methods))
     self.roundtrip_interp(
         uproot.asjagged(
             uproot.asobj(
                 uproot.astable(
                     uproot.asdtype([("fX", ">f8"), ("fY", ">f8"),
                                     ("fZ", ">f8"), ("fE", ">f8")])),
                 uproot_methods.classes.TLorentzVector.Methods), 10))
Ejemplo n.º 2
0
 def test_issue434(self):
     f = uproot.open("tests/samples/issue434.root")
     fromdtype = [("pmt", "u1"), ("tdc", "<u4"), ("tot", "u1")]
     todtype = [("pmt", "u1"), ("tdc", ">u4"), ("tot", "u1")]
     tree = f[b'KM3NET_TIMESLICE_L1'][b'KM3NETDAQ::JDAQTimeslice']
     superframes = tree[b'vector<KM3NETDAQ::JDAQSuperFrame>']
     hits_buffer = superframes[b'vector<KM3NETDAQ::JDAQSuperFrame>.buffer']
     hits = hits_buffer.lazyarray(
         uproot.asjagged(uproot.astable(uproot.asdtype(fromdtype, todtype)),
                         skipbytes=6))
     assert 486480 == hits['tdc'][0][0]
Ejemplo n.º 3
0
    def test_serialization_dataset(self):
        from uproot_skyhook.layout import zlib, Branch, File, Column, Dataset
        from uproot import asdtype, asjagged, asstlbitset

        branch1 = Branch([0, 100, 1000], [123, 1234], zlib, [True, False],
                         [100, 100], [200, 200], [0, 1, 2], [12, 13], None)
        branch2 = Branch([0, 1000], [12345], zlib, [True], [100], [200],
                         [0, 1], [12], None)
        branch3 = Branch([0, 100, 1000], [123456, 1234567], zlib,
                         [False, True], [100, 100], [200, 200], [0, 1, 2],
                         [12, 13], [125, 150])

        branch4 = Branch([0, 100, 1000], [123, 1234], zlib, [True, False],
                         [100, 100], [200, 200], [0, 1, 2], [12, 13], None)
        branch5 = Branch([0, 1000], [12345], zlib, [True], [100], [200],
                         [0, 1], [12], None)
        branch6 = Branch([0, 100, 1000], [123456, 1234567], zlib,
                         [False, True], [100, 100], [200, 200], [0, 1, 2],
                         [12, 13], [125, 150])

        files = [
            File("file1", b"abbacdbad", [branch1, branch2, branch3]),
            File("file2", b"decafcafe", [branch4, branch5, branch6])
        ]

        colnames = ["one", "two", "three"]
        columns = [
            Column(asdtype(float)),
            Column(asjagged(asdtype(int))),
            Column(asstlbitset(17))
        ]

        dataset = Dataset("dataset", "treepath", colnames, columns, files,
                          [0, 1000, 2000], "location_prefix")
        serialized = uproot_skyhook.layout.tobuffer(dataset)
        deserialized = uproot_skyhook.layout.frombuffer(serialized)
        assert deserialized == dataset
Ejemplo n.º 4
0
    def test_issue429(self):
        if sys.version_info[0] >= 3:
            fix = lambda name: name.decode("utf-8")
        else:
            fix = lambda name: name

        file = uproot.open("tests/samples/issue429.root")
        tree = file["data_tr"]
        branch = tree["data_ana_kk"]
        # FIXME: how can uproot.interp.auto.interpret *infer* the 4 bytes of padding?
        dtype = [(fix(x._fName),
                  "float32" if type(x).__name__ == "TLeafF" else "int32")
                 for x in branch._fLeaves]
        array = branch.array(uproot.asdtype(dtype + [("padding", "S4")]))
        assert (array["padding"] == b"\xff\xff\xff\xff").all()
Ejemplo n.º 5
0
    def test_serialization_asdtype_flat(self):
        self.roundtrip_interp(uproot.asdtype(numpy.bool_))
        self.roundtrip_interp(uproot.asdtype("i1"))
        self.roundtrip_interp(uproot.asdtype("<i2"))
        self.roundtrip_interp(uproot.asdtype(">i2"))
        self.roundtrip_interp(uproot.asdtype("<i4"))
        self.roundtrip_interp(uproot.asdtype(">i4"))
        self.roundtrip_interp(uproot.asdtype("<i8"))
        self.roundtrip_interp(uproot.asdtype(">i8"))
        self.roundtrip_interp(uproot.asdtype("u1"))
        self.roundtrip_interp(uproot.asdtype("<u2"))
        self.roundtrip_interp(uproot.asdtype(">u2"))
        self.roundtrip_interp(uproot.asdtype("<u4"))
        self.roundtrip_interp(uproot.asdtype(">u4"))
        self.roundtrip_interp(uproot.asdtype("<u8"))
        self.roundtrip_interp(uproot.asdtype(">u8"))
        self.roundtrip_interp(uproot.asdtype("<f4"))
        self.roundtrip_interp(uproot.asdtype(">f4"))
        self.roundtrip_interp(uproot.asdtype("<f8"))
        self.roundtrip_interp(uproot.asdtype(">f8"))

        self.roundtrip_interp(uproot.asdtype(numpy.bool_, "i1"))
        self.roundtrip_interp(uproot.asdtype("i1", numpy.bool_))
        self.roundtrip_interp(uproot.asdtype("<i2", "<u2"))
        self.roundtrip_interp(uproot.asdtype(">i2", ">u2"))
        self.roundtrip_interp(uproot.asdtype("<i4", "<u4"))
        self.roundtrip_interp(uproot.asdtype(">i4", ">u4"))
        self.roundtrip_interp(uproot.asdtype("<i8", "<u8"))
        self.roundtrip_interp(uproot.asdtype(">i8", ">u8"))
        self.roundtrip_interp(uproot.asdtype("u1", "i1"))
        self.roundtrip_interp(uproot.asdtype("<u2", "<i2"))
        self.roundtrip_interp(uproot.asdtype(">u2", ">i2"))
        self.roundtrip_interp(uproot.asdtype("<u4", "<i4"))
        self.roundtrip_interp(uproot.asdtype(">u4", ">i4"))
        self.roundtrip_interp(uproot.asdtype("<u8", "<i8"))
        self.roundtrip_interp(uproot.asdtype(">u8", ">i8"))
        self.roundtrip_interp(uproot.asdtype("<f4", "<i4"))
        self.roundtrip_interp(uproot.asdtype(">f4", ">i4"))
        self.roundtrip_interp(uproot.asdtype("<f8", "<u8"))
        self.roundtrip_interp(uproot.asdtype(">f8", ">u8"))

        self.roundtrip_interp(uproot.asdtype((numpy.bool_, 10)))
        self.roundtrip_interp(uproot.asdtype(("i1", 10)))
        self.roundtrip_interp(uproot.asdtype(("<i2", 10)))
        self.roundtrip_interp(uproot.asdtype((">i2", 10)))
        self.roundtrip_interp(uproot.asdtype(("<i4", 10)))
        self.roundtrip_interp(uproot.asdtype((">i4", 10)))
        self.roundtrip_interp(uproot.asdtype(("<i8", 10)))
        self.roundtrip_interp(uproot.asdtype((">i8", 10)))
        self.roundtrip_interp(uproot.asdtype(("u1", 10)))
        self.roundtrip_interp(uproot.asdtype(("<u2", 10)))
        self.roundtrip_interp(uproot.asdtype((">u2", 10)))
        self.roundtrip_interp(uproot.asdtype(("<u4", 10)))
        self.roundtrip_interp(uproot.asdtype((">u4", 10)))
        self.roundtrip_interp(uproot.asdtype(("<u8", 10)))
        self.roundtrip_interp(uproot.asdtype((">u8", 10)))
        self.roundtrip_interp(uproot.asdtype(("<f4", 10)))
        self.roundtrip_interp(uproot.asdtype((">f4", 10)))
        self.roundtrip_interp(uproot.asdtype(("<f8", 10)))
        self.roundtrip_interp(uproot.asdtype((">f8", 10)))

        self.roundtrip_interp(uproot.asdtype((numpy.bool_, (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("i1", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<i2", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">i2", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<i4", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">i4", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<i8", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">i8", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("u1", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<u2", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">u2", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<u4", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">u4", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<u8", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">u8", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<f4", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">f4", (10, 20))))
        self.roundtrip_interp(uproot.asdtype(("<f8", (10, 20))))
        self.roundtrip_interp(uproot.asdtype((">f8", (10, 20))))

        self.roundtrip_interp(
            uproot.asdtype((numpy.bool_, (10, 20)), (numpy.bool_, (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("i1", (10, 20)), ("i1", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<i2", (10, 20)), ("<i2", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">i2", (10, 20)), (">i2", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<i4", (10, 20)), ("<i4", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">i4", (10, 20)), (">i4", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<i8", (10, 20)), ("<i8", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">i8", (10, 20)), (">i8", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("u1", (10, 20)), ("u1", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<u2", (10, 20)), ("<u2", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">u2", (10, 20)), (">u2", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<u4", (10, 20)), ("<u4", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">u4", (10, 20)), (">u4", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<u8", (10, 20)), ("<u8", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">u8", (10, 20)), (">u8", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<f4", (10, 20)), ("<f4", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">f4", (10, 20)), (">f4", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype(("<f8", (10, 20)), ("<f8", (20, 10))))
        self.roundtrip_interp(
            uproot.asdtype((">f8", (10, 20)), (">f8", (20, 10))))
Ejemplo n.º 6
0
 def test_serialization_asjagged(self):
     self.roundtrip_interp(uproot.asjagged(uproot.asdtype("f4")))
     self.roundtrip_interp(
         uproot.asjagged(uproot.asdtype("f4"), skipbytes=10))
Ejemplo n.º 7
0
 def test_serialization_asdtype_record(self):
     self.roundtrip_interp(
         uproot.asdtype([("one", int), ("two", float), ("three", bool)]))
Ejemplo n.º 8
0
def recursive_type_wrap(array):
    if isinstance(array, awkward.JaggedArray):
        return asjagged(recursive_type_wrap(array.content))
    return asdtype(array.dtype.fields)
Ejemplo n.º 9
0
for i in range(5):
    result = root_numpy.tree2array(tree,
                                   "branch",
                                   start=branch.basket_entrystart(i),
                                   stop=branch.basket_entrystop(i))
walltime = time.time() - starttime
print("TTree root_numpy jagged2\t", walltime, "sec;\t", num / walltime / 1e6,
      "million floats/sec")

num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged3.root")["jagged3"]["branch"]
for i in range(5):
    jagged = branch.basket(
        i,
        asgenobj(STLVector(STLVector(STLVector(asdtype(">f4")))),
                 branch._context, 6))
    q = awkward.fromiter(jagged)
    num += len(q.content.content.content)
walltime = time.time() - starttime
print("TTree OLD jagged3\t", walltime, "sec;\t", num / walltime / 1e6,
      "million floats/sec")

num = 0
starttime = time.time()
branch = uproot.open("data/sample-jagged3.root")["jagged3"]["branch"]
for i in range(5):
    jagged = branch.basket(i, uproot.asdebug)
    byteoffsets = awkward1.layout.Index64(jagged.offsets)
    rawdata = awkward1.layout.NumpyArray(jagged.content[6:])
    result = awkward1.layout.fromroot_nestedvector(byteoffsets, rawdata, 3,