DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dal_helpers Namespace Reference

Functions

 get_attribute_info (o)
 Dal helpers.
 
 get_relation_info (o)
 
 get_attribute_list (o)
 
 get_relation_list (o)
 
 get_superclass_list (o)
 
 get_subclass_list (o)
 
 compare_dal_obj (a, b)
 
 find_related (dal_obj, set dal_group)
 
 find_duplicates (Iterable collection)
 

Detailed Description

 

Function Documentation

◆ compare_dal_obj()

dal_helpers.compare_dal_obj ( a,
b )
Compare two dal objects by content

Definition at line 24 of file dal_helpers.py.

24def 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#---------------

◆ find_duplicates()

dal_helpers.find_duplicates ( Iterable collection)
Find duplicated dal objects in a collection by comparing objects attributes and relationships

Definition at line 74 of file dal_helpers.py.

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

◆ find_related()

dal_helpers.find_related ( dal_obj,
set dal_group )

Definition at line 48 of file dal_helpers.py.

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

◆ get_attribute_info()

dal_helpers.get_attribute_info ( o)

Dal helpers.

Definition at line 6 of file dal_helpers.py.

6def get_attribute_info(o):
7 return o.__schema__['attribute']
8

◆ get_attribute_list()

dal_helpers.get_attribute_list ( o)

Definition at line 12 of file dal_helpers.py.

12def get_attribute_list(o):
13 return list(get_attribute_info(o))
14

◆ get_relation_info()

dal_helpers.get_relation_info ( o)

Definition at line 9 of file dal_helpers.py.

9def get_relation_info(o):
10 return o.__schema__['relation']
11

◆ get_relation_list()

dal_helpers.get_relation_list ( o)

Definition at line 15 of file dal_helpers.py.

15def get_relation_list(o):
16 return list(get_relation_info(o))
17

◆ get_subclass_list()

dal_helpers.get_subclass_list ( o)

Definition at line 21 of file dal_helpers.py.

21def get_subclass_list(o):
22 return o.__schema__['subclass']
23

◆ get_superclass_list()

dal_helpers.get_superclass_list ( o)

Definition at line 18 of file dal_helpers.py.

18def get_superclass_list(o):
19 return o.__schema__['superclass']
20