DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
daqconf
python
daqconf
validate.py
Go to the documentation of this file.
1
import
conffwk
2
import
confmodel_dal
3
4
5
def
compare_objects
(obj1, obj2):
6
""" Compare 2 dal objects for equality attribute by attribute """
7
same =
True
8
if
type(obj1) != type(obj2):
9
print
(f
"ERROR objects are not the same type {type(obj1)} != {type(obj2)}"
)
10
return
False
11
12
ign=[
'__id'
,
'__fullname__'
,
'__hashvalue__'
,
'__touched__'
]
13
14
d1 = obj1.__dict__
15
d2 = obj2.__dict__
16
for
key
in
d1:
17
if
key
in
ign:
18
continue
19
if
key
in
d2:
20
#print (f" Comparing {obj1.id}[{key}] ({d1[key]}) with {obj2.id}[{key}] ({d2[key]})")
21
22
if
d1[key] != d2[key]:
23
#print (f" difference {obj1.id}[{d1[key]}] != {obj2.id}[{d2[key]}]")
24
same=
False
25
break
26
else
:
27
print
(f
"Error attribute names {key} not common"
)
28
same=
False
29
break
30
return
same
31
32
33
34
def
check_unique_relationship
(objects, relationship):
35
"""
36
Check to see if the given relationship (by class name) is unique
37
among a list of objects. First by comparing the UIDs, then by
38
comparing the values within.
39
"""
40
41
seen = []
42
seen_id = {}
43
unique =
True
44
for
obj
in
objects:
45
print(f
"Checking {obj.id}"
)
46
rel = obj.get(relationship)
47
if
len(rel) < 1:
48
print(f
"No object found for relationship {relationship} in {obj.id}"
)
49
continue
50
#print (f"Found {len(rel)} objects of type {relationship} in {obj.id}")
51
for
val
in
rel:
52
if
val.id
in
seen_id:
53
print
(
54
f
"ERROR {obj.id}: {val.className()} {val.id} already seen in {seen_id[val.id]}"
)
55
unique =
False
56
else
:
57
for
other
in
seen:
58
#print (f" Checking {val.id}=={other.id}?")
59
if
compare_objects
(val, other):
60
print
(f
"object {obj.id} {val.id} is same as {other.id}"
)
61
unique =
False
62
if
not
unique:
63
break
64
seen.append(val)
65
seen_id[val.id] = obj.id
66
return
unique
67
68
69
def
validate_readout
(db, session):
70
errcount = 0
71
# Find all enabled readout apps and check that
72
# DetectorToDaqConnection's are unique
73
ru_apps = []
74
for
app
in
confmodel_dal.session_get_all_applications(db._obj, session.id):
75
if
confmodel_dal.component_disabled(db._obj, session.id, app.id):
76
continue
77
78
app_dal = db.get_dal(app.class_name, app.id)
79
if
"ReadoutApplication"
in
app_dal.oksTypes():
80
ru_apps.append(app_dal)
81
82
if
len(ru_apps) == 0:
83
print(f
"No enabled readout applicatios in session"
)
84
errcount += 1
85
d2d_seen = {}
86
d2d_dals = []
87
snd_dals = []
88
senders_seen = {}
89
for
ru
in
ru_apps:
90
connections = 0
91
for
d2d
in
ru.detector_connections:
92
if
d2d.id
in
d2d_seen:
93
print(f
"Error {ru.id} contains {d2d.id}"
+
94
f
" which is already read out by {d2d_seen[d2d.id]}"
)
95
errcount += 1
96
continue
97
98
senders = 0
99
for
sndr
in
confmodel_dal.d2d_senders(db._obj, d2d.id):
100
if
sndr
in
senders_seen:
101
print(f
"Error sender {sndr.id} already seen in {senders_seen[sndr.id]}"
)
102
errcount += 1
103
continue
104
senders_seen[sndr] = d2d.id
105
snd_dals.append(db.get_dal(
"DetDataSender"
, sndr))
106
senders += 1
107
if
senders == 0:
108
print(f
"Error {d2d.id} does not have any senders"
)
109
errcount += 1
110
continue
111
if
confmodel_dal.d2d_receiver(db._obj, d2d.id) ==
""
:
112
print(f
"Error {d2d.id} does not have a receiver"
)
113
errcount += 1
114
continue
115
d2d_seen[d2d.id] = ru.id
116
d2d_dals.append(d2d)
117
connections += 1
118
if
connections == 0:
119
print(f
"Error {ru.id} contains 0 detector connections"
)
120
errcount += 1
121
122
print
(f
"\nChecking data senders for duplicate streams"
);
123
if
not
check_unique_relationship
(snd_dals,
"DetectorStream"
):
124
errcount += 1
125
126
print
(f
"\nChecking detector connections for duplicate geio ids"
)
127
if
not
check_unique_relationship
(d2d_dals,
"GeoId"
):
128
errcount += 1
129
130
print
(f
"Session {session.id} readout validated with {errcount} errors:"
+
131
f
" contains {len(d2d_seen)} Detector connections"
+
132
f
" in {len(ru_apps)} readout applications"
)
133
134
return
errcount
135
136
def
validate_session
(oksfile, session_name):
137
db =
conffwk.Configuration
(
"oksconflibs:"
+ oksfile)
138
if
session_name ==
""
:
139
session_dals = db.get_dals(class_name=
"Session"
)
140
if
len(session_dals) == 0:
141
print(f
"Error could not find any Session in file {oksfile}"
)
142
return
143
if
len(session_dals) > 1:
144
print(f
"Warning: more than one Session found in database."
145
" Using the first one found"
)
146
session = session_dals[0]
147
else
:
148
try
:
149
session = db.get_dal(
"Session"
, session_name)
150
except
:
151
print(f
"Error could not find Session {session_name} in file {oksfile}"
)
152
return
153
154
print(f
"Validating session {session.id}:"
)
155
errcount =
validate_readout
(db, session)
156
print
(f
"\nSession {session.id} validated with {errcount} errors"
)
conffwk.Configuration.Configuration
Definition
Configuration.py:29
validate.validate_session
validate_session(oksfile, session_name)
Definition
validate.py:136
validate.check_unique_relationship
check_unique_relationship(objects, relationship)
Definition
validate.py:34
validate.compare_objects
compare_objects(obj1, obj2)
Definition
validate.py:5
validate.validate_readout
validate_readout(db, session)
Definition
validate.py:69
Generated on
for DUNE-DAQ by
1.17.0