DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dal_helpers.py
Go to the documentation of this file.
1"""
2"""
3
7 return o.__schema__['attribute']
8
10 return o.__schema__['relation']
11
13 return list(get_attribute_info(o))
14
16 return list(get_relation_info(o))
17
19 return o.__schema__['superclass']
20
22 return o.__schema__['subclass']
23
25 """Compare two dal objects by content"""
26
27 # TODO: add a check on a and b being dal objects
28 # There is no base class for dal objects in python, but dal objects have _shcema__objects.
29
30
31 if a.className() != b.className():
32 return False
33
34 attrs = get_attribute_list(a)
35 rels = get_relation_list(a)
36
37 a_attrs = {x:getattr(a, x) for x in attrs}
38 b_attrs = {x:getattr(b, x) for x in attrs}
39
40 a_rels = {x:getattr(a, x) for x in rels}
41 b_rels = {x:getattr(b, x) for x in rels}
42
43
44 return (a_attrs == b_attrs) and (a_rels == b_rels)
45
46
47#---------------
48def find_related(dal_obj, dal_group: set):
49
50
51 rels = get_relation_list(dal_obj)
52
53 rel_objs = set()
54 for rel in rels:
55 rel_val = getattr(dal_obj, rel)
56
57 if rel_val is None:
58 continue
59
60 rel_objs.update(rel_val if isinstance(rel_val,list) else [rel_val])
61
62 # Isolate relationship objects that are not in the dal_group yet
63 new_rel_objs = rel_objs - dal_group
64
65 # Safely add the new object to the group
66 dal_group.update(rel_objs)
67 for o in new_rel_objs:
68 if o is None:
69 continue
70
71 find_related(o, dal_group)
72
73from collections.abc import Iterable
74def find_duplicates( collection: Iterable ):
75 """
76 Find duplicated dal objects in a collection by comparing objects attributes and relationships
77 """
78
79 n_items = len(collection)
80 duplicates = set()
81 for i in range(n_items):
82 for j in range(i+1, n_items):
83 if compare_dal_obj(collection[i], collection[j]):
84 duplicates.add(collection[i])
85 duplicates.add(collection[j])
86
87 return duplicates
88
get_subclass_list(o)
find_duplicates(Iterable collection)
get_attribute_info(o)
Dal helpers.
Definition dal_helpers.py:6
get_relation_info(o)
Definition dal_helpers.py:9
get_relation_list(o)
get_superclass_list(o)
compare_dal_obj(a, b)
find_related(dal_obj, set dal_group)
get_attribute_list(o)