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

Classes

class  ConfigCommitError
 
class  DalCollector
 
class  DalGroup
 
class  ExtendedDal
 
class  RelationshipCache
 
class  RenameDalCli
 

Functions

list _natural_sort_key (str s)
 
List[DalGroupsort_groups_by_depth (List[DalGroup] groups, Dict[Configuration, RelationshipCache] trees)
 
 rename_duplicate_dals (str input_folder)
 

Variables

 console = Console()
 

Detailed Description

HW: Finds non-unique DAL objects and provides a simple CLI to rename them iteratively

Function Documentation

◆ _natural_sort_key()

list rename_duplicate_dals._natural_sort_key ( str s)
protected

Definition at line 160 of file rename_duplicate_dals.py.

160def _natural_sort_key(s: str) -> list:
161 return [int(c) if c.isdigit() else c.lower() for c in re.split(r"(\d+)", s)]
162
163

◆ rename_duplicate_dals()

rename_duplicate_dals.rename_duplicate_dals ( str input_folder)

Definition at line 379 of file rename_duplicate_dals.py.

379def rename_duplicate_dals(input_folder: str):
380 folder = Path(input_folder)
381 if not folder.exists() or not folder.is_dir():
382 raise FileNotFoundError(f"Cannot find {folder}")
383
384 configs = [Configuration(f"oksconflibs:{f}") for f in folder.glob("*.data.xml")]
385 if not configs:
386 raise FileNotFoundError(
387 "No configs found — ensure the folder contains .data.xml files."
388 )
389
390 collector = DalCollector(configs)
391 RenameDalCli(collector).run()
392
393
static volatile sig_atomic_t run

◆ sort_groups_by_depth()

List[DalGroup] rename_duplicate_dals.sort_groups_by_depth ( List[DalGroup] groups,
Dict[Configuration, RelationshipCache] trees )
Sort DalGroups by their depth in the configuration tree (BFS from Session root).

Definition at line 164 of file rename_duplicate_dals.py.

167) -> List[DalGroup]:
168 """Sort DalGroups by their depth in the configuration tree (BFS from Session root)."""
169 all_ids = {g.dals[0].id for g in groups}
170 tree_list = list(trees.values())
171 covered: Set[str] = set()
172 sorted_groups: List[DalGroup] = []
173 iteration = 0
174
175 while covered != all_ids:
176 iteration += 1
177
178 if iteration == 1:
179 sessions = tree_list[0].db.get_dals("Session")
180 if not sessions:
181 raise ValueError("Configuration must contain a Session object!")
182 root = sessions[0]
183 else:
184 remaining = all_ids - covered
185 root = next((g.dals[0] for g in groups if g.dals[0].id in remaining), None)
186 if root is None:
187 break
188
189 # BFS to build depth map
190 depth_map: Dict[str, int] = {}
191 queue = [(root, 0)]
192 visited: Set[int] = set()
193
194 while queue:
195 obj, depth = queue.pop(0)
196 if id(obj) in visited:
197 continue
198 visited.add(id(obj))
199 depth_map[obj.id] = depth
200 covered.add(obj.id)
201
202 seen_children: Set[int] = set()
203 for tree in tree_list:
204 for child in tree.graph.get(obj, []):
205 if id(child) not in visited and id(child) not in seen_children:
206 queue.append((child, depth + 1))
207 seen_children.add(id(child))
208
209 batch = [g for g in groups if g.dals[0].id in depth_map]
210 batch.sort(key=lambda g: (depth_map[g.dals[0].id], _natural_sort_key(g.dals[0].id)))
211 sorted_groups.extend(batch)
212
213 return sorted_groups
214
215
216# ----- DAL Collector -----
217

Variable Documentation

◆ console

rename_duplicate_dals.console = Console()

Definition at line 19 of file rename_duplicate_dals.py.