Base parameter tree
base_parameter_tree.py - base classes representing a tree of parameters and accessors.
This module implements an arbitrarily-structured, recursively-managed tree of parameters and the appropriate accessor methods that are used to read and write those parameters. Its particular use is in the definition of a tree of parameters for an API adapter and help interfacing of those to the underlying device or object. These base classes are not intended to be used directly, but form the basis for concrete synchronous and asynchronous implementations.
James Hogge, Tim Nicholls, STFC Application Engineering Group.
BaseParameterAccessor
Bases: object
Base container class representing accessor methods for a parameter.
This base class implements a parameter accessor, providing set and get methods for parameters requiring calls to access them, or simply returning the appropriate value if the parameter is a read-only constant. Parameter accessors also contain metadata fields controlling access to and providing information about the parameter.
Valid specifiable metadata fields are: min : minimum allowed value for parameter max : maximum allowed value for parameter allowed_values: list of allowed values for parameter name : readable parameter name description: longer description of parameter units: parameter units display_precision: number of decimal places to display for e.g. float types
The class also maintains the following automatically-populated metadata fields: type: parameter type element_type: for list parameters, the type of the elements in the list writeable: is the parameter writable
Source code in src/odin_control/adapters/base_parameter_tree.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
type
property
Return the type of the parameter.
__init__(path, getter=None, setter=None, **kwargs)
Initialise the BaseParameterAccessor instance.
This constructor initialises the BaseParameterAccessor instance, storing the path of the parameter, its set/get accessors and setting metadata fields based on the the specified keyword arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
path of the parameter within the tree |
required | |
getter
|
get method for the parameter, or a value if read-only constant |
None
|
|
setter
|
set method for the parameter |
None
|
|
kwargs
|
keyword argument list for metadata fields to be set; these must be from the allow list specified in ParameterAccessor.allowed_metadata |
{}
|
Source code in src/odin_control/adapters/base_parameter_tree.py
get(element_idx=None, with_metadata=False)
Get the value of the parameter.
This method returns the value of the parameter, or the value returned by the get accessor if one is defined (i.e. is callable). If the with_metadata argument is true, the value is returned in a dictionary including all metadata for the parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
element_idx
|
index of element to get for list parameters, if applicable |
None
|
|
with_metadata
|
include metadata in the response when set to True |
False
|
Returns:
| Type | Description |
|---|---|
|
value of the parameter |
Source code in src/odin_control/adapters/base_parameter_tree.py
set(value, element_idx=None)
Set the value of the parameter.
This method sets the value of the parameter by calling the set accessor if defined and callable, otherwise raising an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
value to set |
required | |
element_idx
|
index of element to set for list parameters, if applicable |
None
|
Source code in src/odin_control/adapters/base_parameter_tree.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
BaseParameterTree
Bases: object
Base class implementing a tree of parameters and their accessors.
This base class implements an arbitrarily-structured, recursively-managed tree of parameters and the appropriate accessor methods that are used to read and write those parameters. Its particular use is in the definition of a tree of parameters for an API adapter and help interfacing of those to the underlying device or object.
Source code in src/odin_control/adapters/base_parameter_tree.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
tree
property
Return tree object for this parameter tree node.
Used internally for recursive descent of parameter trees.
__init__(tree, mutable=False)
Initialise the BaseParameterTree object.
This constructor recursively initialises the BaseParameterTree object, based on the parameter tree dictionary passed as an argument. This is done recursively, so that a parameter tree can have arbitrary depth and contain other BaseParameterTree instances as necessary.
Initialisation syntax for BaseParameterTree is made by passing a dict representing the tree as an argument. Children of a node at any level of the tree are described with dictionaries/lists e.g.
{"parent" : {"childA" : {...}, "childB" : {...}}} {"parent" : [{...}, {...}]}
Leaf nodes can be one of the following formats:
value - (value,) - (value, {metadata}) getter - (getter,) - (getter, {metadata}) (getter, setter) - (getter, setter, {metadata})
The following tags will also be treated as metadata:
name - A printable name for that branch of the tree description - A printable description for that branch of the tree
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
dict representing the parameter tree |
required | |
mutable
|
Flag, setting the tree |
False
|
Source code in src/odin_control/adapters/base_parameter_tree.py
delete(path='')
Delete parameters from a mutable tree.
This method deletes selected parameters from a tree, if that tree has been flagged as Mutable. Deletion of Branch Nodes means all child nodes of that Branch Node are also deleted
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path to selected Parameter Node in the tree |
''
|
Source code in src/odin_control/adapters/base_parameter_tree.py
get(path, with_metadata=False)
Get the values of parameters in a tree.
This method returns the values at and below a specified path in the parameter tree. This is done by recursively populating the tree with the current values of parameters, returning the result as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
path in tree to get parameter values for |
required | |
with_metadata
|
include metadata in the response when set to True |
False
|
Returns:
| Type | Description |
|---|---|
|
dict of parameter tree at the specified path |
Source code in src/odin_control/adapters/base_parameter_tree.py
replace(path, data)
Replace a branch of parameters in a tree.
This method sets the values of parameters in a tree, based on the data passed to it as a nested dictionary of parameter and value pairs. Any structure below the insertion point in the existing tree is replaced with this new structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
path to set parameters for in the tree |
required | |
data
|
nested dictionary representing structure to replace at the path |
required |
Source code in src/odin_control/adapters/base_parameter_tree.py
set(path, data, replace=False)
Set the values of the parameters in a tree.
This method sets the values of parameters in a tree, based on the data passed to it as a nested dictionary of parameter and value pairs. The updated parameters are merged into the existing tree recursively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
path to set parameters for in the tree |
required | |
data
|
nested dictionary representing values to update at the path |
required | |
replace
|
if set to true then the structure is replaced rather than merged |
False
|