Skip to content

Commit 74fe9ff

Browse files
committed
Replaced strings of collection protocols with enums
All collection protocols are strings, they are now replaced by Enums
1 parent 8420989 commit 74fe9ff

File tree

9 files changed

+148
-155
lines changed

9 files changed

+148
-155
lines changed

config_params.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,29 @@ def get_text(cls, enum_value):
156156

157157
OPHYD_COLLECTIONS = {"amx": False, "fmx": False, "nyx": True}
158158

159+
class CollectionProtocols(str, Enum):
160+
STANDARD = "standard"
161+
RASTER = "raster"
162+
VECTOR = "vector"
163+
BURN = "burn"
164+
RASTER_SCREEN = "rasterScreen"
165+
STEP_RASTER = "stepRaster"
166+
STEP_VECTOR = "stepVector"
167+
MULTI_COL = "multiCol"
168+
MULTI_COL_Q = "multiColQ"
169+
CHARACTERIZE = "characterize"
170+
EDNA_COL = "ednaCol"
171+
E_SCAN = "eScan"
172+
173+
@classmethod
174+
def get_beamline_options(cls, beamline):
175+
all_protocols = (cls.STANDARD, cls.RASTER, cls.VECTOR, cls.BURN, cls.RASTER_SCREEN,
176+
cls.STEP_RASTER, cls.STEP_VECTOR, cls.MULTI_COL, cls.CHARACTERIZE,
177+
cls.EDNA_COL)
178+
beamline_options = {
179+
"nyx": (cls.STANDARD, cls.RASTER, cls.VECTOR),
180+
"amx": all_protocols,
181+
"fmx": all_protocols
182+
}
183+
184+
return beamline_options.get(beamline, ())

daq_lib.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -605,29 +605,29 @@ def collectData(currentRequest):
605605
os.system(comm_s)
606606
logger.debug('starting initial motions - transmission and detector distance')
607607
daq_macros.setTrans(attenuation)
608-
if not prot in ["eScan"]:
608+
if not prot in [CollectionProtocols.E_SCAN]:
609609
beamline_lib.mvaDescriptor("detectorDist",colDist)
610610
logger.debug('transmission and detector distance done')
611611
# now that the detector is in the correct position, get the beam center
612612
currentRequest['request_obj']['xbeam'] = getPvDesc('beamCenterX')
613613
currentRequest['request_obj']['ybeam'] = getPvDesc('beamCenterY')
614614
db_lib.updateRequest(currentRequest)
615-
if (prot == "raster"):
615+
if prot == CollectionProtocols.RASTER:
616616
logger.info('entering raster')
617617
RE(daq_macros.snakeRaster(currentRequest["uid"]))
618618
status = 0
619619
logger.info('exiting raster')
620-
elif (prot == "stepRaster"):
620+
elif prot == CollectionProtocols.STEP_RASTER:
621621
status = daq_macros.snakeStepRaster(currentRequest["uid"])
622-
elif (prot == "vector" or prot == "stepVector"):
622+
elif prot in (CollectionProtocols.VECTOR, CollectionProtocols.STEP_VECTOR):
623623
imagesAttempted = collect_detector_seq_hw(sweep_start,range_degrees,img_width,exposure_period,file_prefix,data_directory_name,file_number_start,currentRequest)
624-
elif (prot == "multiCol"):
624+
elif prot == CollectionProtocols.MULTI_COL:
625625
RE(daq_macros.snakeRaster(currentRequest["uid"]))
626-
elif (prot == "rasterScreen"):
626+
elif prot == CollectionProtocols.RASTER_SCREEN:
627627
daq_macros.rasterScreen(currentRequest)
628-
elif (prot == "multiColQ"):
628+
elif prot == CollectionProtocols.MULTI_COL_Q:
629629
daq_macros.multiCol(currentRequest)
630-
elif (prot == "eScan"):
630+
elif prot == CollectionProtocols.E_SCAN:
631631
daq_macros.eScan(currentRequest)
632632
else: #standard, screening, or edna - these may require autoalign, checking first
633633
if (reqObj["pos_x"] != -999):
@@ -654,7 +654,7 @@ def collectData(currentRequest):
654654
sweep_start = reqObj["sweep_start"]
655655
daq_macros.setTrans(attenuation)
656656

