Beispiel #1
0
def create_tree():

    f = TemporaryFile()
    tree = Tree("tree", model=create_model())
    # fill the tree
    for i in xrange(1000):
        assert_equal(tree.a_vect, LorentzVector(0, 0, 0, 0))
        random_vect = LorentzVector(gauss(.5, 1.), gauss(.5, 1.),
                                    gauss(.5, 1.), gauss(.5, 1.))
        tree.a_vect.copy_from(random_vect)
        assert_equal(tree.a_vect, random_vect)
        tree.a_x = gauss(.5, 1.)
        tree.a_y = gauss(.3, 2.)
        tree.a_z = gauss(13., 42.)
        tree.b_n = randint(1, 5)
        for j in xrange(tree.b_n):
            vect = LorentzVector(gauss(.5, 1.), gauss(.5, 1.), gauss(.5, 1.),
                                 gauss(.5, 1.))
            tree.b_vect.push_back(vect)
            tree.b_x.push_back(randint(1, 10))
            tree.b_y.push_back(gauss(.3, 2.))
        tree.i = i
        assert_equal(tree.b_n, tree.b_vect.size())
        assert_equal(tree.b_n, tree.b_x.size())
        assert_equal(tree.b_n, tree.b_y.size())
        tree.fill(reset=True)
    tree.write()
    # TFile.Close the file but keep the underlying
    # tempfile file descriptor open
    ROOT.TFile.Close(f)
    FILES.append(f)
    FILE_PATHS.append(f.GetName())
Beispiel #2
0
def test_file():

    f = TemporaryFile()
    assert_raises(DoesNotExist, f.Get, 'blah')
    hist = Hist(1, 0, 1, name='test')
    hist.Write()
    hist2 = f.test
    assert hist2.__class__ == hist.__class__
    os.unlink(f.GetName())
Beispiel #3
0
    def setup_class(cls):
        class ObjectA(TreeModel):
            # A simple tree object
            x = FloatCol()
            y = FloatCol()
            z = FloatCol()

        class ObjectB(TreeModel):
            # A tree object collection
            x = stl.vector('int')
            y = stl.vector('float')
            vect = stl.vector('TLorentzVector')
            # collection size
            n = IntCol()

        class Event(ObjectA.prefix('a_') + ObjectB.prefix('b_')):
            i = IntCol()

        for i in range(5):
            f = TemporaryFile()
            tree = Tree("tree", model=Event)
            # fill the tree
            for i in xrange(10000):
                tree.a_x = gauss(.5, 1.)
                tree.a_y = gauss(.3, 2.)
                tree.a_z = gauss(13., 42.)
                tree.b_vect.clear()
                tree.b_x.clear()
                tree.b_y.clear()
                tree.b_n = randint(1, 5)
                for j in xrange(tree.b_n):
                    vect = LorentzVector(gauss(.5, 1.), gauss(.5, 1.),
                                         gauss(.5, 1.), gauss(.5, 1.))
                    tree.b_vect.push_back(vect)
                    tree.b_x.push_back(randint(1, 10))
                    tree.b_y.push_back(gauss(.3, 2.))
                tree.i = i
                tree.fill()
            tree.write()
            # TFile.Close the file but keep the underlying
            # tempfile file descriptor open
            ROOT.TFile.Close(f)
            cls.files.append(f)
            cls.file_paths.append(f.GetName())