Skip to content
8 changes: 8 additions & 0 deletions slac_db/controls_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ def get_pmt_controls_information(pmt_names: List[str] = None):
"No method of getting additional controls_information for PMTs."
)
return {}


def get_toroid_controls_information(toroid_names: List[str] = None):
if toroid_names:
raise NotImplementedError(
"No method of getting additional controls_information for toroids."
)
return {}
46 changes: 29 additions & 17 deletions slac_db/db_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"LBLM": "lblms",
"BPM": "bpms",
"LCAV": "tcavs",
"INST": "pmts"
"INST": "pmts",
"IMON": "toroids",
}


def _build_metadata(device_name):
"""Generate Metadata field for a YAML device.

Expand All @@ -25,24 +27,25 @@ def _build_metadata(device_name):
Returns:
rv (dict): Device Metadata
"""

def parse_beampaths(beampath_csv):
if beampath_csv is None:
return []
beampaths = beampath_csv.replace(' ', '').split(',')
beampaths = filter(None, beampaths)
yield from beampaths
if beampath_csv is None:
return []
beampaths = beampath_csv.replace(" ", "").split(",")
beampaths = filter(None, beampaths)
yield from beampaths

def _round_values(meta):
for i, v in meta.items():
if type(v) is float:
meta[i] = round(v, 3)
return meta

beampath_csv = slac_db.oracle.get_device_row(device_name)["beampath"]
rv = {
rv = {
"area": slac_db.device.get_attribute(device_name, "area"),
"beam_path": list(parse_beampaths(beampath_csv)),
"type": slac_db.device.get_attribute(device_name, "device_type")
"type": slac_db.device.get_attribute(device_name, "device_type"),
}
rv.update(_round_values(slac_db.device.get_all_meta(device_name)))
expected_meta = slac_db.create.combined._DEVICE_META_MAP.get(
Expand All @@ -56,6 +59,7 @@ def _round_values(meta):
rv.update({m[1]: None})
return rv


def _build_controls_information(device_name):
"""Returns controls information in YAML Device Format.

Expand All @@ -67,16 +71,15 @@ def _build_controls_information(device_name):
"control_name": slac_db.device.get_attribute(device_name, "cs_name"),
}


def _build_devices(area, device_type):
"""Generator for all devices of a given type in a given area.

Args:
area (str): Area Name
device_type (str): Oracle Device Type
"""
devices = slac_db.device.get_devices(
area=area, device_type=device_type
)
devices = slac_db.device.get_devices(area=area, device_type=device_type)
for d in devices:
if device_type == "INST" and not d.startswith("PMT"):
continue
Expand All @@ -86,10 +89,14 @@ def _build_devices(area, device_type):
continue
cs = _build_controls_information(d)
meta = _build_metadata(d)
yield d, {
"controls_information": cs,
"metadata": meta,
}
yield (
d,
{
"controls_information": cs,
"metadata": meta,
},
)


def _build_types(area):
"""Generator for all devices in an area sorted by type.
Expand All @@ -108,6 +115,7 @@ def _build_types(area):
all_types[yaml].update(d)
yield yaml, all_types[yaml]


def _build_areas(areas):
"""Generator for all devices in a given area

Expand All @@ -117,9 +125,10 @@ def _build_areas(areas):
for a in areas:
yv = {t: d for t, d in _build_types(a)}
if not yv:
continue
continue
yield a, yv


def get_device(device_name):
"""Returns the expected device dict for a given device.

Expand All @@ -141,6 +150,7 @@ def get_device(device_name):
return None
return device_dict


def build():
"""Returns the expected device dict for a given device.

Expand All @@ -150,12 +160,14 @@ def build():
Returns:
(dict): YAML Device Dictionary
"""

def _parse_areas():
areas = slac_db.device.get_all_areas()
for a in areas:
if " " in a or "*" in a:
continue
yield a

areas = list(_parse_areas())
out = {a: d for a, d in _build_areas(areas)}
return out
24 changes: 24 additions & 0 deletions slac_db/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
get_bpm_metadata,
get_tcav_metadata,
get_pmt_metadata,
get_toroid_metadata,
)
from slac_db.controls_information import (
get_magnet_controls_information,
Expand All @@ -21,6 +22,7 @@
get_bpm_controls_information,
get_tcav_controls_information,
get_pmt_controls_information,
get_toroid_controls_information,
)


Expand Down Expand Up @@ -574,6 +576,28 @@ def extract_pmts(self, area: Union[str, List[str]] = ["HTR"]):
)
return complete_pmt_data

def extract_toroids(self, area: Union[str, List[str]] = ["DL10"]):
required_toroid_types = ["IMON"]
possible_toroid_pvs = {
"TMIT": "tmit",
}
basic_toroid_data = self.extract_devices(
area=area,
required_types=required_toroid_types,
pv_search_terms=possible_toroid_pvs,
)
if basic_toroid_data:
additional_metadata_data = get_toroid_metadata()
additional_controls_data = get_toroid_controls_information()
complete_toroid_data = self.add_extra_data_to_device(
device_data=basic_toroid_data,
additional_controls_information=additional_controls_data,
additional_metadata=additional_metadata_data,
)
return complete_toroid_data
else:
return {}

def extract_metadata_by_device_names(
self, device_names=Optional[List[str]], required_fields=Optional[List[str]]
):
Expand Down
8 changes: 8 additions & 0 deletions slac_db/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,11 @@ def get_pmt_metadata(pmt_names: List[str] = []):
pmt_metadata = yaml.safe_load(f)

return pmt_metadata


def get_toroid_metadata(toroid_names: List[str] = []):
if toroid_names:
raise NotImplementedError(
"No method of getting additional metadata for toroids."
)
return {}
5 changes: 4 additions & 1 deletion slac_db/package_data/accessor_names.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 6 additions & 11 deletions slac_db/package_data/beampaths.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions slac_db/package_data/wire_area_metadata.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading