DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
selection_interface.py
Go to the documentation of this file.
1'''
2Class which defines selection menus where the menu is generated by a tree
3'''
4
5from abc import ABC, abstractmethod
6from daqconf.cider.data_structures.structured_configuration import StructuredConfiguration
7from daqconf.cider.data_structures.relational_graph import RelationalGraph
8
10 ''' Generic Selection interface
11 '''
12 def __init__(self, config_handler: StructuredConfiguration):
13 self._handler = config_handler
15
16 def recompose(self)->None:
17 # Regenerates the GUI
19
20 @abstractmethod
22 # Abstract method to be implemented by concrete classes
23 return {}
24
25 @property
26 def relationships(self):
27 # Return the relationships between objects
28 return self._relational_dict
29
30
31# Couple of concrete classes
33 '''Selection menu based purely on the class of objects
34 '''
36 """Returns all classes + conf objs for class/derived classes
37 """
38 return self._handler.configuration_handler.get_all_conf_classes()
39
40 def __repr__(self):
41 return "ClassSelectionMenu"
42
44 ''' Selection menu based on class relationships
45 '''
47 configuration_dict = {f"[green]Sessions" : [self.__build_node(top_node) for top_node in self._handler.relational_graph.top_level_nodes if top_node.className() == "Session"],
48 f"[green]Objects outside of Session" : [self.__build_node(top_node) for top_node in self._handler.relational_graph.top_level_nodes if top_node.className() != "Session"]}
49
50 return configuration_dict
51
52 def __build_node(self, conf_obj):
53 """Build each node of the relational graph
54
55 Arguments:
56 conf_obj -- Configuration object
57 """
58
59 # We can deal with the schema
60 relationships = self._handler.configuration_handler.get_relationships_for_conf_object(conf_obj)
61
62 if not len(relationships):
63 return conf_obj
64
65 relations_list = []
66 for rel_category in relationships:
67 for rel_type, rel in rel_category.items():
68 # TODO: Better data structure, need class info for now
69 if rel_type=='rel_info':
70 continue
71 # Bit slower but configuration isn't large enough for this to really matter]
72 relations_list.append({f"[blue]{rel_type}[/blue]": [self.__build_node(r) for r in rel]})
73
74
75 return {conf_obj: relations_list}
76
77 def __repr__(self):
78 return "RelationalSelectionMenu"
__init__(self, StructuredConfiguration config_handler)