657-
if (reqObj["protocol"] == "characterize" or reqObj["protocol"] == "ednaCol"):
657+
if (reqObj["protocol"] in (CollectionProtocols.CHARACTERIZE, CollectionProtocols.EDNA_COL):
658658
characterizationParams = reqObj["characterizationParams"]
659659
index_success = daq_macros.dna_execute_collection3(0.0,img_width,2,exposure_period,data_directory_name+"/",file_prefix,1,-89.0,1,currentRequest)
660660
if (index_success):
@@ -693,7 +693,7 @@ def collectData(currentRequest):
693693
runNum = db_lib.incrementSampleRequestCount(sampleID)
694694
newReqObj["runNum"] = runNum
695695
newStratRequest = db_lib.addRequesttoSample(sampleID,newReqObj["protocol"],daq_utils.owner,newReqObj,priority=0,proposalID=daq_utils.getProposalID())
696-
if (reqObj["protocol"] == "ednaCol"):
696+
if (reqObj["protocol"] == CollectionProtocols.EDNA_COL):
697697
logger.info("new strat req = ")
698698
logger.info(newStratRequest)
699699
db_lib.updatePriority(currentRequest["uid"],-1)
@@ -709,7 +709,7 @@ def collectData(currentRequest):
709709
beamline_lib.mvaDescriptor("omega",sweep_start)
710710
collect_detector_seq_hw(sweep_start,range_degrees,img_width,exposure_period,file_prefix,data_directory_name,file_number_start,currentRequest)
711711
try:
712-
if (logMe) and prot == 'raster':
712+
if (logMe) and prot == CollectionProtocols.RASTER:
713713
logMxRequestParams(currentRequest,wait=False)
714714
elif (logMe):
715715
logMxRequestParams(currentRequest)
@@ -721,9 +721,9 @@ def collectData(currentRequest):
721721
logger.error('caught key error in logging: %s' % e)
722722

723723
# collection finished, start processing
724-
if reqObj["protocol"] in ("standard", "vector", "raster"):
724+
if reqObj["protocol"] in (CollectionProtocols.STANDARD, CollectionProtocols.VECTOR, CollectionProtocols.RASTER):
725725
send_kafka_message(topic=f'{daq_utils.beamline}.lsdc.documents', event='stop', uuid=currentRequest['uid'], protocol=reqObj["protocol"])
726-
if (prot == "vector" or prot == "standard" or prot == "stepVector"):
726+
if prot in (CollectionProtocols.VECTOR, CollectionProtocols.STANDARD, CollectionProtocols.STEP_VECTOR):
727727
if daq_utils.beamline != "nyx":
728728
seqNum = flyer.detector.cam.sequence_id.get()
729729
comm_s = os.environ["LSDCHOME"] + "/runSpotFinder4syncW.py " + data_directory_name + " " + file_prefix + " " + str(currentRequest["uid"]) + " " + str(seqNum) + " " + str(currentIspybDCID)+ "&"
@@ -785,7 +785,7 @@ def collect_detector_seq_hw(sweep_start,range_degrees,image_width,exposure_perio
785785
reqObj = currentRequest["request_obj"]
786786
protocol = str(reqObj["protocol"])
787787
sweep_start = sweep_start % 360.0 if sweep_start > 0 else sweep_start % -360
788-
if (protocol == "vector" or protocol == "stepVector"):
788+
if protocol in (CollectionProtocols.VECTOR, CollectionProtocols.STEP_VECTOR):
789789
beamline_lib.mvaDescriptor("omega",sweep_start)
790790
if (image_width == 0):
791791
number_of_images = range_degrees
@@ -807,22 +807,23 @@ def collect_detector_seq_hw(sweep_start,range_degrees,image_width,exposure_perio
807807

808808
if OPHYD_COLLECTIONS[daq_utils.beamline]:
809809
logger.info("ophyd collections enabled")
810-
if (protocol == "standard"):
810+
if (protocol == CollectionProtocols.STANDARD):
811811
RE(daq_macros.standard_plan_wrapped(currentRequest))
812-
elif (protocol == "vector"):
812+
elif (protocol == CollectionProtocols.VECTOR):
813813
RE(daq_macros.vector_plan_wrapped(currentRequest))
814814
else:
815-
if (protocol == "standard" or protocol == "characterize" or protocol == "ednaCol" or protocol == "burn"):
815+
if (protocol in (CollectionProtocols.STANDARD, CollectionProtocols.CHARACTERIZE,
816+
CollectionProtocols.EDNA_COL, CollectionProtocols.BURN):
816817
logger.info("vectorSync " + str(time.time()))
817818
daq_macros.vectorSync()
818819
logger.info("zebraDaq " + str(time.time()))
819820

820821
vector_params = daq_macros.gatherStandardVectorParams()
821822
logger.debug(f"vector_params: {vector_params}")
822823
RE(daq_macros.standard_zebra_plan(flyer,angleStart,number_of_images,range_degrees,image_width,exposure_period,file_prefix_minus_directory,data_directory_name,file_number, vector_params, file_prefix_minus_directory))
823-
elif (protocol == "vector"):
824+
elif (protocol == CollectionProtocols.VECTOR):
824825
RE(daq_macros.vectorZebraScan(currentRequest))
825-
elif (protocol == "stepVector"):
826+
elif (protocol == CollectionProtocols.STEP_VECTOR):
826827
daq_macros.vectorZebraStepScan(currentRequest)
827828
else:
828829
pass

daq_macros.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,8 +1431,9 @@ def snakeRasterNoTile(rasterReqID,grain=""):
14311431
rasterRequest["request_obj"]["rasterDef"]["status"] = 2
14321432
protocol = reqObj["protocol"]
14331433
logger.info("protocol = " + protocol)
1434-
if (protocol == "multiCol" or parentReqProtocol == "multiColQ"):
1435-
if (parentReqProtocol == "multiColQ"):
1434+
if (protocol == CollectionProtocols.MULTI_COL or
1435+
parentReqProtocol == CollectionProtocols.MULTI_COL_Q):
1436+
if (parentReqProtocol == CollectionProtocols.MULTI_COL_Q):
14361437
multiColThreshold = parentReqObj["diffCutoff"]
14371438
else:
14381439
multiColThreshold = reqObj["diffCutoff"]
@@ -1789,7 +1790,7 @@ def snakeRasterNormal(rasterReqID,grain=""):
17891790
rasterReqID))
17901791
spotFindThread.start()
17911792
spotFindThreadList.append(spotFindThread)
1792-
send_kafka_message(f'{daq_utils.beamline}.lsdc.documents', event='event', uuid=rasterReqID, protocol="raster", row=i, proc_flag=procFlag)
1793+
send_kafka_message(f'{daq_utils.beamline}.lsdc.documents', event='event', uuid=rasterReqID, protocol=CollectionProtocols.RASTER, row=i, proc_flag=procFlag)
17931794

17941795

17951796
"""governor transitions:
@@ -1824,8 +1825,9 @@ def snakeRasterNormal(rasterReqID,grain=""):
18241825
rasterResult = generateGridMap(rasterRequest)
18251826

18261827
logger.info(f'protocol = {reqObj["protocol"]}')
1827-
if (reqObj["protocol"] == "multiCol" or parentReqProtocol == "multiColQ"):
1828-
if (parentReqProtocol == "multiColQ"):
1828+
if (reqObj["protocol"] == CollectionProtocols.MULTI_COL or
1829+
parentReqProtocol == CollectionProtocols.MULTI_COL_Q):
1830+
if (parentReqProtocol == CollectionProtocols.MULTI_COL_Q):
18291831
multiColThreshold = parentReqObj["diffCutoff"]
18301832
else:
18311833
multiColThreshold = reqObj["diffCutoff"]
@@ -2169,7 +2171,7 @@ def snakeRasterBluesky(rasterReqID, grain=""):
21692171
rasterReqID))
21702172
spotFindThread.start()
21712173
spotFindThreadList.append(spotFindThread)
2172-
send_kafka_message(f'{daq_utils.beamline}.lsdc.documents', event='event', uuid=rasterReqID, protocol="raster", row=row_index, proc_flag=procFlag)
2174+
send_kafka_message(f'{daq_utils.beamline}.lsdc.documents', event='event', uuid=rasterReqID, protocol=CollectionProtocols.RASTER, row=row_index, proc_flag=procFlag)
21732175
logger.info('row complete')
21742176
"""governor transitions:
21752177
initiate transitions here allows for GUI sample/heat map image to update
@@ -2214,8 +2216,9 @@ def snakeRasterBluesky(rasterReqID, grain=""):
22142216
rasterResult = generateGridMap(rasterRequest)
22152217

22162218
logger.info(f'protocol = {reqObj["protocol"]}')
2217-
if (reqObj["protocol"] == "multiCol" or parentReqProtocol == "multiColQ"):
2218-
if (parentReqProtocol == "multiColQ"):
2219+
if (reqObj["protocol"] == CollectionProtocols.MULTI_COL or
2220+
parentReqProtocol == CollectionProtocols.MULTI_COL_Q):
2221+
if (parentReqProtocol == CollectionProtocols.MULTI_COL_Q):
22192222
multiColThreshold = parentReqObj["diffCutoff"]
22202223
else:
22212224
multiColThreshold = reqObj["diffCutoff"]
@@ -2820,7 +2823,7 @@ def defineRectRaster(currentRequest,raster_w_s,raster_h_s,stepsizeMicrons_s,xoff
28202823

28212824
tempnewRasterRequest = daq_utils.createDefaultRequest(sampleID, basePath=currentRequest["request_obj"]["basePath"])
28222825
reqObj = tempnewRasterRequest["request_obj"]
2823-
reqObj["protocol"] = "raster"
2826+
reqObj["protocol"] = CollectionProtocols.RASTER
28242827
reqObj["exposure_time"] = getBlConfig("rasterDefaultTime")
28252828
reqObj["img_width"] = getBlConfig("rasterDefaultWidth")
28262829
reqObj["attenuation"] = getBlConfig("rasterDefaultTrans")
@@ -4161,7 +4164,7 @@ def zebraDaqRasterBluesky(flyer, angle_start, num_images, scanWidth, imgWidth, e
41614164
x_end_um=x_vec_end, y_end_um=y_vec_end, z_end_um=z_vec_end, \
41624165
file_prefix=filePrefix, data_directory_name=data_directory_name,\
41634166
detector_dead_time=detectorDeadTime, scan_encoder=scanEncoder, change_state=changeState,\
4164-
row_index=row_index, transmission=1, protocol="raster")
4167+
row_index=row_index, transmission=1, protocol=CollectionProtocols.RASTER)
41654168
yield from bp.fly([raster_flyer])
41664169

41674170
logger.info("vector Done")

daq_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
logger.error("daq_utils: ISPYB import error, %s" %e)
1414

1515
import db_lib
16+
from config_params import CollectionProtocols
1617

1718
global beamline
1819
beamline = os.environ["BEAMLINE_ID"]
@@ -222,7 +223,7 @@ def createDefaultRequest(sample_id,createVisit=True, basePath=None):
222223
"sweep_start": screenPhist, "sweep_end": screenPhiend,
223224
"img_width": screenWidth,
224225
"exposure_time": screenExptime,
225-
"protocol": "standard",
226+
"protocol": CollectionProtocols.STANDARD,
226227
"detDist": screenDist,
227228
"parentReqID": -1,
228229
"basePath": basePath,

db_lib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from collections import defaultdict
66

77
import amostra.client.commands as acc
8+
from config_params import CollectionProtocols
89
import conftrak.client.commands as ccc
910
import conftrak.exceptions
1011
import six
@@ -887,6 +888,6 @@ def deleteCompletedRequestsforSample(sid):
887888
requestList=getRequestsBySampleID(sid)
888889
for i in range (0,len(requestList)):
889890
if (requestList[i]["priority"] == -1): #good to clean up completed requests after unmount
890-
if (requestList[i]["protocol"] == "raster" or requestList[i]["protocol"] == "vector"):
891+
if requestList[i]["protocol"] in (CollectionProtocols.RASTER, CollectionProtocols.VECTOR):
891892
deleteRequest(requestList[i]['uid'])
892893

0 commit comments

Comments
 (0)