diff --git a/daq_lib.py b/daq_lib.py index 63adf37a..c2705065 100644 --- a/daq_lib.py +++ b/daq_lib.py @@ -22,6 +22,7 @@ import bluesky.plan_stubs as bps import logging from utils import validation +import requests logger = logging.getLogger(__name__) try: @@ -446,6 +447,14 @@ def runDCQueue(): #maybe don't run rasters from here??? logger.info("running queue in daq server") while (1): currentRequest = db_lib.popNextRequest(daq_utils.beamline) + if (currentRequest == {}): + break + elif currentRequest is None: + gui_message("Queue contains collection requests from different proposals" + "and not using commissioning directory." + "Please remove invalid requests or switch to" + "commissioning directory to continue") + break if (getBlConfig("queueCollect") == 1): if (getBlConfig(BEAM_CHECK) == 1): waitBeam() @@ -462,14 +471,6 @@ def runDCQueue(): #maybe don't run rasters from here??? if (abort_flag): abort_flag = 0 #careful about when to reset this return - if (currentRequest == {}): - break - elif currentRequest is None: - gui_message("Queue contains collection requests from different proposals" - "and not using commissioning directory." - "Please remove invalid requests or switch to" - "commissioning directory to continue") - break logger.info("processing request " + str(time.time())) reqObj = currentRequest["request_obj"] gov_lib.set_detz_in(gov_robot, reqObj["detDist"]) @@ -753,8 +754,22 @@ def collectData(currentRequest): node = getBlConfig(nodeName) dimpleNode = getBlConfig("dimpleNode") if (daq_utils.detector_id == "EIGER-16"): + with open(f"{os.environ['CONFIGDIR']}/autoproc_blacklist.json") as autoproc_blacklist_file: + autoproc_proposal_data = json.load(autoproc_blacklist_file) + run_autoproc = 0 + try: + r = requests.get(f"{os.environ['NSLS2_API_URL']}/v1/proposal/{currentRequest['proposalID']}") + r.raise_for_status() + response = r.json()['proposal'] + if ("proprietary" in response["type"].lower() + or int(currentRequest["proposalID"]) in autoproc_proposal_data["blacklist"]): + run_autoproc = 0 + else: + run_autoproc = 1 + except Exception as e: + run_autoproc = 0 seqNum = flyer.detector.cam.sequence_id.get() - comm_s = os.environ["LSDCHOME"] + "/runFastDPH5.py " + data_directory_name + " " + str(seqNum) + " " + str(currentRequest["uid"]) + " " + str(fastEPFlag) + " " + node + " " + str(dimpleFlag) + " " + dimpleNode + " " + str(currentIspybDCID)+ "&" + comm_s = os.environ["LSDCHOME"] + "/runFastDPH5.py " + data_directory_name + " " + str(seqNum) + " " + str(currentRequest["uid"]) + " " + str(fastEPFlag) + " " + node + " " + str(dimpleFlag) + " " + dimpleNode + " " + str(currentIspybDCID)+ " " + str(run_autoproc) + " &" else: comm_s = os.environ["LSDCHOME"] + "/runFastDP.py " + data_directory_name + " " + file_prefix + " " + str(file_number_start) + " " + str(int(round(range_degrees/img_width))) + " " + str(currentRequest["uid"]) + " " + str(fastEPFlag) + " " + node + " " + str(dimpleFlag) + " " + dimpleNode + "&" logger.info(f'Running fastdp command: {comm_s}') diff --git a/runFastDPH5.py b/runFastDPH5.py index 66c845a0..047a5c6a 100755 --- a/runFastDPH5.py +++ b/runFastDPH5.py @@ -2,9 +2,11 @@ import os import sys import db_lib -from daq_utils import getBlConfig +from daq_utils import getBlConfig, setBlConfig import xmltodict +import json import logging +import subprocess logger = logging.getLogger() logging.getLogger().setLevel(logging.INFO) handler1 = logging.FileHandler('fast_dp.txt') @@ -32,26 +34,59 @@ runDimple = int(sys.argv[6]) dimpleNode = sys.argv[7] ispybDCID = 1 #int(sys.argv[8]) +runAutoProc = int(sys.argv[9]) +# runAutoProc = 0 -comm_s = f"ssh -q {node} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}fast_dp.sh {request_id} {numstart}\"" -logger.info(comm_s) -os.system(comm_s) +try: + comm_s = f"ssh -q {node} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}fast_dp.sh {request_id} {numstart}\"" + logger.info(comm_s) + os.system(comm_s) + fastDPResultFile = runningDir+"/fast_dp.xml" + fd = open(fastDPResultFile) + resultObj = xmltodict.parse(fd.read()) + logger.info(f"finished fast_dp {request_id}") + resultID = db_lib.addResultforRequest("fastDP",request_id,owner,resultObj,beamline=os.environ["BEAMLINE_ID"]) + newResult = db_lib.getResult(resultID) + visitName = getBlConfig("visitName") +except Exception as e: + logger.error("runfastdph5 error running fastdp: %s" % e) -fastDPResultFile = runningDir+"/fast_dp.xml" -fd = open(fastDPResultFile) -resultObj = xmltodict.parse(fd.read()) -logger.info(f"finished fast_dp {request_id}") -resultID = db_lib.addResultforRequest("fastDP",request_id,owner,resultObj,beamline=os.environ["BEAMLINE_ID"]) -newResult = db_lib.getResult(resultID) -visitName = getBlConfig("visitName") try: ispybLib.insertResult(newResult,"fastDP",request,visitName,ispybDCID,fastDPResultFile) except Exception as e: logger.error("runfastdph5 insert result ispyb error: %s" % e) + if (runFastEP): os.system("fast_ep") #looks very bad! running on ca1! + if (runDimple): - dimpleComm = getBlConfig("dimpleComm") - comm_s = f"ssh -q {dimpleNode} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}dimple.sh {request_id} {numstart}\"" - logger.info(f"running dimple: {comm_s}") - os.system(comm_s) + try: + dimpleComm = getBlConfig("dimpleComm") + comm_s = f"ssh -q {dimpleNode} \"{os.environ['MXPROCESSINGSCRIPTSDIR']}dimple.sh {request_id} {numstart}\"" + logger.info(f"running dimple: {comm_s}") + # os.system(comm_s) + subprocess.Popen(comm_s, shell=True) + except Exception as e: + logger.error("runfastdph5 error running dimple: %s" % e) + +if runAutoProc: + logger.info("Running AUTO-AUTOPROC...") + setBlConfig("auto_proc_lock", True) + try: + queue = getBlConfig("auto_proc_queue") + queue.append((directory, request_id)) + setBlConfig("auto_proc_queue", queue) + except Exception as e: + logger.exception("Could not add request to autoproc queue") + finally: + setBlConfig("auto_proc_lock", False) + start_in_proc = None + autoproc_processor_list = json.loads(getBlConfig("autoprocNodes")) + for proc_num in autoproc_processor_list: + if not getBlConfig(proc_num): + start_in_proc = proc_num + break + if start_in_proc: + comm_s = f"ssh {start_in_proc} \"nohup {os.environ['MXPROCESSINGSCRIPTSDIR']}autoproc.sh {start_in_proc} {os.environ['BEAMLINE_ID']} & \" " + logger.info(f"Initializing AUTO-AUTOPROC {comm_s} \n In ({directory}, {request_id})") + subprocess.Popen(comm_s, shell=True)