Skip to content

Commit

Permalink
Made it work for excalibur
Browse files Browse the repository at this point in the history
  • Loading branch information
EdWarrick committed Jun 27, 2017
1 parent 2c88a80 commit 76abd75
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 102 deletions.
35 changes: 0 additions & 35 deletions malcolm/blocks/excalibur/FemDetectorManager.yaml~

This file was deleted.

3 changes: 2 additions & 1 deletion malcolm/imalcolm.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,8 @@ def main():
sys.path.insert(0,
"/dls_sw/work/tools/RHEL6-x86_64/odin/venv/lib/python2.7/"
"site-packages")
require("tornado", "numpy", "cothread", "ruamel.yaml",
sys.path.append("/dls_sw/work/common/python/cothread")
require("tornado", "numpy", "ruamel.yaml",
"scanpointgenerator", "plop", "pygelf", "h5py")
#sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "scanpointgenerator"))
sys.path.append(
Expand Down
2 changes: 1 addition & 1 deletion malcolm/modules/ADCore/parts/detectordriverpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def run(self, context, update_completed_steps):
# update_completed_steps come in
try:
child.when_value_matches(
"arrayCounter", self.done_when_reaches, timeout=0.1)
"arrayCounter", self.done_when_reaches, timeout=5.0)
except TimeoutError:
raise ValueError("Detector %r didn't produce %s frames in time" % (
self.params.mri, self.done_when_reaches))
Expand Down
25 changes: 13 additions & 12 deletions malcolm/modules/BL14I/BL14I-ML-MALC-01.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
#!/home/qvr31998/malcolm/pymalcolm/malcolm/imalcolm.py

- parameters.string:
- builtin.defines.string:
name: configDir
description: Where to store saved configs
default: /dls_sw/i14/epics/malcolm
value: /dls_sw/i14/epics/malcolm

- blocks.xspress3.Xspress3DetectorManager:
- xspress3.blocks.xspress3_detector_manager_block:
pvPrefix: BL14I-EA-XSP3-01
mriPrefix: BL14I-ML-XSP3-01
configDir: $(configDir)

#- blocks.excalibur.ExcaliburDetectorManager:
# pvPrefix: BL14I-EA-EXCBR-01
# mriPrefix: BL14I-ML-EXCBR-01
# configDir: $(configDir)
- excalibur.blocks.excalibur_detector_runnable_block:
pvPrefix: BL14I-EA-EXCBR-01
mriPrefix: BL14I-ML-EXCBR-01
configDir: $(configDir)

- blocks.demo.I14PMACManager:
- BL14I.blocks.pmac_runnable_block:
mriPrefix: BL14I-ML-BRICK-14
configDir: $(configDir)

- blocks.pandabox.PandABoxManager:
- ADPandABlocks.blocks.pandablocks_runnable_block:
pvPrefix: BL14I-MO-PANDA-01
mriPrefix: BL14I-ML-PANDA-01
hostname: bl14i-mo-pandabox-01
configDir: $(configDir)

- blocks.demo.I14Manager:
- BL14I.blocks.xspress3_scan_block:
mri: BL14I-ML-SCAN-01
det: BL14I-ML-XSP3-01
brick: BL14I-ML-BRICK-14
pandabox: BL14I-ML-PANDA-01
configDir: $(configDir)

- comms.pva.PvaServerComms:
- pva.blocks.pva_server_block:
mri: $(yamlname):PVA-SERVER

7 changes: 7 additions & 0 deletions malcolm/modules/BL14I/blocks/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from malcolm.yamlutil import make_block_creator, check_yaml_names

pmac_runnable_block = make_block_creator(__file__, "pmac_runnable_block.yaml")
xspress3_scan_block = make_block_creator(__file__, "xspress3_scan_block.yaml")

__all__ = check_yaml_names(globals())

Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
- parameters.string:
- builtin.parameters.string:
name: mriPrefix
description: MRI for created block

- parameters.string:
- builtin.parameters.string:
name: configDir
description: Where to store saved configs

- controllers.RunnableController:
- scanning.controllers.RunnableController:
mri: $(mriPrefix)
configDir: $(configDir)

#- includes.pmac.compoundmotor_collection:
# mri: I18-T1-X
# prefix: BL18I-MO-TABLE-01:CSX
# scannable: t1x

#- includes.pmac.compoundmotor_collection:
# mri: I18-T1-Y
# prefix: BL18I-MO-TABLE-01:HEIGHT
# scannable: sc_MicroFocusSampleY

- includes.pmac.rawmotor_collection:
- pmac.includes.rawmotor_collection:
mri: BL14I-ML-STAGE-01:XC
prefix: BL14I-MO-STEP-14:M1
motorPrefix: BL14I-MO-STAGE-01:XC
scannable: stage1_x

- includes.pmac.rawmotor_collection:
- pmac.includes.rawmotor_collection:
mri: BL14I-ML-STAGE-01:YC
prefix: BL14I-MO-STEP-14:M2
motorPrefix: BL14I-MO-STAGE-01:YC
scannable: stage1_y

- includes.pmac.trajectory_collection:
- pmac.includes.trajectory_collection:
mri: $(mriPrefix):TRAJ
prefix: BL14I-MO-STEP-14
statPrefix: BL14I-MO-STEP-14
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
- parameters.string:
- builtin.parameters.string:
name: mri
description: MRI for created block

- parameters.string:
- builtin.parameters.string:
name: det
description: MRI for detector DetectorManager object

- parameters.string:
- builtin.parameters.string:
name: brick
description: MRI for brick PMACManager object

- parameters.string:
- builtin.parameters.string:
name: pandabox
description: MRI for PandABoxManager object

- parameters.string:
- builtin.parameters.string:
name: configDir
description: Where to store saved configs

- controllers.RunnableController:
- scanning.controllers.RunnableController:
mri: $(mri)
axesToMove: [stage1_x, stage1_y]
configDir: $(configDir)

- parts.ADCore.DatasetTablePart:
- ADCore.parts.DatasetTablePart:
name: DSET

- parts.pmac.PmacRunnableChildPart:
- pmac.parts.PmacRunnableChildPart:
name: BRICK
mri: $(brick)

- parts.ADCore.DatasetRunnableChildPart:
- ADCore.parts.DatasetRunnableChildPart:
name: DET
mri: $(det)

- parts.ADCore.DatasetRunnableChildPart:
- ADCore.parts.DatasetRunnableChildPart:
name: PANDABOX
mri: $(pandabox)
6 changes: 5 additions & 1 deletion malcolm/modules/builtin/parts/childpart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

import numpy as np

from malcolm.compat import OrderedDict
from malcolm.core import Part, REQUIRED, method_takes, serialize_object, \
Attribute, Subscribe, Unsubscribe, Put
Expand Down Expand Up @@ -152,7 +154,9 @@ def report_modified(self, context):
attr = getattr(child, name)
if isinstance(attr, Attribute) and "config" in attr.meta.tags:
current_value = serialize_object(attr.value)
if original_value != current_value:
try:
np.testing.assert_equal(original_value, current_value)
except AssertionError:
we_modified = name in self.we_modified
ret.append(ModifiedInfo(
name, original_value, current_value, we_modified))
Expand Down
8 changes: 5 additions & 3 deletions malcolm/modules/excalibur/parts/femdriverpart.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from malcolm.modules.builtin.parts import StatefulChildPart
from malcolm.modules.scanning.controllers import RunnableController
from malcolm.modules.ADCore.infos import NDArrayDatasetInfo
from malcolm.modules.ADCore.infos import NDArrayDatasetInfo, UniqueIdInfo


class FemDriverPart(StatefulChildPart):
# Only need to report that we will make a dataset, top level will do all
# control
@RunnableController.ReportStatus
def report_configuration(self, _):
return [NDArrayDatasetInfo(rank=2)]
def report_configuration(self, context):
child = context.block_view(self.params.mri)
return [
NDArrayDatasetInfo(rank=2), UniqueIdInfo(child.arrayCounter.value)]
48 changes: 25 additions & 23 deletions malcolm/modules/excalibur/parts/vdswrapperpart.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,17 @@ def __init__(self, params):

@RunnableController.Abort
@RunnableController.Reset
@RunnableController.PostRunIdle
def abort(self, context):
self.close_files()

def close_files(self):
for file_ in self.raw_datasets + [self.vds]:
if file_ is not None and file_.id.valid:
self._logger.info("Closing file %s", file_)
self.log.info("Closing file %s", file_)
file_.close()
self.raw_datasets = []
self.vds = None

def _create_dataset_infos(self, generator, filename):
uniqueid_path = "/entry/NDAttributes/NDArrayUniqueId"
Expand Down Expand Up @@ -118,10 +121,9 @@ def configure(self, context, completed_steps, steps_to_do, part_info,
params):
self.done_when_reaches = completed_steps + steps_to_do

self._logger.debug("Creating ExternalLinks from VDS to FEM1.h5")
self.log.debug("Creating ExternalLinks from VDS to FEM1.h5")
self.vds_path = os.path.join(params.fileDir, self.OUTPUT_FILE)
raw_file_path = os.path.join(params.fileDir,
self.RAW_FILE_TEMPLATE.format(1))
raw_file_path = self.RAW_FILE_TEMPLATE.format(1)
node_tree = list(self.default_node_tree)
for axis in params.generator.axes:
for base in self.set_bases:
Expand All @@ -143,7 +145,7 @@ def configure(self, context, completed_steps, steps_to_do, part_info,
self.vds.create_dataset(self.SUM, initial_shape,
maxshape=max_shape, dtype="float64")

self._logger.debug("Calling vds-gen to create dataset in VDS")
self.log.debug("Calling vds-gen to create dataset in VDS")
files = [self.RAW_FILE_TEMPLATE.format(fem) for fem in self.fems]
shape = [str(d) for d in params.generator.shape] + \
[str(self.stripe_height), str(self.stripe_width)]
Expand All @@ -162,14 +164,18 @@ def configure(self, context, completed_steps, steps_to_do, part_info,
self.TARGET_NODE, "/entry/detector/detector"]
# Define output file path
command += [self.OUTPUT, self.OUTPUT_FILE]
command += [self.LOG_LEVEL, "1"] # str(self._logger.level / 10)]
self.log_info("Command: %s", command)
command += [self.LOG_LEVEL, "1"] # str(self.log.level / 10)]
self.log.info("Command: %s", command)
check_call(command)

# Store required attributes
self.raw_paths = [os.path.abspath(os.path.join(params.fileDir, file_))
for file_ in files]

# Open the VDS
self.vds = h5.File(self.vds_path, self.APPEND, libver="latest")


# Return the dataset information
dataset_infos = list(self._create_dataset_infos(
params.generator, self.vds_path))
Expand All @@ -184,39 +190,35 @@ def seek(self, context, completed_steps, steps_to_do, part_info):
@RunnableController.Run
@RunnableController.Resume
def run(self, context, update_completed_steps):
self.vds = h5.File(self.vds_path, self.APPEND, libver="latest")
try:
# Wait until raw files exist and have UniqueIDArray
if not self.raw_datasets:
for path_ in self.raw_paths:
self.log_info("Waiting for file %s to be created", path_)
self.log.info("Waiting for file %s to be created", path_)
while not os.path.exists(path_):
context.sleep(1)
self.raw_datasets.append(
h5.File(path_, self.READ, libver="latest", swmr=True))
for dataset in self.raw_datasets:
self.log_info("Waiting for id in file %s", dataset)
self.log.info("Waiting for id in file %s", dataset)
while self.ID not in dataset:
context.sleep(1)

self.log_info("Monitoring raw files until ID reaches %s",
context.sleep(0.1)
try:
self.log.info("Monitoring raw files until ID reaches %s",
self.done_when_reaches)
while self.id < self.done_when_reaches:
context.sleep(0.1) # Allow while loop to be aborted
ids = []
for dataset in self.raw_datasets:
ids.append(self.get_id(dataset))
if min(ids) > self.id:
self.log_info("Raw ID changed: %s - "
self.log.info("Raw ID changed: %s - "
"Updating VDS ID and Sum", min(ids))
idx = ids.index(min(ids))
self.update_id(idx)
self.update_sum(idx)

self.log_info("ID reached: %s", self.id)
self.log.info("ID reached: %s", self.id)
except Exception as error:
self.log_error("Error in run. Message:\n%s", error.message)
raise
finally:
self.log.exception("Error in run. Message:\n%s", error.message)
self.close_files()

@property
Expand All @@ -228,14 +230,14 @@ def get_id(self, file_):
file_[self.ID].refresh()
return max(file_[self.ID].value.flatten())
else:
self.log_warning("File %s does not exist or does not have a "
self.log.warning("File %s does not exist or does not have a "
"UniqueIDArray, returning 0", file_)
return 0

def update_id(self, min_dataset):
min_id = self.raw_datasets[min_dataset][self.ID]

self.log_debug("ID shape:\n%s", min_id.shape)
self.log.debug("ID shape:\n%s", min_id.shape)
self.vds[self.ID].resize(min_id.shape)
self.vds[self.ID][...] = min_id

Expand All @@ -254,6 +256,6 @@ def update_sum(self, min_dataset):
mask = min_sum < 0
sum_[mask] = -1

self.log_debug("Sum shape:\n%s", sum_.shape)
self.log.debug("Sum shape:\n%s", sum_.shape)
self.vds[self.SUM].resize(sum_.shape)
self.vds[self.SUM][...] = sum_

0 comments on commit 76abd75

Please sign in to comment.