Skip to content
Snippets Groups Projects
Commit 4db44ada authored by Danilo Ferreira de Lima's avatar Danilo Ferreira de Lima
Browse files

Merged.

parents 91232763 e3d4a37f
No related branches found
No related tags found
2 merge requests!59Interface CrystFEL with Karabo and allow automatic parameter tunning with rcrystfel,!53Train picker arbiter kernel
import re
import numpy as np
from karabo.bound import (
BOOL_ELEMENT,
......@@ -66,7 +68,10 @@ class PickyBoi(PythonDevice):
BOOL_ELEMENT(expected)
.key("breakStreamAfterEnd")
.description("If active, end the output stream after the range of selected train IDs has been forwarded.")
.description(
"If active, end the output stream after the range of selected train "
"IDs has been forwarded."
)
.assignmentOptional()
.defaultValue(False)
.reconfigurable()
......@@ -120,6 +125,17 @@ class PickyBoi(PythonDevice):
.reconfigurable()
.commit(),
STRING_ELEMENT(expected)
.key("sourceFilterRegex")
.assignmentOptional()
.defaultValue("")
.description(
"If set, only data from sources matching this regex will be forwarded. "
"If not set, all sources are forwarded."
)
.reconfigurable()
.commit(),
INT64_ELEMENT(expected)
.key("ppuTrainOffset")
.description(
......@@ -149,17 +165,6 @@ class PickyBoi(PythonDevice):
.initialValue(0)
.commit(),
STRING_ELEMENT(expected)
.key("sourceRegexp")
.description(
"Regular expression to be used to filter the source value of the data. "
"If left empty, no filtering is performed."
)
.assignmentOptional()
.defaultValue("")
.reconfigurable()
.commit(),
SLOT_ELEMENT(expected)
.key("toggleFollowPpu")
.allowedStates(State.MONITORING, State.PASSIVE, State.ERROR)
......@@ -254,20 +259,20 @@ class PickyBoi(PythonDevice):
def input_handler(self, input_channel):
all_metadata = input_channel.getMetaData()
have_written_something = False
regexp = self.unsafe_get("sourceRegexp")
if len(regexp) > 0:
regexp = re.compile(regexp)
source_re = self.unsafe_get("sourceFilterRegex")
if len(source_re) > 0:
source_re = re.compile(source_re)
else:
regexp = None
source_re = None
for input_index in range(input_channel.size()):
state = self.get("state")
data = input_channel.read(input_index)
meta = all_metadata[input_index]
source = meta.get("source")
if regexp is not None:
if not regexp.match(source):
continue
if source_re is not None and not source_re.match(source):
continue
current_tid = Timestamp.fromHashAttributes(
meta.getAttributes("timestamp")
).getTrainId()
......@@ -323,10 +328,11 @@ class PickyBoi(PythonDevice):
# if breakStreamAfterEnd is set, end the stream
# and stop acquiring
if (self.get("breakStreamAfterEnd")
and state is State.ACQUIRING):
if self.get("breakStreamAfterEnd") and state is State.ACQUIRING:
self.signalEndOfStream("output")
self.log.INFO("End of stream reached, following setting breakStreamAfterEnd.")
self.log.INFO(
"End of stream reached, following setting breakStreamAfterEnd."
)
self.updateState(State.PASSIVE)
elif target_tid > current_tid:
# wait
......@@ -337,14 +343,20 @@ class PickyBoi(PythonDevice):
# if breakStreamAfterEnd is set, end the stream
# and stop acquiring
last_train_to_get = (max(self._trains_to_get)
if len(self._trains_to_get) > 0
else current_tid)
if (self.get("breakStreamAfterEnd")
last_train_to_get = (
max(self._trains_to_get)
if len(self._trains_to_get) > 0
else current_tid
)
if (
self.get("breakStreamAfterEnd")
and current_tid > last_train_to_get
and state is State.ACQUIRING):
and state is State.ACQUIRING
):
self.signalEndOfStream("output")
self.log.INFO("End of stream reached, following setting breakStreamAfterEnd.")
self.log.INFO(
"End of stream reached, following setting breakStreamAfterEnd."
)
self.updateState(State.PASSIVE)
state = self.get("state")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment