DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
cider.data_structures.configuration_handler.ConfigurationHandler Class Reference

Public Member Functions

 __init__ (self, str configuration_file_name)
List[Dict[str, object]] get_relationships_for_conf_object (self, object conf_object)
List[object] get_conf_objects_class (self, str conf_class)
Dict[str, List[object]] get_all_conf_classes (self)
List[str] get_related_classes (self, str class_id)
List[str] get_inherited_classes (self, str class_id)
conffwk.Configuration configuration (self)
None configuration (self)
 conf_obj_list (self)
object get_obj (self, str class_id, str uid)
None commit (self, str update_message)
int n_dals (self)
None add_new_conf_obj (self, str class_id, str uid)
None destroy_conf_obj (self, str class_id, str uid)
None modify_relationship (self, str class_id, str uid, str relationship_name, object updated_value, bool append=False)

Protected Attributes

conffwk.Configuration _configuration = self.__open_configuration(configuration_file_name)
list _loaded_dals = []

Private Member Functions

conffwk.Configuration __open_configuration (self, str configuration_file_name)
None __cache_all_conf_objects (self)

Detailed Description

Definition at line 7 of file configuration_handler.py.

Constructor & Destructor Documentation

◆ __init__()

cider.data_structures.configuration_handler.ConfigurationHandler.__init__ ( self,
str configuration_file_name )
Configuration handler object, essentially a wrapper around a conffwk.Configuration object

Arguments:
    configuration_file_name -- name of the configuration .database.xml file to open

Definition at line 9 of file configuration_handler.py.

9 def __init__(self, configuration_file_name: str):
10 """Configuration handler object, essentially a wrapper around a conffwk.Configuration object
11
12 Arguments:
13 configuration_file_name -- name of the configuration .database.xml file to open
14 """
15
16 # Load configuration
17 self._configuration = self.__open_configuration(configuration_file_name)
18
19 # To be filled with ALL config objects (as DALs)
20 self._loaded_dals = []
21 # Fills self._loaded_dals,
22 self.__cache_all_conf_objects()
23

Member Function Documentation

◆ __cache_all_conf_objects()

None cider.data_structures.configuration_handler.ConfigurationHandler.__cache_all_conf_objects ( self)
private
Adds all loaded dals to self._loaded_dals

Definition at line 36 of file configuration_handler.py.

36 def __cache_all_conf_objects(self)->None:
37 """Adds all loaded dals to self._loaded_dals
38 """
39 for conf_class in self._configuration.classes():
40 for conf_obj in self._configuration.get_dals(conf_class):
41 if conf_obj in self._loaded_dals: continue
42
43 self._loaded_dals.append(conf_obj)
44

◆ __open_configuration()

conffwk.Configuration cider.data_structures.configuration_handler.ConfigurationHandler.__open_configuration ( self,
str configuration_file_name )
private
Opens configuration object safely 

Definition at line 24 of file configuration_handler.py.

24 def __open_configuration(self, configuration_file_name: str)->conffwk.Configuration:
25 '''Opens configuration object safely '''
26 if not os.path.isfile(configuration_file_name):
27 raise Exception(f"Cannot find file: {configuration_file_name}")
28
29 try:
30 configuration = conffwk.Configuration(f"oksconflibs:{configuration_file_name}")
31 except Exception as e:
32 raise e
33
34 return configuration
35

◆ add_new_conf_obj()

None cider.data_structures.configuration_handler.ConfigurationHandler.add_new_conf_obj ( self,
str class_id,
str uid )
Add new configuration object

Arguments:
    class_id -- Class name
    uid -- Unique object ID

Definition at line 152 of file configuration_handler.py.

152 def add_new_conf_obj(self, class_id: str, uid: str) -> None:
153 """Add new configuration object
154
155 Arguments:
156 class_id -- Class name
157 uid -- Unique object ID
158 """
159 self.configuration.create_obj(class_id, uid, at=self.configuration.active_database)
160 config_as_dal = self.configuration.get_dal(class_id, uid)
161 self.configuration.update_dal(config_as_dal)
162 self._loaded_dals.append(config_as_dal)
163

◆ commit()

None cider.data_structures.configuration_handler.ConfigurationHandler.commit ( self,
str update_message )
Commit changes to the database

Arguments:
    update_message -- Add message to the update

Definition at line 137 of file configuration_handler.py.

