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

Functions

 compare_objects (obj1, obj2)
 
 check_unique_relationship (objects, relationship)
 
 validate_readout (db, session)
 
 validate_session (oksfile, session_name)
 

Function Documentation

◆ check_unique_relationship()

validate.check_unique_relationship ( objects,
relationship )
Check to see if the given relationship (by class name) is unique
among a list of objects. First by comparing the UIDs, then by
comparing the values within.

Definition at line 34 of file validate.py.

34def 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

◆ compare_objects()

validate.compare_objects ( obj1,
obj2 )
 Compare 2 dal objects for equality attribute by attribute 

Definition at line 5 of file validate.py.

5def 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

◆ validate_readout()

validate.validate_readout ( db,
session )

Definition at line 69 of file validate.py.

69def 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.session_get_all_applications(db._obj, session.id):
75 if confmodel.component_disabled(db._obj, session.id, app.id):
76 continue
77 if app.class_name == "ReadoutApplication":
78 ru_apps.append(db.get_dal(app.class_name, app.id))
79 if len(ru_apps) == 0:
80 print(f"No enabled readout applicatios in session")
81 errcount += 1
82 d2d_seen = {}
83 d2d_dals = []
84 snd_dals = []
85 senders_seen = {}
86 for ru in ru_apps:
87 connections = 0
88 for d2d in ru.contains:
89 if d2d.className() != "DetectorToDaqConnection":
90 print(f"Error {ru.id} contains a {d2d.className()} where it should have a DetectorToDaqConnection")
91 errcount += 1
92 continue
93 if d2d.id in d2d_seen:
94 print(f"Error {ru.id} contains {d2d.id}"+
95 f" which is already read out by {d2d_seen[d2d.id]}")
96 errcount += 1
97 continue
98
99 senders = 0
100 receiver = 0
101 for d2d_res in d2d.contains:
102 if "DetDataReceiver" in d2d_res.oksTypes():
103 receiver += 1
104 elif "DetDataSender" in d2d_res.oksTypes():
105 if d2d_res.id in senders_seen:
106 print(f"Error sender {d2d_res.id} already seen in {senders_seen[d2d_res.id]}")
107 errcount += 1
108 continue
109 senders_seen[d2d_res.id] = d2d.id
110 snd_dals.append(d2d_res)
111 senders += 1
112 elif "ResourceSet" in d2d_res.oksTypes():
113 for snd_res in d2d_res.contains:
114 if "DetDataSender" in snd_res.oksTypes():
115 if snd_res.id in senders_seen:
116 print(f"Error sender {snd_res.id} already seen in {senders_seen[d2d_res.id]}")
117 errcount += 1
118 continue
119 senders_seen[snd_res.id] = d2d.id
120 snd_dals.append(snd_res)
121 senders += 1
122 if senders == 0:
123 print(f"Error {d2d.id} does not have any senders")
124 errcount += 1
125 continue
126 if receiver == 0:
127 print(f"Error {d2d.id} does not have a receiver")
128 errcount += 1
129 continue
130 d2d_seen[d2d.id] = ru.id
131 d2d_dals.append(d2d)
132 connections += 1
133 if connections == 0:
134 print(f"Error {ru.id} contains 0 detector connections")
135 errcount += 1
136
137 print (f"\nChecking data senders for duplicate streams");
138 if not check_unique_relationship(snd_dals, "DetectorStream"):
139 errcount += 1
140
141 print (f"\nChecking detector connections for duplicate geio ids")
142 if not check_unique_relationship(d2d_dals, "GeoId"):
143 errcount += 1
144
145 print (f"Session {session.id} readout validated with {errcount} errors:"+
146 f" contains {len(d2d_seen)} Detector connections"+
147 f" in {len(ru_apps)} readout applications")
148
149 return errcount
150

◆ validate_session()

validate.validate_session ( oksfile,
session_name )

Definition at line 151 of file validate.py.

151def validate_session(oksfile, session_name):
152 db = conffwk.Configuration("oksconflibs:" + oksfile)
153 if session_name == "":
154 session_dals = db.get_dals(class_name="Session")
155 if len(session_dals) == 0:
156 print(f"Error could not find any Session in file {oksfile}")
157 return
158 if len(session_dals) > 1:
159 print(f"Warning: more than one Session found in database."
160 " Using the first one found")
161 session = session_dals[0]
162 else:
163 try:
164 session = db.get_dal("Session", session_name)
165 except:
166 print(f"Error could not find Session {session_name} in file {oksfile}")
167 return
168
169 print(f"Validating session {session.id}:")
170 errcount = validate_readout(db, session)
171 print (f"\nSession {session.id} validated with {errcount} errors")