DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
rename_duplicate_dals.RelationshipCache Class Reference
Collaboration diagram for rename_duplicate_dals.RelationshipCache:
[legend]

Public Member Functions

 __init__ (self, Configuration|str db)
 
List[DalBaseget_parents (self, DalBase obj)
 

Public Attributes

 db = db
 
Dict[DalBase, List[DalBase]] graph = self._build_graph()
 
list _parents_cache
 

Protected Member Functions

 _relations (self, str class_name)
 
Dict[DalBase, List[DalBase]] _build_graph (self)
 

Protected Attributes

dict _relations_cache = {}
 
dict _parents_cache = {}
 

Detailed Description

Caches parent-child relationships between DAL objects to avoid repeated DB calls.

Definition at line 31 of file rename_duplicate_dals.py.

Constructor & Destructor Documentation

◆ __init__()

rename_duplicate_dals.RelationshipCache.__init__ ( self,
Configuration | str db )

Definition at line 34 of file rename_duplicate_dals.py.

34 def __init__(self, db: Configuration | str):
35 if isinstance(db, str):
36 db = Configuration("oksconflibs:" + db)
37 self.db = db
38 self._relations_cache: Dict[str, Any] = {}
39 self._parents_cache: Dict[Any, list] = {}
40 self.graph = self._build_graph()
41

Member Function Documentation

◆ _build_graph()

Dict[DalBase, List[DalBase]] rename_duplicate_dals.RelationshipCache._build_graph ( self)
protected

Definition at line 47 of file rename_duplicate_dals.py.

47 def _build_graph(self) -> Dict[DalBase, List[DalBase]]:
48 graph = {}
49 for obj in self.db.get_all_dals().values():
50 children = []
51 for rel in self._relations(obj.className()):
52 related = getattr(obj, rel, None)
53 if related is None:
54 continue
55 children.extend(related if isinstance(related, list) else [related])
56 if children:
57 graph[obj] = children
58 return graph
59

◆ _relations()

rename_duplicate_dals.RelationshipCache._relations ( self,
str class_name )
protected

Definition at line 42 of file rename_duplicate_dals.py.

42 def _relations(self, class_name: str):
43 if class_name not in self._relations_cache:
44 self._relations_cache[class_name] = self.db.relations(class_name, all=True)
45 return self._relations_cache[class_name]
46

◆ get_parents()

List[DalBase] rename_duplicate_dals.RelationshipCache.get_parents ( self,
DalBase obj )

Definition at line 60 of file rename_duplicate_dals.py.

60 def get_parents(self, obj: DalBase) -> List[DalBase]:
61 if obj not in self._parents_cache:
62 self._parents_cache[obj] = [
63 parent for parent, children in self.graph.items() if obj in children
64 ]
65 return self._parents_cache[obj]
66
67
68# ----- Extended DAL (wraps a DAL with its config + tree context) -----
69

Member Data Documentation

◆ _parents_cache [1/2]

dict rename_duplicate_dals.RelationshipCache._parents_cache = {}
protected

Definition at line 39 of file rename_duplicate_dals.py.

◆ _parents_cache [2/2]

list rename_duplicate_dals.RelationshipCache._parents_cache
Initial value:
= [
parent for parent, children in self.graph.items() if obj in children
]

Definition at line 61 of file rename_duplicate_dals.py.

◆ _relations_cache

rename_duplicate_dals.RelationshipCache._relations_cache = {}
protected

Definition at line 38 of file rename_duplicate_dals.py.

◆ db

rename_duplicate_dals.RelationshipCache.db = db

Definition at line 37 of file rename_duplicate_dals.py.

◆ graph

Dict[DalBase, List[DalBase]] rename_duplicate_dals.RelationshipCache.graph = self._build_graph()

Definition at line 40 of file rename_duplicate_dals.py.


The documentation for this class was generated from the following file: