Ejemplo n.º 1
0
    def test_pass_arguments_to_base_class(self):
        tree = MockTree(entries=1000)
        events = BEvents(tree, 100)
        self.assertEqual(100, events.nEvents)
        self.assertEqual(0, events.start)

        events = BEvents(tree, 100, 20)
        self.assertEqual(100, events.nEvents)
        self.assertEqual(20, events.start)
Ejemplo n.º 2
0
    def test_getattr_same_objects(self):
        tree = MockTree()
        events = BEvents(tree)
        branchBuilder = MockBranchBuilder()
        events.buildBranch = branchBuilder

        branch1 = MockBranch()
        branchBuilder.next = branch1
        jet_pt1 = events.jet_pt
        self.assertIs(branch1, jet_pt1)

        branch2 = MockBranch()
        branchBuilder.next = branch2
        jet_pt2 = events.jet_pt

        self.assertIs(branch1, jet_pt2)
        self.assertIsNot(branch2, jet_pt2)

        it = iter(events)
        event = next(it)

        branch3 = MockBranch()
        branchBuilder.next = branch3
        jet_pt3 = event.jet_pt

        self.assertIs(branch1, jet_pt3)
        self.assertIsNot(branch3, jet_pt3)
Ejemplo n.º 3
0
 def __call__(self):
     chain = ROOT.TChain(self.config.treeName)
     for path in self.config.inputPaths:
         path = convert_lfn_to_pfn_or_aaa(path)
         chain.Add(path)
     events = BEvents(chain, self.config.maxEvents, self.config.start)
     events.config = self.config
     return events
Ejemplo n.º 4
0
def use_BEvents():
    inputFile = ROOT.TFile.Open(inputPath)
    tree = inputFile.Get(treeName)
    events = BEvents(tree)
    jet_pt = events.jet_pt
    for event in events:
        for i in range(len(jet_pt)):
            jet_pt[i]
Ejemplo n.º 5
0
    def test_getattr(self):
        tree = MockTree()
        events = BEvents(tree)
        branchBuilder = MockBranchBuilder()
        events.buildBranch = branchBuilder

        branchBuilder.next = MockBranch()
        jet_pt = events.jet_pt
        self.assertIsInstance(jet_pt, MockBranch)
Ejemplo n.º 6
0
def use_BEvents():
    inputFile = ROOT.TFile.Open(inputPath)
    tree = inputFile.Get(treeName)
    events = BEvents(tree)
    jet_pt = events.jet_pt
    trigger_path = events.trigger_path
    trigger_version = events.trigger_version
    for event in events:
        for i in range(len(jet_pt)):
            jet_pt[i]
Ejemplo n.º 7
0
    def test_getattr_getentry(self):
        tree = MockTree()
        events = BEvents(tree, start=10)
        branchBuilder = MockBranchBuilder()
        events.buildBranch = branchBuilder

        self.assertEqual(-1, events.iEvent)
        self.assertEqual(-1, tree.ievent)
        self.assertFalse(tree.getEntry_called)
        branchBuilder.next = MockBranch()
        jet_pt = events.jet_pt
        self.assertFalse(tree.getEntry_called)

        it = iter(events)
        event = next(it)
        tree.getEntry_called = False
        self.assertEqual(0, events.iEvent)
        self.assertEqual(10, tree.ievent)
        self.assertFalse(tree.getEntry_called)
        jet_pt = event.jet_pt
        self.assertFalse(tree.getEntry_called)

        tree.getEntry_called = False
        met_pt = event.met_pt
        self.assertTrue(tree.getEntry_called)
        self.assertEqual(0, events.iEvent)
        self.assertEqual(10, tree.ievent)

        event = next(it)
        tree.getEntry_called = False
        self.assertEqual(1, events.iEvent)
        self.assertEqual(11, tree.ievent)
        self.assertFalse(tree.getEntry_called)
        jet_pt = event.jet_pt
        self.assertFalse(tree.getEntry_called)

        tree.getEntry_called = False
        met_pt = event.met_pt
        self.assertFalse(tree.getEntry_called)
        self.assertEqual(1, events.iEvent)
        self.assertEqual(11, tree.ievent)

        tree.getEntry_called = False
        njets = event.njets
        self.assertTrue(tree.getEntry_called)
        self.assertEqual(1, events.iEvent)
        self.assertEqual(11, tree.ievent)
Ejemplo n.º 8
0
 def test_init_branch_status(self):
     tree = MockTree()
     self.assertEqual([], tree.branchstatus)
     events = BEvents(tree)
     events.buildBranch = MockBranchBuilder()
     self.assertEqual([('*', 0)], tree.branchstatus)
Ejemplo n.º 9
0
 def test_repr(self):
     tree = MockTree()
     events = BEvents(tree)
     repr(events)
Ejemplo n.º 10
0
    def test_getattr_exception(self):
        tree = MockTree()
        events = BEvents(tree)
        events.buildBranch = MockBranchBuilder()

        self.assertRaises(AttributeError, events.__getattr__, 'no_such_branch')