DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
session.py
Go to the documentation of this file.
1import conffwk
2
3def get_segment_apps(segment):
4 """
5 Gather the list of applications in the segment and its sub-segments
6 """
7 apps = []
8
9 for ss in segment.segments:
10 apps += get_segment_apps(ss)
11
12 for aa in segment.applications:
13 apps.append(aa)
14
15 apps.append(segment.controller)
16
17 return apps
18
19
20def get_session_apps(confdb, session_name=""):
21 """
22 Gather the apps defined used in a session.
23 """
24 if session_name == "":
25 session_dals = confdb.get_dals(class_name="Session")
26 if len(session_dals) == 0:
27 print(f"Error could not find any Session in file {confdb.databases}")
28 return
29 session = session_dals[0]
30 else:
31 try:
32 session = confdb.get_dal("Session", session_name)
33 except:
34 print(f"Error could not find Session {session_name} in file {confdb.databases}")
35 return
36
37 segment = session.segment
38
39 return get_segment_apps(segment)
40
41
43 """
44 Gather the applications used in any session present in the database
45 """
46
47 output = {}
48 session_dals = confdb.get_dals(class_name="Session")
49 if len(session_dals) == 0:
50 print(f"Error could not find any Session in file {confdb.databases}")
51 return {}
52
53 for session in session_dals:
54 segment = session.segment
55 output[session.id] = get_segment_apps(segment)
56
57 return output
58
59
60def enable_resource_in_session(db, session_name: str, resource: list[str], disable: bool):
61 """Script to enable or disable (-d) Resources from the first Session of the
62 specified OKS database file"""
63 if session_name == "":
64 session_dals = db.get_dals(class_name="Session")
65 if len(session_dals) == 0:
66 print(f"Error could not find any Session in file {db.databases}")
67 return
68 session = session_dals[0]
69 else:
70 try:
71 session = db.get_dal("Session", session_name)
72 except:
73 print(f"Error could not find Session {session_name} in file {db.databases}")
74 return
75
76 disabled = session.disabled
77 for res in resource:
78 try:
79 res_dal = db.get_dal("ResourceBase", res)
80 except:
81 print(f"Error could not find Resource {res} in file {db.databases}")
82 continue
83
84 if disable:
85 if res_dal in disabled:
86 print(
87 f"{res} is already in disabled relationship of Session {session.id}"
88 )
89 else:
90 # Add to the Segment's disabled list
91 print(f"Adding {res} to disabled relationship of Session {session.id}")
92 disabled.append(res_dal)
93 else:
94 if res_dal not in disabled:
95 print(f"{res} is not in disabled relationship of Session {session.id}")
96 else:
97 # Remove from the Segments disabled list
98 print(
99 f"Removing {res} from disabled relationship of Session {session.id}"
100 )
101 disabled.remove(res_dal)
102 session.disabled = disabled
103 db.update_dal(session)
104 db.commit()
105
enable_resource_in_session(db, str session_name, list[str] resource, bool disable)
Definition session.py:60
get_apps_in_any_session(confdb)
Definition session.py:42
get_segment_apps(segment)
Definition session.py:3