DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
dal_helpers.py
Go to the documentation of this file.
1
"""
2
"""
3
6
def
get_attribute_info
(o):
7
return
o.__schema__[
'attribute'
]
8
9
def
get_relation_info
(o):
10
return
o.__schema__[
'relation'
]
11
12
def
get_attribute_list
(o):
13
return
list(
get_attribute_info
(o))
14
15
def
get_relation_list
(o):
16
return
list(
get_relation_info
(o))
17
18
def
get_superclass_list
(o):
19
return
o.__schema__[
'superclass'
]
20
21
def
get_subclass_list
(o):
22
return
o.__schema__[
'subclass'
]
23
24
def
compare_dal_obj
(a, b):
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
#---------------
48
def
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
73
from
collections.abc
import
Iterable
74
def
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
dal_helpers.get_relation_info
get_relation_info(o)
Definition
dal_helpers.py:9
dal_helpers.compare_dal_obj
compare_dal_obj(a, b)
Definition
dal_helpers.py:24
dal_helpers.get_attribute_info
get_attribute_info(o)
Dal helpers.
Definition
dal_helpers.py:6
dal_helpers.find_related
find_related(dal_obj, set dal_group)
Definition
dal_helpers.py:48
dal_helpers.get_attribute_list
get_attribute_list(o)
Definition
dal_helpers.py:12
dal_helpers.find_duplicates
find_duplicates(Iterable collection)
Definition
dal_helpers.py:74
dal_helpers.get_subclass_list
get_subclass_list(o)
Definition
dal_helpers.py:21
dal_helpers.get_relation_list
get_relation_list(o)
Definition
dal_helpers.py:15
dal_helpers.get_superclass_list
get_superclass_list(o)
Definition
dal_helpers.py:18
Generated on
for DUNE-DAQ by
1.17.0