def test_papasevent(self): #create a dummy papasevent papasevent = PapasEvent(0) ecals = dict() tracks = dict() mixed = dict() for i in range(0, 2): uid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, i, 't', 4.5) ecals[uid] = uid papasevent.history[uid] = Node(uid) uidt = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, i, 's', 4.5) tracks[uidt] = uidt papasevent.history[uidt] = Node(uidt) papasevent.history[uidt].add_child(papasevent.history[uid]) lastid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, 3, 't', 3) ecals[lastid] = lastid papasevent.history[lastid] = Node(lastid) papasevent.add_collection(ecals) papasevent.add_collection(tracks) #create HistoryHelper hhelper = HistoryHelper(papasevent) #get all ids in event ids = hhelper.event_ids() self.assertTrue(len(ids) == 5) #check id_from_pretty self.assertTrue(hhelper.id_from_pretty('et3') == lastid) #check get_linked_ids linked = hhelper.get_linked_ids(lastid) #everything linked to lastid (which is just lastid) self.assertTrue(linked[0] == lastid and len(linked) == 1) self.assertTrue( hhelper.get_linked_ids( ids[0], direction="undirected")[1] == hhelper.id_from_pretty('ts0')) self.assertTrue( hhelper.get_linked_ids( ids[0], direction="parents")== hhelper.get_linked_ids( ids[0], direction="undirected")) self.assertTrue( hhelper.get_linked_ids(ids[0], direction="children") == [hhelper.id_from_pretty('et0')]) #filter_ids self.assertTrue( len(hhelper.filter_ids(ids, 'ts')) == 2) self.assertTrue( hhelper.filter_ids(ids, 'no') == []) #get_collection self.assertTrue( len( hhelper.get_collection(ids[1:2], 'no')) == 0) self.assertTrue( len( hhelper.get_collection([99], 'no')) == 0) self.assertTrue( len(hhelper.get_collection(ids[0:2], 'ts')) == 1) pass #get_history_subgroups subgroups = hhelper.get_history_subgroups() self.assertTrue(len(subgroups) == 3) #get_linked_collection self.assertTrue(hhelper.get_linked_collection( hhelper.id_from_pretty('et0'), 'ts').keys() == [hhelper.id_from_pretty('ts0')]) self.assertRaises(KeyError, hhelper.get_linked_collection, 0, 'ts') self.assertTrue(len(hhelper.get_linked_collection( hhelper.id_from_pretty('et0'), 'no')) == 0)
def test_identifier(self): Identifier.reset() uid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, 's', 1.23456) id1 = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, 's', 12.782) self.assertTrue (Identifier.pretty(id1) == 'ts2') ids = [] for i in range(-2, 2): uid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, 's', 2**(i) ) ids.append(uid) ids = sorted(ids, reverse = True) self.assertTrue(Identifier.pretty(ids[0]) == 'ts6') self.assertTrue(Identifier.get_value(ids[0]) == 2.0) self.assertTrue(Identifier.pretty(ids[3]) == 'ts3') self.assertTrue(Identifier.get_value(ids[3]) == 0.25)
def test_identifier(self): Identifier.reset() uid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, 0, 's', 1.23456) id1 = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, 1, 's', 12.782) self.assertTrue(Identifier.pretty(id1) == 'ts1') ids = [] for i in range(0, 5): uid = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, i, 's', 2**(i - 2)) ids.append(uid) ids = sorted(ids, reverse=True) self.assertTrue(Identifier.pretty(ids[0]) == 'ts4') self.assertTrue(Identifier.get_value(ids[0]) == 4.0) self.assertTrue(Identifier.pretty(ids[3]) == 'ts1') self.assertTrue(Identifier.get_value(ids[3]) == 0.5)
def test_papasevent(self): #create a dummy papasevent papasevent = PapasEvent(0) ecals = dict() tracks = dict() mixed = dict() for i in range(0, 2): uid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, 't', 4.5) ecals[uid] = uid papasevent.history[uid] = Node(uid) uidt = Identifier.make_id(Identifier.PFOBJECTTYPE.TRACK, 's', 4.5) tracks[uidt] = uidt papasevent.history[uidt] = Node(uidt) papasevent.history[uidt].add_child(papasevent.history[uid]) lastid = Identifier.make_id(Identifier.PFOBJECTTYPE.ECALCLUSTER, 't', 3) ecals[lastid] = lastid papasevent.history[lastid] = Node(lastid) papasevent.add_collection(ecals) papasevent.add_collection(tracks) #create HistoryHelper hhelper = HistoryHelper(papasevent) #get all ids in event ids = hhelper.event_ids() self.assertTrue(len(ids) == 5) #check id_from_pretty self.assertTrue(hhelper.id_from_pretty('et5') == lastid) #check get_linked_ids linked = hhelper.get_linked_ids( lastid) #everything linked to lastid (which is just lastid) self.assertTrue(linked[0] == lastid and len(linked) == 1) self.assertTrue( hhelper.get_linked_ids(ids[0], direction="undirected")[1] == hhelper.id_from_pretty('ts2')) self.assertTrue( hhelper.get_linked_ids(ids[0], direction="parents") == hhelper.get_linked_ids(ids[0], direction="undirected")) self.assertTrue( hhelper.get_linked_ids(ids[0], direction="children") == [hhelper.id_from_pretty('et1')]) #filter_ids self.assertTrue(len(hhelper.filter_ids(ids, 'ts')) == 2) self.assertTrue(hhelper.filter_ids(ids, 'no') == []) #get_collection self.assertTrue(len(hhelper.get_collection(ids[1:2], 'no')) == 0) self.assertTrue(len(hhelper.get_collection([99], 'no')) == 0) self.assertTrue(len(hhelper.get_collection(ids[0:2], 'ts')) == 1) pass #get_history_subgroups subgroups = hhelper.get_history_subgroups() self.assertTrue(len(subgroups) == 3) #get_linked_collection self.assertTrue( hhelper.get_linked_collection(hhelper.id_from_pretty( 'et1'), 'ts').keys() == [hhelper.id_from_pretty('ts2')]) self.assertRaises(KeyError, hhelper.get_linked_collection, 0, 'ts') self.assertTrue( len( hhelper.get_linked_collection(hhelper.id_from_pretty('et1'), 'no')) == 0)