137 def commit(self, update_message: str) -> None:
138 """Commit changes to the database
139
140 Arguments:
141 update_message -- Add message to the update
142 """
143 self.configuration.commit(update_message)
144

◆ conf_obj_list()

cider.data_structures.configuration_handler.ConfigurationHandler.conf_obj_list ( self)
List of loaded in dals

Definition at line 120 of file configuration_handler.py.

120 def conf_obj_list(self):
121 """List of loaded in dals
122 """
123 return self._loaded_dals
124

◆ configuration() [1/2]

None cider.data_structures.configuration_handler.ConfigurationHandler.configuration ( self)
dummy method in case I try to do something silly

Definition at line 114 of file configuration_handler.py.

114 def configuration(self)->None:
115 """dummy method in case I try to do something silly
116 """
117 raise NotImplementedError(f"Configuration object is not mutable, please create new object")
118

◆ configuration() [2/2]

conffwk.Configuration cider.data_structures.configuration_handler.ConfigurationHandler.configuration ( self)
Access the underlying configuration object

Definition at line 108 of file configuration_handler.py.

108 def configuration(self)->conffwk.Configuration:
109 """Access the underlying configuration object
110 """
111 return self._configuration
112

◆ destroy_conf_obj()

None cider.data_structures.configuration_handler.ConfigurationHandler.destroy_conf_obj ( self,
str class_id,
str uid )
Destroy a configuration object

Arguments:
    class_id -- class name
    uid -- unique object ID

Definition at line 164 of file configuration_handler.py.

164 def destroy_conf_obj(self, class_id: str, uid: str) -> None:
165 """Destroy a configuration object
166
167 Arguments:
168 class_id -- class name
169 uid -- unique object ID
170 """
171 dal = self.configuration.get_dal(class_id, uid)
172 self.configuration.destroy_dal(dal)
173 self._loaded_dals.remove(dal)
174

◆ get_all_conf_classes()

Dict[str, List[object]] cider.data_structures.configuration_handler.ConfigurationHandler.get_all_conf_classes ( self)
Gets all classes + objects of that class in the configuration

Returns:
    dictionary of class : dal objects

Definition at line 81 of file configuration_handler.py.

81 def get_all_conf_classes(self) -> Dict[str, List[object]]:
82 """Gets all classes + objects of that class in the configuration
83
84 Returns:
85 dictionary of class : dal objects
86 """
87 return {conf_class: self.get_conf_objects_class(conf_class)
88 for conf_class in self._configuration.classes()}
89

◆ get_conf_objects_class()

List[object] cider.data_structures.configuration_handler.ConfigurationHandler.get_conf_objects_class ( self,
str conf_class )
Get all configuration objects of a given class

Arguments:
    conf_class -- Coniguration class to get objects of

Returns:
    List of configuration objects of the given class

Definition at line 70 of file configuration_handler.py.

70 def get_conf_objects_class(self, conf_class: str) -> List[object]:
71 """Get all configuration objects of a given class
72
73 Arguments:
74 conf_class -- Coniguration class to get objects of
75
76 Returns:
77 List of configuration objects of the given class
78 """
79 return self._configuration.get_dals(conf_class)
80

◆ get_inherited_classes()

List[str] cider.data_structures.configuration_handler.ConfigurationHandler.get_inherited_classes ( self,
str class_id )

Definition at line 101 of file configuration_handler.py.

101 def get_inherited_classes(self, class_id: str)->List[str]:
102 inherited_classes = [class_ for class_ in self._configuration.classes()\
103 if self._configuration.is_subclass(class_, class_id)]
104 return inherited_classes
105
106

◆ get_obj()

object cider.data_structures.configuration_handler.ConfigurationHandler.get_obj ( self,
str class_id,
str uid )
Get a particular configuration object 

Arguments:
    class_id -- Class name
    uid -- Unique object ID

Returns:
    DAL object satisfying the input

Definition at line 125 of file configuration_handler.py.

125 def get_obj(self, class_id: str, uid: str) -> object:
126 """Get a particular configuration object
127
128 Arguments:
129 class_id -- Class name
130 uid -- Unique object ID
131
132 Returns:
133 DAL object satisfying the input
134 """
135 return self.configuration.get_obj(class_id, uid)
136

◆ get_related_classes()

List[str] cider.data_structures.configuration_handler.ConfigurationHandler.get_related_classes ( self,
str class_id )
Get all related to classes to a given input class

