Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions hackathon/databroker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Swift/t + DataBroker

This set of files demonstrates how to access a DataBroker from swift.

## Environment

To run this demo you need:

- a Python 3.6 with requirements.txt installed
- a Python interpreter embedded in swift/t with swift-requirements.txt installed
- a running local mongodb server

You can create a conda environment, which takes care of all the steps (except the
last one):

```
conda env create -f conda-env.yml
```

The mongodb server can be installed as follows:

```
sudo apt update && sudo apt install mongodb-server
```

## Execution

To run this:

- copy local.yml to `~/.config/databroker/local.yml` (or someplace
else on the search path, see
https://nsls-ii.github.io/databroker/configuration.html#search-path)
- then in 3 different sessions run the following:
- **1st**: `conda activate swift-t` and `bluesky-0MQ-proxy 2000 2001`
- **2nd**: `conda activate swift-t` and `swift-t -n <number-of-cores> -l read_databroker.swift`
- **3rd**: `conda activate swift-t` and `ipython`, and then in the IPython
session run `%run -i gen_data.py` to generate some synthetic data by
RunEngine, which will be published to the 0MQ proxy. In the 2nd
session you should see a bunch of events printed to the screen, meaning
the swift/t received the events from the proxy.
26 changes: 0 additions & 26 deletions hackathon/databroker/Readme.md

This file was deleted.

13 changes: 13 additions & 0 deletions hackathon/databroker/conda-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: swift-t
channels:
- lightsource2-tag
- defaults
dependencies:
- bluesky
- databroker
- ipython
- numpy
- ophyd
- pymongo
- python=3.6
- swift-t
3 changes: 3 additions & 0 deletions hackathon/databroker/gen_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
import bluesky.plans as bp
from bluesky import RunEngine
from bluesky.callbacks.zmq import Publisher
from bluesky.callbacks.best_effort import BestEffortCallback
from ophyd.sim import motor, det

db = databroker.Broker.named('local')
bec = BestEffortCallback()
RE = RunEngine()
RE.subscribe(db.insert)
RE.subscribe(bec)

pub = Publisher('localhost:2000', RE=RE)

Expand Down
14 changes: 4 additions & 10 deletions hackathon/databroker/read_databroker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ deserializer = pickle.loads
address = ('localhost', 2001)

_context = zmq.Context()
print(f'=== _context: {_context}')
_socket = _context.socket(zmq.SUB)
print(f'=== _socket: {_socket}')

url = "tcp://%s:%d" % address
print(f'=== _url: {url}')
_socket.connect(url)
print('connect')

Expand All @@ -40,7 +37,7 @@ def _poll(_socket, deserializer, DocumentNames):
hostname = hostname.decode()
name = name.decode()
doc = deserializer(doc)
yield (DocumentNames[name], doc)
yield (name, doc)

doc_gen = _poll(_socket, deserializer, DocumentNames)
----,
Expand Down Expand Up @@ -68,15 +65,12 @@ except StopIteration:
{
result = python_persist(
----
import time
time.sleep(1)
ev = %s
print(type(ev))
name, doc = %s
----
% inp
,
----
f"{ev['seq_num']} {ev['uid']}: {ev['data']}"
name
----
);

Expand All @@ -87,7 +81,7 @@ global const int MAX = 1000;
process()
{
for (int i = 0, boolean stop = false;
i < MAX && !stop;
!stop;
i = i+1, stop = end_of_data)
{
line = get_event();
Expand Down