dev_data_policy_custom.md 1.35 KB
Newer Older
Wout De Nolf's avatar
Wout De Nolf committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Custom data policy

SCAN_SAVING is a `ParametersWardrobe` which defines the data policy in the BLISS session. The activate data policy is selected in the session object (see `bliss/common/session.py`):

```python
class Session:

    def _set_scan_saving_class(self, scan_saving_class):
        scan_saving.set_scan_saving_class(scan_saving_class)
        self.scan_saving = scan_saving.ScanSaving(self.name)
        if is_bliss_shell():
            self.env_dict["SCAN_SAVING"] = self.scan_saving
```

15
Creating a custom data policy means deriving a class from `bliss.scanning.scan_saving.BasicScanSaving`:
Wout De Nolf's avatar
Wout De Nolf committed
16
17
18

```python

19
class CustomScanSaving(BasicScanSaving):
Wout De Nolf's avatar
Wout De Nolf committed
20
21
    DEFAULT_VALUES = {
        # default and not removable values
22
        "scan_number_format": "%04d",
Wout De Nolf's avatar
Wout De Nolf committed
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
        ...
        # saved properties in Redis:
        "_proposal": "",
        ...
    }

    # read only attributes implemented with python properties
    PROPERTY_ATTRIBUTES = [
        "proposal",
        ...
    ]
    REDIS_SETTING_PREFIX = "custom_scan_saving"

    SLOTS = ["_custom_attr"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._custom_attr = None

    def get(self):
        try:
            # calculate all parameters
        except KeyError as keyname:
            raise RuntimeError("Missing %s attribute in CustomScanSaving" % keyname)
```