Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
Rose Yemelyanova committed Oct 10, 2023
1 parent 7f1278b commit c7d4253
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 108 deletions.
12 changes: 11 additions & 1 deletion src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ class EnvironmentConfig(BlueapiBaseModel):
Source(kind=SourceKind.PLAN_FUNCTIONS, module="blueapi.startup.example_plans"),
Source(kind=SourceKind.PLAN_FUNCTIONS, module="blueapi.plans"),
]
visit_service_url: str = "http://p38-control.diamond.ac.uk:8088/api/0.0.1"
visit_id: str = "v1"
facility: str = "Diamond"
science_group: str = "MX"
beamline: str = "I03"

def __eq__(self, other: object) -> bool:
if isinstance(other, EnvironmentConfig):
return str(self.sources) == str(other.sources)
return (
(str(self.sources) == str(other.sources))
and (self.facility == other.facility)
and (self.science_group == other.science_group)
and (self.beamline == other.beamline))

return False


Expand Down
3 changes: 3 additions & 0 deletions src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ def find_device(self, addr: Union[str, List[str]]) -> Optional[Device]:
return find_component(self.devices, addr)

def with_config(self, config: EnvironmentConfig) -> None:
# need to see in config. And create directory provider here.
# import dodal and call factory function to make instance of GdaDirectoryProvider.
self.dir_provider = make_directory_provider(config.thing)
for source in config.sources:
mod = import_module(str(source.module))

Expand Down
Empty file removed src/blueapi/plugins/__init__.py
Empty file.
106 changes: 0 additions & 106 deletions src/blueapi/plugins/data_writing.py

This file was deleted.

53 changes: 53 additions & 0 deletions src/blueapi/preprocessors/attach_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import bluesky.plan_stubs as bps
from bluesky.utils import make_decorator
from ophyd_async.detector import DirectoryInfo, DirectoryProvider

from blueapi.config import ApplicationConfig, ConfigLoader
from blueapi.core import MsgGenerator


class GDADirectoryProvider(DirectoryProvider):
def __call__(self) -> DirectoryInfo:
return super().__call__()

async def update(self) -> None:
...


DATA_SESSION = "data_session"
DATA_GROUPS = "data_groups"

# TODO: this is a temporary solution; I should think about how config is passed down in
# the whole app.
config = ConfigLoader(ApplicationConfig).load().env


def attach_metadata(
plan: MsgGenerator,
provider: GDADirectoryProvider,
) -> MsgGenerator:
"""Updates a directory provider default location for file storage."""
staging = False

messages = list(plan)
will_write_data = "open_run" in [msg.command for msg in messages]
remade_plan = (msg for msg in messages)

for message in remade_plan:
if (message.command == "stage") and (not staging and will_write_data):
yield from bps.wait_for([provider.update])
staging = True

if message.command == "open_run":
message.kwargs[DATA_SESSION] = provider().filename_prefix
message.kwargs[DATA_GROUPS] = [
config.facility,
config.science_group,
config.beamline,
config.visit_id,
]

yield message


attach_metadata_decorator = make_decorator(attach_metadata)
Empty file.
12 changes: 11 additions & 1 deletion src/blueapi/service/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from blueapi.core.event import EventStream
from blueapi.messaging import StompMessagingTemplate
from blueapi.messaging.base import MessagingTemplate
from blueapi.preprocessors.attach_metadata import attach_metadata
from blueapi.worker.reworker import RunEngineWorker
from blueapi.worker.worker import Worker

Expand Down Expand Up @@ -74,13 +75,22 @@ def stop(self) -> None:


HANDLER: Optional[Handler] = None
#PROVIDER: Optional[GDADirectoryProvider] = None


def setup_handler(
config: Optional[ApplicationConfig] = None,
) -> None:
global HANDLER
handler = Handler(config)
#global PROVIDER

# make a global GdaDirectoryProvider, if config provided.
if config:
config.env()

#provider = GDADirectoryProvider(config.)

handler = Handler(config, context=BlueskyContext(plan_wrappers=[attach_metadata]))
handler.start()

HANDLER = handler
Expand Down

0 comments on commit c7d4253

Please sign in to comment.