Arguments:
    class_id -- Name of class

Returns:
    List of all related classses

Definition at line 90 of file configuration_handler.py.

90 def get_related_classes(self, class_id: str)->List[str]:
91 """Get all related to classes to a given input class
92
93 Arguments:
94 class_id -- Name of class
95
96 Returns:
97 List of all related classses
98 """
99 return self._configuration.relations(class_id, True)
100

◆ get_relationships_for_conf_object()

List[Dict[str, object]] cider.data_structures.configuration_handler.ConfigurationHandler.get_relationships_for_conf_object ( self,
object conf_object )
For a given configuration object, return all related objects

Arguments:
    conf_object -- configuration DAL object

Returns:
    List of related objects

Definition at line 46 of file configuration_handler.py.

46 def get_relationships_for_conf_object(self, conf_object: object) -> List[Dict[str, object]]:
47 """For a given configuration object, return all related objects
48
49 Arguments:
50 conf_object -- configuration DAL object
51
52 Returns:
53 List of related objects
54 """
55 relations = self.get_related_classes(conf_object.className())
56
57 relations_list = []
58
59 # Loop over relations
60 for rel, rel_info in relations.items():
61 rel_val = getattr(conf_object, rel)
62 # Hacky but pybind got fussy about casting list(dal)
63 if not isinstance(rel_val, list):
64 rel_val = [rel_val]
65
66 relations_list.append({rel: [v for v in rel_val if v is not None], 'rel_info': rel_info})
67
68 return relations_list
69

◆ modify_relationship()

None cider.data_structures.configuration_handler.ConfigurationHandler.modify_relationship ( self,
str class_id,
str uid,
str relationship_name,
object updated_value,
bool append = False )
Modify TODO: EDIT THIS

:param class_id: _description_
:type class_id: _type_
:param uid: _description_
:type uid: _type_
:param relationship_name: _description_
:type relationship_name: str
:param updated_value: _description_
:type updated_value: _type_
:param append: _description_, defaults to False
:type append: bool, optional

Definition at line 175 of file configuration_handler.py.

182 ) -> None:
183 """Modify TODO: EDIT THIS
184
185 :param class_id: _description_
186 :type class_id: _type_
187 :param uid: _description_
188 :type uid: _type_
189 :param relationship_name: _description_
190 :type relationship_name: str
191 :param updated_value: _description_
192 :type updated_value: _type_
193 :param append: _description_, defaults to False
194 :type append: bool, optional
195 """
196 # Firstly we need to find the relationship this is referring to
197 selected_dal = self.configuration.get_dal(class_id, uid)
198 # Okay need a better way of doing this...
199 rel_list = self.get_relationships_for_conf_object(selected_dal)
200
201 for relations in rel_list:
202 # Need to find our dal
203 if list(relations.keys())[0] != relationship_name:
204 continue
205
206 # Next we need to check the type of our object is okay
207 if updated_value not in self.get_conf_objects_class(relations['rel_info']['type']):
208 raise Exception(updated_value)
209 # raise TypeError(f"Cannot use object {updated_value} for relation expecting type {relations['rel_info']['type']}")
210
211 # Need to make sure everything is typed correctly
212 if append and relations['rel_info']['multivalue']:
213 rel = list(relations.items)[0]
214 rel.append(updated_value)
215
216 elif relations['rel_info']['multivalue']:
217 rel = [updated_value]
218 else:
219 rel = updated_value
220
221 # Should update the dal
222 setattr(selected_dal, relationship_name, rel)
223 self.configuration.update_dal(selected_dal)
224
225
226 return
227
228 raise RuntimeError(f"Cannot find relationship with name {relationship_name}

◆ n_dals()

int cider.data_structures.configuration_handler.ConfigurationHandler.n_dals ( self)
Lists the total number of loaded objects
    _description_

Definition at line 146 of file configuration_handler.py.

146 def n_dals(self)->int:
147 """Lists the total number of loaded objects
148 _description_
149 """
150 return len(self._loaded_dals)
151

Member Data Documentation

◆ _configuration

conffwk.Configuration cider.data_structures.configuration_handler.ConfigurationHandler._configuration = self.__open_configuration(configuration_file_name)
protected

Definition at line 17 of file configuration_handler.py.

◆ _loaded_dals

cider.data_structures.configuration_handler.ConfigurationHandler._loaded_dals = []
protected

Definition at line 20 of file configuration_handler.py.


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