update example's to the current state of sf-daq

This commit is contained in:
Dmitry Ozerov
2023-10-13 16:12:05 +02:00
parent 4dde9a0400
commit db5906db64
4 changed files with 37 additions and 39 deletions
+9 -17
View File
@@ -33,7 +33,7 @@ r = requests.post(f'{broker_address}/retrieve_from_buffers',json=parameters, tim
```
return object `r` is a dictionary with at least two keys: `'status'` and `'message'`. In case of no problem with the request to retrieve data (so request is accepted to be processed
by broker), `'status'` is 'ok', `'message'` is 'OK' and there are additional fields in reply : `run_number`, `acquisition_number` and `unique_acquistition_number` and list of `'files'` which sf-daq will produce in corresponding data/ directory
by broker), `'status'` is 'ok', `'message'` is 'OK' and there are additional fields in reply : `run_number`, `acquisition_number` and `unique_acquisition_number` and list of `'files'` which sf-daq will produce in corresponding data/ directory
```python
r.json()
{'status': 'ok', 'message': 'OK', 'run_number': '10', 'acquisition_number': '1', 'unique_acquisition_number': '101', 'files': ['/sf/alvra/data/p17502/raw/run0010/data/acq0001.PVDATA.h5']}
@@ -235,23 +235,18 @@ Example of log files above shows that there are missing pulseid's for some of th
Command line example how to use broker to request a retireve of data is daq_client.py. To run is enough to have python > 3.6 and standard packages (requests, os, json)
(so standard PSI python environment is good for this purpose):
```bash
$ module load psi-python36/4.4.0
$ python daq_client.py -h
usage: daq_client.py [-h] [-p PGROUP] [-d OUTPUT_DIRECTORY] [-c CHANNELS_FILE]
[-e EPICS_FILE] [-f FILE_DETECTORS]
[-r RATE_MULTIPLICATOR] [-s SCAN_STEP_FILE]
[--start_pulseid START_PULSEID]
[--stop_pulseid STOP_PULSEID]
$ module load psi-python39/2021.11
test broker
$ python daq_client.py --help
usage: daq_client.py [-h] [-p PGROUP] [-c CHANNELS_FILE] [-e EPICS_FILE] [-f FILE_DETECTORS] [-r RATE_MULTIPLICATOR]
[-s SCAN_STEP_FILE] [--start_pulseid START_PULSEID] [--stop_pulseid STOP_PULSEID]
simple daq client example
optional arguments:
-h, --help show this help message and exit
-p PGROUP, --pgroup PGROUP
pgroup, example p12345
-d OUTPUT_DIRECTORY, --output_directory OUTPUT_DIRECTORY
output directory for the data, relative path to the
raw directory in the pgroup
-c CHANNELS_FILE, --channels_file CHANNELS_FILE
TXT file with list channels
-e EPICS_FILE, --epics_file EPICS_FILE
@@ -276,17 +271,14 @@ optional arguments:
It can also run in a standard PSI environment, but the pulse_id's would be wrong (the proper way to get a pulse_id is to use one of the channel which provide them
effectively, see client_example.py). So in case one run this example in environment without pyepics, the guessed, fake pulseid would be approximately ok (due to the lock to the 50Hz electricity frequency for accelerator, our 100Hz is not an ideal 100Hz, so it's impossible to make a 100% accurate prediction from time to pulse_id)
```bash
. /opt/gfa/python 3.7 # this loads proper environment with pyepics in it
. /opt/gfa/python 3.9 # this loads proper environment with pyepics in it
$ ipython
Python 3.7.5 (default, Oct 25 2019, 15:51:11)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import client_example as client
In [2]: daq_client = client.BrokerClient(pgroup="p12345")
In [3]: daq_client.configure(output_directory="test/daq", channels_file="channel_list", rate_multiplicator=2, detectors_file="jf_jf01.json")
In [3]: daq_client.configure(channels_file="channel_list", rate_multiplicator=2, detectors_file="jf_jf01.json")
In [4]: daq_client.run(1000)
[####################] 99% Run: 2
+8 -8
View File
@@ -7,14 +7,16 @@ import os
import daq_client
pulseid = {
"alvra" : "SLAAR11-LTIM01-EVR0:RX-PULSEID",
"bernina" : "SLAAR21-LTIM01-EVR0:RX-PULSEID",
"maloja" : "SLAAR11-LTIM01-EVR0:RX-PULSEID"
"alvra" : "SLAAR11-LTIM01-EVR0:RX-PULSEID",
"bernina" : "SLAAR21-LTIM01-EVR0:RX-PULSEID",
"cristallina" : "SLAAR21-LTIM01-EVR0:RX-PULSEID",
"maloja" : "SLAAR11-LTIM01-EVR0:RX-PULSEID",
"furka" : "SLAAR11-LTIM01-EVR0:RX-PULSEID"
}
def get_beamline():
import socket
ip2beamlines = {"129.129.242": "alvra", "129.129.243": "bernina", "129.129.246": "maloja"}
ip2beamlines = {"129.129.242": "alvra", "129.129.243": "bernina", "129.129.244": "cristallina", "129.129.246": "maloja", "129.129.247": "furka"}
ip=socket.gethostbyname(socket.gethostname())
beamline = None
if ip[:11] in ip2beamlines:
@@ -53,7 +55,6 @@ class BrokerClient:
self.rate_multiplicator = 1
self.output_directory = None
self.channels_file = None
self.epics_file = None
self.detectors_file = None
@@ -66,12 +67,11 @@ class BrokerClient:
if not os.path.isdir(raw_directory):
raise NameError(f'{raw_directory} doesnt exist or accessible')
def configure(self, output_directory=None,
def configure(self,
channels_file=None, epics_file=None,
detectors_file=None, scan_step_info_file=None,
rate_multiplicator=1):
self.output_directory = output_directory
self.channels_file = channels_file
self.epics_file = epics_file
self.detectors_file = detectors_file
@@ -96,7 +96,7 @@ class BrokerClient:
if stop_pulseid is None:
stop_pulseid = get_current_pulseid()
last_run_previous = self.last_run
self.last_run = daq_client.retrieve_data_from_buffer_files(pgroup=self.pgroup, output_directory=self.output_directory,
self.last_run = daq_client.retrieve_data_from_buffer_files(pgroup=self.pgroup,
channels_file=self.channels_file, epics_file=self.epics_file,
detectors_file=self.detectors_file,
start_pulseid=self.start_pulseid, stop_pulseid=stop_pulseid,
+20 -14
View File
@@ -7,10 +7,9 @@ TIMEOUT_DAQ = 10
def run():
parser = argparse.ArgumentParser(description='test broker')
parser = argparse.ArgumentParser(description='simple daq client example')
parser.add_argument("-p", "--pgroup", help="pgroup, example p12345", default="p18493")
parser.add_argument("-d", "--output_directory", help="output directory for the data, relative path to the raw directory in the pgroup", default="covid/test1")
parser.add_argument("-c", "--channels_file", help="TXT file with list channels", default=None)
@@ -27,14 +26,14 @@ def run():
args = parser.parse_args()
retrieve_data_from_buffer_files(pgroup=args.pgroup, output_directory=args.output_directory,
retrieve_data_from_buffer_files(pgroup=args.pgroup,
channels_file=args.channels_file, epics_file=args.epics_file,
detectors_file=args.file_detectors,
start_pulseid=args.start_pulseid, stop_pulseid=args.stop_pulseid,
rate_multiplicator=args.rate_multiplicator,
scan_step_info_file=args.scan_step_file)
def retrieve_data_from_buffer_files(pgroup=None, output_directory=None,
def retrieve_data_from_buffer_files(pgroup=None,
channels_file=None, epics_file=None,
detectors_file=None,
start_pulseid=None, stop_pulseid=None,
@@ -83,7 +82,7 @@ def retrieve_data_from_buffer_files(pgroup=None, output_directory=None,
return None
run_number = retrieve_data_from_buffer(pgroup=pgroup, output_directory=output_directory,
run_number = retrieve_data_from_buffer(pgroup=pgroup,
camera_channels=camera_channels, bsread_channels=bsread_channels,
epics_channels=epics_channels,
detectors=detectors,
@@ -92,7 +91,7 @@ def retrieve_data_from_buffer_files(pgroup=None, output_directory=None,
scan_step_info=scan_step_info)
return run_number
def retrieve_data_from_buffer(pgroup=None, output_directory=None,
def retrieve_data_from_buffer(pgroup=None,
camera_channels=[], bsread_channels=[], epics_channels=[],
detectors=None,
start_pulseid=None, stop_pulseid=None,
@@ -108,8 +107,6 @@ def retrieve_data_from_buffer(pgroup=None, output_directory=None,
parameters = {}
parameters["pgroup"] = pgroup
parameters["directory_name"] = output_directory
parameters["start_pulseid"] = start_pulseid
parameters["stop_pulseid"] = stop_pulseid
@@ -139,13 +136,22 @@ def retrieve_data_from_buffer(pgroup=None, output_directory=None,
responce = r.json()
if "status" in responce:
if responce["status"] == "ok":
run_number = (responce["message"])
print(f'success: run number(request_id) is {run_number}')
else:
if "message" in responce:
print(f' Error, reason : {responce["message"]}')
message = responce.get("message", None)
run_number = responce.get("run_number", None)
if run_number is not None:
run_number = int(run_number)
run_number_print = f'{run_number:04}'
else:
print(f'responce is not standard : {responce}')
run_number_print = None
acq_number = responce.get("acquisition_number", None)
unq_acq_number = responce.get("unique_acquisition_number", None)
files_daq = responce.get("files", [])
print(f'success: {message=} {run_number=} {acq_number=} {unq_acq_number=}')
print(f' these files to expect in raw/{pgroup}/run{run_number_print}/data/ directory : {files_daq}')
else:
message = responce.get("message", None)
print(f' Error, reason : {message=}')
print(f' whole responce : {responce=}')
else:
print("Bad responce from request")